Skip to content

Commit

Permalink
Update deploy.yml and compile.yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
novosadkry committed Sep 1, 2023
1 parent 0099bf0 commit d324dff
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
strategy:
matrix:
configuration: [Debug, Release]
configuration: [Release]
os: [ubuntu-latest, windows-latest]

name: Build and Test
Expand All @@ -19,6 +19,15 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v3

# Fetch NuGet packages from cache
- name: Restore package cache
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj*') }}
restore-keys: |
${{ runner.os }}-nuget
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/deploy.yml
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

0 comments on commit d324dff

Please sign in to comment.