Skip to content

Deploy to Production #29

Deploy to Production

Deploy to Production #29

Workflow file for this run

name: Deploy to Production
on:
workflow_dispatch:
inputs:
publish_docker:
description: 'Publish to Docker'
required: false
type: boolean
workflow_call:
inputs:
tag:
required: false
type: string
concurrency: production
jobs:
compile:
name: Compile and Test
uses: ./.github/workflows/compile.yml
if: ${{ inputs.publish_docker }}
publish_docker:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: [compile]
if: ${{ inputs.publish_docker }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: novosadkry/novaxis
tags: |
type=raw,value=${{ inputs.tag || github.ref_name }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
update_server:
name: Update production environment
runs-on: ubuntu-latest
needs: [publish_docker]
if: ${{ !failure() && !cancelled() }}
environment: production
steps:
- name: Replace Docker container
uses: appleboy/ssh-action@master
env:
TAG: ${{ inputs.tag || github.ref_name }}
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
envs: TAG
script: |
cd ./files/novaxis/
sudo -E docker-compose down
sudo -E docker-compose pull
sudo -E docker-compose up -d
restore_server:
name: Restore production environment
runs-on: ubuntu-latest
needs: [update_server]
if: ${{ failure() && needs.update_server.result == 'failure' }}
environment: production
steps:
- name: Replace Docker container
uses: appleboy/ssh-action@master
env:
TAG: 'latest'
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
envs: TAG
script: |
cd ./files/novaxis/
sudo -E docker-compose down
sudo -E docker-compose pull
sudo -E docker-compose up -d