Skip to content

Deploy to development with reset=false core=d3697f3 country config=7623c34 #581

Deploy to development with reset=false core=d3697f3 country config=7623c34

Deploy to development with reset=false core=d3697f3 country config=7623c34 #581

Workflow file for this run

name: Deploy (development)
run-name: Deploy to ${{ inputs.environment }} with reset=${{ inputs.reset }} core=${{ inputs.core-image-tag }} country config=${{ inputs.countryconfig-image-tag }}
on:
workflow_call:
inputs:
environment:
type: string
description: Environment to deploy to
required: true
core-image-tag:
type: string
description: Core DockerHub image tag
required: true
default: 'v1.4.1'
countryconfig-image-tag:
type: string
description: Your Country Config DockerHub image tag
required: true
reset:
type: string
description: Reset the environment
default: 'false'
required: false
debug:
type: boolean
description: Open SSH session to the runner after deployment
default: false
required: false
workflow_dispatch:
inputs:
environment:
type: choice
description: Environment to deploy to
required: true
default: 'staging'
options:
- staging
- qa
- development
core-image-tag:
description: Core DockerHub image tag
required: true
default: 'v1.6.0'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
required: true
reset:
type: boolean
description: Reset the environment
default: false
jobs:
deploy:
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
outputs:
outcome: ${{ steps.deploy.outcome }}
timeout-minutes: 60
steps:
- name: Clone core
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: 'opencrvs/opencrvs-core'
path: './opencrvs-core'
- name: Clone country config resource package
uses: actions/checkout@v3
with:
fetch-depth: 0
path: './${{ github.event.repository.name }}'
- name: Checkout country branch
run: |
cd ${{ github.event.repository.name }}
git checkout ${{ inputs.countryconfig-image-tag }}
cd ../
- name: Checkout core branch
run: |
cd opencrvs-core
git checkout ${{ inputs.core-image-tag }}
- name: Read known hosts
run: |
cd ${{ github.event.repository.name }}
echo "KNOWN_HOSTS<<EOF" >> $GITHUB_ENV
sed -i -e '$a\' ./infrastructure/known-hosts
cat ./infrastructure/known-hosts >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ env.KNOWN_HOSTS }}
- name: Unset KNOWN_HOSTS variable
run: |
echo "KNOWN_HOSTS=" >> $GITHUB_ENV
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Wait for images to be available
run: |
while true; do
if docker manifest inspect opencrvs/ocrvs-auth:${{ inputs.core-image-tag }}; then
break
fi
sleep 10
done
while true; do
if docker manifest inspect ${{ secrets.DOCKERHUB_ACCOUNT }}/${{ secrets.DOCKERHUB_REPO }}:${{ inputs.countryconfig-image-tag }}; then
break
fi
sleep 10
done
- name: Export all secrets and environment variables
run: |
cd ./${{ github.event.repository.name }}
SECRETS_JSON_WITH_NEWLINES=$(cat<<EOF
${{ toJSON(secrets) }}
EOF)
#
# Secrets & variables with newlines are filtered out automatically
# This includes SSH_KEY and KNOWN_HOSTS
#
while IFS= read -r secret; do
echo "$secret" >> .env.${{ inputs.environment }}
done < <(
jq -r '
to_entries |
map(
select(.value | test("\n") | not) |
"\(.key)=\"\(.value)\""
) |
.[]' <<< "$SECRETS_JSON_WITH_NEWLINES"
)
VARS_JSON_WITH_NEWLINES=$(cat<<EOF
${{ toJSON(vars) }}
EOF)
while IFS= read -r var; do
echo "$var" >> .env.${{ inputs.environment }}
done < <(
jq -r '
to_entries |
map(
select(.value | test("\n") | not) |
"\(.key)=\"\(.value)\""
) |
.[]' <<< "$VARS_JSON_WITH_NEWLINES"
)
- name: Deploy to ${{ inputs.environment }}
id: deploy
run: |
cd ./${{ github.event.repository.name }}
yarn deploy \
--clear_data=no \
--environment=${{ inputs.environment }} \
--host=${{ vars.DOMAIN }} \
--ssh_host=${{ vars.SSH_HOST || secrets.SSH_HOST }} \
--ssh_port=${{ vars.SSH_PORT || secrets.SSH_PORT }} \
--ssh_user=${{ secrets.SSH_USER }} \
--version=${{ inputs.core-image-tag }} \
--country_config_version=${{ inputs.countryconfig-image-tag }} \
--replicas=${{ vars.REPLICAS }}
reset:
needs: deploy
if: ${{ inputs.reset == 'true' && needs.deploy.outputs.outcome == 'success' }}
uses: ./.github/workflows/clear-environment.yml
with:
environment: ${{ inputs.environment }}
secrets: inherit
seed-data:
needs: reset
if: ${{ inputs.reset == 'true' && needs.reset.outputs.outcome == 'success' }}
uses: ./.github/workflows/seed-data.yml
with:
environment: ${{ inputs.environment }}
core-image-tag: ${{ inputs.core-image-tag }}
secrets: inherit