Skip to content

Commit

Permalink
Slightly improved deployment syntax, and added example deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
zachsa committed Oct 5, 2022
1 parent 31c76d5 commit 49eb375
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 4 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/deploy_example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# After forking the repository
# copy and adjust this deployment
# file to setup an automated deployment
# from the new, forked repository

name: Example deployment

on:
workflow_dispatch:

env:
REGISTRY: ghcr.io
NCCRD_IMAGE_NAME: ${{ github.repository }}_example_node
NGINX_IMAGE_NAME: ${{ github.repository }}_example_nginx
BRANCH_REF: main
DEPLOYMENT_HOSTNAME: ${{ secrets.DEPLOYMENT_HOSTNAME }} # Add as repository secret
DEPLOYMENT_HOST_USERNAME: ${{ secrets.DEPLOYMENT_HOST_USERNAME }} # Add as repository secret
DEPLOYMENT_HOST_PASSWORD: ${{ secrets.DEPLOYMENT_HOST_PASSWORD }} # Add as repository secret
DEPLOYMENT_HOST_SSH_PORT: ${{ secrets.DEPLOYMENT_HOST_SSH_PORT }} # Add as repository secret
ODP_AUTH_CLIENT_SECRET: ${{ secrets.ODP_AUTH_CLIENT_SECRET }} # Add as repository secret
MSSQL_PASSWORD: ${{ secrets.MSSQL_PASSWORD }} # Add as repository secret
MSSQL_USERNAME: ${{ secrets.MSSQL_USERNAME }} # Add as repository secret

jobs:
build-nginx:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
ref: ${{ env.BRANCH_REF }}

- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.NGINX_IMAGE_NAME }}
tags: |
type=sha
- name: Build and push NCCRD
uses: docker/build-push-action@v2
with:
context: src/nginx
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

build-nccrd:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Check out source code (shared)
uses: actions/checkout@v2
with:
ref: ${{ env.BRANCH_REF }}

- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.NCCRD_IMAGE_NAME }}
tags: |
type=sha
- name: Build and push NCCRD
uses: docker/build-push-action@v2
with:
context: .
build-args: |
HOSTNAME=https://your-domain.com
DEFAULT_NOTICES="This is the new deployment!,info"
SHOW_DEV_WARNING="true"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

deploy:
needs: [build-nginx, build-nccrd]
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
ref: ${{ env.BRANCH_REF }}

- name: (SCP) Copy Docker files to app server
uses: appleboy/scp-action@master
with:
host: ${{ env.DEPLOYMENT_HOSTNAME }}
username: ${{ env.DEPLOYMENT_HOST_USERNAME }}
password: ${{ env.DEPLOYMENT_HOST_PASSWORD }}
port: ${{ env.DEPLOYMENT_HOST_SSH_PORT }}
source: 'deploy/stable/stack.yml'
target: 'nccrd-stable'

- name: (SSH) Deploy Docker stack
uses: appleboy/ssh-action@master
with:
host: ${{ env.DEPLOYMENT_HOSTNAME }}
username: ${{ env.DEPLOYMENT_HOST_USERNAME }}
password: ${{ env.DEPLOYMENT_HOST_PASSWORD }}
port: ${{ env.DEPLOYMENT_HOST_SSH_PORT }}
script: |
echo "MSSQL_PASSWORD=${{ env.MSSQL_PASSWORD }}" > /home/runner/nccrd-stable/deploy/stable/stack.env
echo "MSSQL_USERNAME=${{ env.MSSQL_USERNAME }}" >> /home/runner/nccrd-stable/deploy/stable/stack.env
echo "NCCRD_IMAGE=${{ needs.build-nccrd.outputs.image }}" >> /home/runner/nccrd-stable/deploy/stable/stack.env
echo "NGINX_IMAGE=${{ needs.build-nginx.outputs.image }}" >> /home/runner/nccrd-stable/deploy/stable/stack.env
echo "ODP_AUTH_CLIENT_SECRET=${{ env.ODP_AUTH_CLIENT_SECRET }}" >> /home/runner/nccrd-stable/deploy/stable/stack.env
export $(cat /home/runner/nccrd-stable/deploy/stable/stack.env) > /dev/null 2>&1;
docker stack deploy -c /home/runner/nccrd-stable/deploy/stable/stack.yml nccrd_stable
4 changes: 2 additions & 2 deletions .github/workflows/deploy_nccrd.environment.gov.za.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: src/nginx
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
build-args: |
HOSTNAME=https://nccrd.environment.gov.za
SHOW_DEV_WARNING="false"
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_nccrd.saeon.ac.za.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: src/nginx
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
HOSTNAME=https://nccrd.saeon.ac.za
DEFAULT_NOTICES="This is the DEVELOPMENT deployment,warn"
SHOW_DEV_WARNING="true"
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down

0 comments on commit 49eb375

Please sign in to comment.