From 3933e038f41dbb1d9f152b3e0fe099c23d45738e Mon Sep 17 00:00:00 2001 From: Adibov Date: Thu, 23 Nov 2023 14:45:42 +0330 Subject: [PATCH] ci: add deploy workflow --- .github/workflows/deploy.yaml | 61 +++++++++++++++++++++++++++++++ backend/aaiss_backend/settings.py | 2 +- docker-compose.yml | 6 ++- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..da34d4b --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,61 @@ +name: Deploy + +on: + push: + branches: + - master + - add-deploy-workflow # FIXME: remove this line + workflow_dispatch: # This will make the workflow dispatched only manually + inputs: + +jobs: + build-and-push: + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Compose + uses: ndeloof/install-compose-action@v0.0.1 + with: + version: v2.20.2 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build docker images + run: docker compose build + + - name: Push docker images + run: docker compose push backend + + deploy: + needs: build-and-push + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Copy files to VM + uses: appleboy/scp-action@master + with: + host: ${{ vars.VM_HOST }} + username: ${{ vars.VM_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + overwrite: true + source: docker-compose.yml + target: /home/${{ vars.VM_USERNAME }}/AAISS-2023 + + - name: Deploy to the VM + uses: appleboy/ssh-action@master + with: + host: ${{ vars.VM_HOST }} + username: ${{ vars.VM_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + # TODO: handle envs + script: | + docker compose -f AAISS-2023/docker-compose.yml pull + docker compose -f AAISS-2023/docker-compose.yml up -d \ No newline at end of file diff --git a/backend/aaiss_backend/settings.py b/backend/aaiss_backend/settings.py index 8f838f2..d8e0152 100644 --- a/backend/aaiss_backend/settings.py +++ b/backend/aaiss_backend/settings.py @@ -191,4 +191,4 @@ PAYWALL = env.str("PAYWALL", "ZIFY") #ZIFY -ZIFY_AUTH = env.str("ZIFY_AUTH") \ No newline at end of file +ZIFY_AUTH = env.str("ZIFY_AUTH", "") \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9be5544..f58d695 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,17 @@ version: '3.8' services: migrate_db: + image: aaissaut/aaiss:backend build: ./backend command: ./manage.py migrate volumes: - ./backend/data:/backend-aaiss/data - web: + backend: depends_on: migrate_db: condition: service_completed_successfully + image: aaissaut/aaiss:backend build: ./backend command: gunicorn aaiss_backend.wsgi:application --bind 0.0.0.0:6446 volumes: @@ -26,7 +28,7 @@ services: caddy: depends_on: - web: + backend: condition: service_healthy image: caddy:2.7.3 volumes: