Skip to content

Deploy NATS

Deploy NATS #15

Workflow file for this run

name: Deploy NATS
on:
workflow_dispatch:
inputs:
clear_jetstream:
description: 'Clear Jetstream'
required: true
default: 'false'
type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
detect-deployment-environment:
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.set-env.outputs.environment }}
steps:
- name: Determine deployment environment
id: set-env
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "::set-output name=environment::production"
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
echo "::set-output name=environment::staging"
else
echo "::set-output name=environment::none"
fi
deploy_nats:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
needs:
- detect-deployment-environment
if: github.ref_name == 'main' || github.ref_name == 'dev'
environment:
name: ${{ needs.detect-deployment-environment.outputs.environment }}
env:
CLEAR_JETSTREAM: ${{ github.event.inputs.clear_jetstream }}
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DEVELOPER_TOKEN: ${{ secrets.DEVELOPER_TOKEN }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PY_DATABASE_URL: ${{ secrets.PY_DATABASE_URL }}
FASTSTREAM_NATS_PASSWORD: ${{ secrets.FASTSTREAM_NATS_PASSWORD }}
WASP_NATS_PASSWORD: ${{ secrets.WASP_NATS_PASSWORD }}
AUTH_NATS_PASSWORD: ${{ secrets.AUTH_NATS_PASSWORD }}
NATS_PUB_NKEY: ${{ secrets.NATS_PUB_NKEY }}
DOMAIN: ${{ vars.DOMAIN }}
SSH_KEY: ${{ secrets.SSH_KEY }}
steps:
- uses: actions/checkout@v3 # Don't change it to cheackout@v4. V4 is not working with container image.
# This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
- run: chown -R $(id -u):$(id -g) $PWD
- run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "TAG=latest" >> $GITHUB_ENV ; else echo "TAG=dev" >> $GITHUB_ENV ; fi;
- run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
- run: "which ssh-agent || ( apt-get update -y && apt-get install openssh-client git gettext -y )"
- run: eval $(ssh-agent -s)
- run: mkdir -p ~/.ssh
- run: chmod 700 ~/.ssh
- run: ssh-keyscan "$DOMAIN" >> ~/.ssh/known_hosts
- run: chmod 644 ~/.ssh/known_hosts
- run: echo "$SSH_KEY" | base64 --decode > key.pem
- run: chmod 600 key.pem
- run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$DOMAIN" "docker images"
- run: bash scripts/deploy-nats.sh
- run: rm key.pem