Skip to content

Create new github action to handle auto creation and destruction of t… #263

Create new github action to handle auto creation and destruction of t…

Create new github action to handle auto creation and destruction of t… #263

name: Backend Production Deployment
on:
push:
branches:
- master
paths:
- "zubhub_backend/**"
- "!zubhub_backend/zubhub/docs/**"
- "!zubhub_backend/.gitignore"
- "!zubhub_backend/.env.example"
- "!zubhub_backend/.dockerignore"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout files
uses: actions/checkout@v2
- name: Build and push django api
id: docker_build_web
uses: docker/build-push-action@v2
with:
context: ./zubhub_backend/
file: ./zubhub_backend/compose/web/prod/Dockerfile
push: true
tags: unstructuredstudio/zubhub-services_web:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Build and push celery worker
id: docker_build_celery
uses: docker/build-push-action@v2
with:
context: ./zubhub_backend/
file: ./zubhub_backend/compose/celery/prod/Dockerfile
push: true
tags: unstructuredstudio/zubhub-services_celery:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Build and push media service
id: docker_build_media
uses: docker/build-push-action@v2
with:
context: ./zubhub_backend/
file: ./zubhub_backend/compose/media/prod/Dockerfile
push: true
tags: unstructuredstudio/zubhub-services_media:latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Copy file via scp
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DO_BACKEND_HOST }}
username: ${{ secrets.DO_BACKEND_USERNAME }}
key: ${{ secrets.DO_SSHKEY }}
source: "."
target: "/home/zubhub-services/zubhub"
- name: Executing remote command
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DO_BACKEND_HOST }}
username: ${{ secrets.DO_BACKEND_USERNAME }}
key: ${{ secrets.DO_SSHKEY }}
script: |
cp /home/zubhub-services/zubhub/zubhub_backend/compose/deploy_backend.sh /home/zubhub-services/
sudo bash /home/zubhub-services/deploy_backend.sh
doctl compute droplet list 'zubhub-services*' > droplets.txt
droplets_count=`wc -l < droplets.txt`
rm droplets.txt
docker service scale zubhub-services_web=$(($droplets_count - 1))