Deploy dependencies with reset=true core=b2e71bf country config=8628349 #98
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
name: Deploy (development) | |
run-name: Deploy ${{ inputs.stack }} with reset=${{ inputs.reset }} core=${{ inputs.core-image-tag }} country config=${{ inputs.countryconfig-image-tag }} | |
on: | |
workflow_call: | |
inputs: | |
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 | |
stack: | |
type: string | |
description: Stack name | |
required: true | |
dependencies: | |
type: string | |
description: Redeploy dependencies | |
default: 'false' | |
required: false | |
reset: | |
type: string | |
description: Reset the environment | |
default: 'false' | |
required: false | |
workflow_dispatch: | |
inputs: | |
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 | |
stack: | |
type: string | |
description: Stack name | |
required: true | |
dependencies: | |
type: boolean | |
description: Redeploy dependencies | |
default: false | |
required: false | |
reset: | |
type: boolean | |
description: Reset the environment | |
default: false | |
jobs: | |
download-images: | |
environment: ${{ inputs.stack }} | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 60 | |
steps: | |
- name: Check if vars.BLOCK_NEW_DEPLOYMENTS is set to true | |
run: | | |
if [[ "${{ vars.BLOCK_NEW_DEPLOYMENTS }}" == "true" ]]; then | |
echo "BLOCK_NEW_DEPLOYMENTS in Github environment settings is set to true, exiting..." | |
echo "Set the variable to anything other than 'true' and redeploy" | |
echo "https://github.com/opencrvs/e2e/settings/environments" | |
exit 1 | |
fi | |
- name: Clone country config resource package | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
path: './${{ github.event.repository.name }}' | |
- name: Checkout country branch | |
run: | | |
cd ${{ github.event.repository.name }} | |
cd ../ | |
- 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 ${{ vars.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.stack }} | |
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.stack }} | |
done < <( | |
jq -r ' | |
to_entries | | |
map( | |
select(.value | test("\n") | not) | | |
"\(.key)=\"\(.value)\"" | |
) | | |
.[]' <<< "$VARS_JSON_WITH_NEWLINES" | |
) | |
- name: Download images for ${{ inputs.stack }} | |
run: | | |
cd ./${{ github.event.repository.name }} | |
bash infrastructure/deployment/download-images.sh \ | |
--clear_data=no \ | |
--environment=${{ inputs.stack }} \ | |
--host=${{ vars.DOMAIN }} \ | |
--stack=${{ inputs.stack }} \ | |
--update-dependencies=${{ inputs.dependencies }} \ | |
--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 }} | |
deploy: | |
environment: ${{ inputs.stack }} | |
needs: download-images | |
runs-on: ubuntu-22.04 | |
concurrency: | |
group: deploy | |
cancel-in-progress: false | |
outputs: | |
outcome: ${{ steps.deploy.outcome }} | |
timeout-minutes: 60 | |
steps: | |
- name: Check if vars.BLOCK_NEW_DEPLOYMENTS is set to true | |
run: | | |
if [[ "${{ vars.BLOCK_NEW_DEPLOYMENTS }}" == "true" ]]; then | |
echo "BLOCK_NEW_DEPLOYMENTS in Github environment settings is set to true, exiting..." | |
echo "Set the variable to anything other than 'true' and redeploy" | |
echo "https://github.com/opencrvs/e2e/settings/environments" | |
exit 1 | |
fi | |
- name: Generate summary | |
run: | | |
echo "Deploying environment to https://${{ inputs.stack }}.${{ vars.DOMAIN }}" >> $GITHUB_STEP_SUMMARY | |
echo "Core image tag: ${{ inputs.core-image-tag }}" >> $GITHUB_STEP_SUMMARY | |
echo "Country config image tag: ${{ inputs.countryconfig-image-tag }}" >> $GITHUB_STEP_SUMMARY | |
echo "Reset environment: ${{ inputs.reset }}" >> $GITHUB_STEP_SUMMARY | |
echo "Redeploy dependencies: ${{ inputs.dependencies }}" >> $GITHUB_STEP_SUMMARY | |
- 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: 1 | |
path: './${{ github.event.repository.name }}' | |
- name: Checkout country branch | |
run: | | |
cd ${{ github.event.repository.name }} | |
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: 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.stack }} | |
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.stack }} | |
done < <( | |
jq -r ' | |
to_entries | | |
map( | |
select(.value | test("\n") | not) | | |
"\(.key)=\"\(.value)\"" | |
) | | |
.[]' <<< "$VARS_JSON_WITH_NEWLINES" | |
) | |
- name: Deploy to ${{ inputs.stack }} | |
id: deploy | |
run: | | |
cd ./${{ github.event.repository.name }} | |
yarn install | |
yarn deploy \ | |
--clear_data=no \ | |
--environment=${{ inputs.stack }} \ | |
--host=${{ vars.DOMAIN }} \ | |
--stack=${{ inputs.stack }} \ | |
--update-dependencies=${{ inputs.dependencies }} \ | |
--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.stack }} | |
stack: ${{ inputs.stack }} | |
secrets: inherit | |
seed-data: | |
needs: reset | |
if: ${{ inputs.reset == 'true' && needs.reset.outputs.outcome == 'success' }} | |
uses: ./.github/workflows/seed-data.yml | |
with: | |
environment: ${{ inputs.stack }} | |
core-image-tag: ${{ inputs.core-image-tag }} | |
stack: ${{ inputs.stack }} | |
secrets: inherit |