Skip to content

feat: Demark a Society's SU status (#835) #331

feat: Demark a Society's SU status (#835)

feat: Demark a Society's SU status (#835) #331

Workflow file for this run

name: Production Build, Push & Deploy
# Pushes a new image to the main registry for pushes to the dev or main branch
# Then logs in to the respective server and deploys the new image
# Both dev and main branches are pushed to the same registry, but only the respective instance pulls the new image
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' }}"
SSH_HOST: "${{ github.ref == 'refs/heads/main' && secrets.PROD_SERVER_SSH_HOST || secrets.SERVER_SSH_HOST }}"
SSH_USER: "${{ github.ref == 'refs/heads/main' && secrets.PROD_SERVER_SSH_USER || secrets.SERVER_SSH_USER }}"
SSH_KEY: "${{ github.ref == 'refs/heads/main' && secrets.PROD_SERVER_SSH_KEY || secrets.SERVER_SSH_KEY }}"
SSH_PORT: "${{ github.ref == 'refs/heads/main' && secrets.PROD_SERVER_SSH_PORT || secrets.SERVER_SSH_PORT }}"
DEPLOY_PATH: "${{ github.ref == 'refs/heads/main' && '/root/sta-compose' || '/var/sta' }}"
DOCKER_FILE: "${{ github.ref == 'refs/heads/main' && 'docker-compose.droplet.yml' || 'docker-compose.hetzner.yml' }}"
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- 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 }}
DEPLOY_PATH: ${{ env.DEPLOY_PATH }}
DOCKER_FILE: ${{ env.DOCKER_FILE }}
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_KEY }}
port: ${{ env.SSH_PORT }}
envs: API_SERVICE_NAME, AUX_SERVICE_NAMES, DEPLOY_PATH, DOCKER_FILE
script: |
cd $DEPLOY_PATH
docker compose -f $DOCKER_FILE pull $API_SERVICE_NAME $AUX_SERVICE_NAMES
docker compose -f $DOCKER_FILE up -d $API_SERVICE_NAME $AUX_SERVICE_NAMES
docker compose -f $DOCKER_FILE exec -T $API_SERVICE_NAME python manage.py migrate