Skip to content

Commit

Permalink
fixes the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmegatelo committed Jun 25, 2024
1 parent dd2ddc5 commit b69a7c2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
76 changes: 46 additions & 30 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
name: Master branch deploy

on:
workflow_dispatch:
push:
branches:
- master

jobs:
jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- run: docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }}
- run: docker build -t ghcr.io/$GITHUB_ACTOR/infomate:latest -t ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA .
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:latest
build:
name: Build image
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@master
- run: docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }}
- run: docker build -f ./infra/production/django/Dockerfile -t ghcr.io/$GITHUB_ACTOR/walter:latest -t ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA .
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter:latest

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build
env:
SSH_KEY_PATH: /tmp/ssh_key
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Make envfile
run: export | grep "secret_" | sed "s/declare -x secret_//" > .env
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
APP_HOST: ${{ env.APP_HOST }}
- run: echo "GITHUB_SHA=$GITHUB_SHA" >> .env
- run: echo "${{ secrets.PRODUCTION_SSH_KEY }}" > ${{ env.SSH_KEY_PATH }} && chmod 600 ${{ env.SSH_KEY_PATH }}
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} -r $(pwd)/* ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} .env ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/.env
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} docker-compose.production.yml ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/docker-compose.prod.yml
- run: ssh -i ${{ env.SSH_KEY_PATH }} ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }} "cd /home/walter/walter && docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }} && docker pull ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA && docker-compose -f docker-compose.prod.yml --env-file=.env up -d && docker system prune --all --force"
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
needs: build
env:
SSH_KEY_PATH: /tmp/ssh_key
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Make envfile
run: export | grep "secret_" | sed "s/declare -x secret_//" > .env
env:
secret_SECRET_KEY: ${{ secrets.SECRET_KEY }}
secret_DJANGO_ALLOWED_HOSTS: ${{ env.DJANGO_ALLOWED_HOSTS }}
secret_DEBUG: ${{ env.DEBUG }}
secret_SQL_ENGINE: ${{ env.SQL_ENGINE }}
secret_SQL_DATABASE: ${{ env.SQL_DATABASE }}
secret_SQL_USER: ${{ secrets.SQL_USER }}
secret_SQL_PASSWORD: ${{ secrets.SQL_PASSWORD }}
secret_SQL_HOST: ${{ env.SQL_HOST }}
secret_SQL_PORT: ${{ env.SQL_HOST }}
secret_RABBITMQ_DEFAULT_USER: ${{ secrets.RABBITMQ_DEFAULT_USER }}
secret_RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }}
secret_CELERY_BROKER: ${{ env.CELERY_BROKER }}
secret_CELERY_BACKEND: ${{ env.CELERY_BACKEND }}
secret_CELERY_FLOWER_USER: ${{ secrets.CELERY_FLOWER_USER }}
secret_CELERY_FLOWER_PASSWORD: ${{ secrets.CELERY_FLOWER_PASSWORD }}
secret_CHANNELS_REDIS: ${{ env.CHANNELS_REDIS }}
- run: echo "GITHUB_SHA=$GITHUB_SHA" >> .env
- run: echo "${{ secrets.PRODUCTION_SSH_KEY }}" > ${{ env.SSH_KEY_PATH }} && chmod 600 ${{ env.SSH_KEY_PATH }}
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} -r $(pwd)/* ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} .env ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/.env
- run: scp -o StrictHostKeyChecking=no -i ${{ env.SSH_KEY_PATH }} docker-compose.prod.yml ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }}:/home/walter/walter/docker-compose.prod.yml
- run: ssh -i ${{ env.SSH_KEY_PATH }} ${{ secrets.PRODUCTION_SSH_USERNAME }}@${{ secrets.PRODUCTION_SSH_HOST }} "cd /home/walter/walter && docker login ghcr.io -u $GITHUB_ACTOR -p ${{ secrets.GHCR_TOKEN }} && docker pull ghcr.io/$GITHUB_ACTOR/walter:$GITHUB_SHA && docker compose -f docker-compose.prod.yml --env-file=.env up -d && docker system prune --all --force"
8 changes: 4 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
web:
build:
context: .
dockerfile: ./infra/production/django/Dockerfile
dockerfile: ghcr.io/mrmegatelo/walter:${GITHUB_SHA:-latest}
command: /start
volumes:
- staticfiles:/app/staticfiles
Expand Down Expand Up @@ -50,7 +50,7 @@ services:
celery_worker:
build:
context: .
dockerfile: ./infra/production/django/Dockerfile
dockerfile: ghcr.io/mrmegatelo/walter:${GITHUB_SHA:-latest}
image: walter_celery_worker
command: /start-celeryworker
volumes:
Expand All @@ -65,7 +65,7 @@ services:
celery_beat:
build:
context: .
dockerfile: ./infra/production/django/Dockerfile
dockerfile: ghcr.io/mrmegatelo/walter:${GITHUB_SHA:-latest}
image: walter_celery_beat
command: /start-celerybeat
volumes:
Expand All @@ -80,7 +80,7 @@ services:
flower:
build:
context: .
dockerfile: ./infra/production/django/Dockerfile
dockerfile: ghcr.io/mrmegatelo/walter:${GITHUB_SHA:-latest}
image: walter_celery_flower
command: /start-flower
volumes:
Expand Down

0 comments on commit b69a7c2

Please sign in to comment.