Skip to content

Merge pull request #753 from BristolSTA/fix/workflows #316

Merge pull request #753 from BristolSTA/fix/workflows

Merge pull request #753 from BristolSTA/fix/workflows #316

Workflow file for this run

name: Build, push, deploy
on:
push:
branches: [dev, main]
env:
IMAGE_NAME: api
IMAGE_OWNER: bristolsta
API_SERVICE_NAME: "${{ github.ref == 'refs/heads/main' && 'uobtheatre-api' || 'uobtheatre-api-staging' }}"
AUX_SERVICE_NAMES: "${{ github.ref == 'refs/heads/main' && 'uobtheatre-api-celery-worker' || 'uobtheatre-api-staging-celery-worker' }}"
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file compose/production/django/Dockerfile --tag ghcr.io/$IMAGE_OWNER/$IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- name: Log into registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.BRISTOLSTA_REGISTRY_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: docker push ghcr.io/$IMAGE_OWNER/$IMAGE_NAME:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy new image
uses: appleboy/ssh-action@master
env:
API_SERVICE_NAME: ${{ env.API_SERVICE_NAME }}
AUX_SERVICE_NAMES: ${{ env.AUX_SERVICE_NAMES }}
with:
host: ${{ secrets.SERVER_SSH_HOST }}
username: ${{ secrets.SERVER_SSH_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_SSH_PORT }}
envs: API_SERVICE_NAME, AUX_SERVICE_NAMES
script: |
cd /var/sta
docker-compose pull $API_SERVICE_NAME $AUX_SERVICE_NAMES
docker-compose up -d $API_SERVICE_NAME $AUX_SERVICE_NAMES
docker-compose exec -T $API_SERVICE_NAME python manage.py migrate