Skip to content

fix(ci): Docker and Poetry 2 compatibility for CI/CD #3

fix(ci): Docker and Poetry 2 compatibility for CI/CD

fix(ci): Docker and Poetry 2 compatibility for CI/CD #3

name: Login into host machine, build and start the app's daemon

Check failure on line 1 in .github/workflows/deploy-bare-metal.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/deploy-bare-metal.yml

Invalid workflow file

(Line: 63, Col: 12): Job 'deploy' depends on unknown job 'build-django'.
on:
push:
branches:
- bare-metal-deploy
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
working-directory: ./frontend
run: pnpm install
- name: Build frontend
working-directory: ./frontend
run: pnpm build
build-backend:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --only main
- name: Run Tests
env:
TEST: 1
run: |
poetry run python manage.py test
deploy:
runs-on: ubuntu-latest
needs: build-django
steps:
- uses: actions/checkout@master
- name: copy repo to host machine
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: 22
source: "poetry.lock,pyproject.toml,api,backend,config,core,frontend,manage.py"
target: "app_to_deploy"
- name: build the backend, the frontend and start the app's daemon
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: 22
script: |
echo -e "======================== HOST DEPLOY STARTED ========================\n"
cd app_to_deploy
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Changed directory into app_to_deploy ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd frontend
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Changed directory into frontend ~~~~~~~~~~~~~~~~~~~~~~~~\n"
npm ci
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Installed javascript dependencies successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
rm .env
touch .env
echo 'NODE_ENV=production' >> .env
echo 'AUTH_TOKEN='${{ secrets.AUTH_KEY }} >> .env
echo 'GTAG_ID='${{ secrets.GTAG_ID }} >> .env
npx webpack
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Built frontend successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd ..
rm .env
touch .env
echo 'MODE=production' >> .env
echo 'SECRET_KEY='${{ secrets.SECRET_KEY }} >> .env
echo 'CDN_NAME='${{ secrets.CDN_NAME }} >> .env
echo 'CDN_API_KEY='${{ secrets.CDN_API_KEY }} >> .env
echo 'CDN_API_SECRET='${{ secrets.CDN_API_SECRET }} >> .env
echo 'DB_HOST='${{ secrets.DB_HOST }} >> .env
echo 'DB_NAME='${{ secrets.NAME }} >> .env
echo 'DB_USER=${{ secrets.DB_USER }}' >> .env
echo 'DB_PASSWORD=${{ secrets.DB_PASSWORD }}' >> .env
echo 'SMTP_HOST_USER='${{ secrets.SMTP_HOST_USER }} >> .env
echo 'SMTP_HOST_PASSWORD='${{ secrets.SMTP_HOST_PASSWORD }} >> .env
cd ..
cp -rf --no-target-directory app_to_deploy app
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Replaced current running code with new one ~~~~~~~~~~~~~~~~~~~~~~~~\n"
cd app
python3 -m pip install --upgrade pip
pip install poetry
poetry install --only main
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Installed python requirements successfully ~~~~~~~~~~~~~~~~~~~~~~~~\n"
poetry run python3 manage.py migrate
poetry run python3 manage.py collectstatic --no-input
poetry run python3 manage.py clearcache
echo ${{ secrets.SSH_PASSWORD }} | sudo -S rm /etc/supervisord.d/drt.ini
echo ${{ secrets.SSH_PASSWORD }} | sudo -S cp ./config/supervisor/drt.ini /etc/supervisord.d/
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl update
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl reread
echo ${{ secrets.SSH_PASSWORD }} | sudo -S supervisorctl status drt
rm .env
echo -e "~~~~~~~~~~~~~~~~~~~~~~~~ Gunicorn daemon is up ~~~~~~~~~~~~~~~~~~~~~~~~\n"
echo -e "======================== HOST DEPLOY IS DONE ========================\n"