docker image experiment #255
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Master branch deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
name: Build docker images | |
runs-on: ubuntu-latest | |
environment: production | |
strategy: | |
matrix: | |
image_name: ['django', 'frontend'] | |
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-${{matrix.image_name}}:latest -t ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:$GITHUB_SHA . | |
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:$GITHUB_SHA | |
- run: docker image push ghcr.io/$GITHUB_ACTOR/walter-${{matrix.image_name}}:latest | |
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_DJANGO_SECRET_KEY: ${{ secrets.SECRET_KEY }} | |
secret_DJANGO_ALLOWED_HOSTS: ${{ secrets.DJANGO_ALLOWED_HOSTS }} | |
secret_DEBUG: ${{ vars.DEBUG }} | |
secret_SQL_ENGINE: ${{ vars.SQL_ENGINE }} | |
secret_SQL_DATABASE: ${{ vars.SQL_DATABASE }} | |
secret_SQL_USER: ${{ secrets.SQL_USER }} | |
secret_SQL_PASSWORD: ${{ secrets.SQL_PASSWORD }} | |
secret_SQL_HOST: ${{ vars.SQL_HOST }} | |
secret_SQL_PORT: ${{ vars.SQL_PORT }} | |
secret_RABBITMQ_DEFAULT_USER: ${{ secrets.RABBITMQ_DEFAULT_USER }} | |
secret_RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }} | |
secret_CELERY_BROKER: ${{ vars.CELERY_BROKER }} | |
secret_CELERY_BACKEND: ${{ vars.CELERY_BACKEND }} | |
secret_CELERY_FLOWER_USER: ${{ secrets.CELERY_FLOWER_USER }} | |
secret_CELERY_FLOWER_PASSWORD: ${{ secrets.CELERY_FLOWER_PASSWORD }} | |
secret_CHANNELS_REDIS: ${{ vars.CHANNELS_REDIS }} | |
secret_EMAIL_HOST: ${{ vars.EMAIL_HOST }} | |
secret_EMAIL_PORT: ${{ vars.EMAIL_PORT }} | |
secret_EMAIL_HOST_USER: ${{ secrets.EMAIL_HOST_USER }} | |
secret_EMAIL_HOST_PASSWORD: ${{ secrets.EMAIL_HOST_PASSWORD }} | |
secret_EMAIL_USE_TLS: ${{ vars.EMAIL_USE_TLS }} | |
secret_REDIS_LOCATION: ${{ vars.REDIS_LOCATION }} | |
secret_SENTRY_DSN: ${{ secrets.SENTRY_DSN }} | |
- 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-web:$GITHUB_SHA && docker pull ghcr.io/$GITHUB_ACTOR/walter-frontend:$GITHUB_SHA && docker compose -f docker-compose.prod.yml up -d && docker system prune --all --force" |