-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update deploy.yml and compile.yml files
- Loading branch information
1 parent
0099bf0
commit d324dff
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
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@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: novosadkry/novaxis | ||
tags: | | ||
type=raw,value=${{ inputs.tag || github.ref_name }} | ||
flavor: | | ||
latest=false | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
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 |