diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..8a94c38 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,55 @@ +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 + with: + host: ${{ vars.VM_HOST }} + username: ${{ vars.VM_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + 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/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..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: