From 6bc3934f230fc37c353c21b6d2700a82ca9169b8 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 | 57 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 6 ++-- 2 files changed, 61 insertions(+), 2 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..13759fa --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,57 @@ +name: Deploy + +on: + push: + branches: + - master + - add-deploy-workflow # FIXME: remove this line + workflow_dispatch: # This will make the workflow dispatched only manually + +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 + + deploy: + needs: build-and-push + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Compose + uses: ndeloof/install-compose-action@v0.0.1 + with: + version: v2.20.2 + + - name: Deploy to the VM + uses: appleboy/ssh-action@master + # TODO: handle creating .env file on the VM + with: + host: ${{ vars.VM_HOST }} + username: ${{ vars.VM_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + envs: WALLDOZER_VERSION,BOT_TOKEN + script: | + echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + docker compose pull + docker compose up -d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9be5544..ca20bcc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,15 +2,17 @@ version: '3.8' services: migrate_db: + image: aaissaut/aaiss/backend:latest 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:latest 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: