Skip to content

Commit 35dbed7

Browse files
authored
Merge branch 'develop' into release-v1.6.4
2 parents 12401e2 + 5a43ee8 commit 35dbed7

File tree

116 files changed

+27882
-5559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+27882
-5559
lines changed

.github/workflows/deploy-prod.yml

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
core-image-tag:
1515
description: Core DockerHub image tag
1616
required: true
17-
default: 'v1.6.1'
17+
default: 'v1.6.3'
1818
countryconfig-image-tag:
1919
description: Your Country Config DockerHub image tag
2020
required: true
@@ -28,11 +28,34 @@ jobs:
2828
- uses: trstringer/manual-approval@v1
2929
with:
3030
secret: ${{ github.TOKEN }}
31-
approvers: euanmillar,rikukissa
31+
approvers: rochel07,solomcfly
3232
minimum-approvals: 1
3333
issue-title: 'Deploy (${{ github.event.inputs.environment }}): core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }}'
3434
issue-body: 'Please approve or deny the deployment of core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }} to ${{ github.event.inputs.environment }}'
3535
exclude-workflow-initiator-as-approver: false
36+
- name: Set ENV_VAR dynamically
37+
run: echo "ENV_VAR=ENV_${{ github.event.inputs.environment }}" >> $GITHUB_ENV
38+
39+
- name: Create .env file
40+
run: |
41+
echo "${{ vars[env.ENV_VAR] }}" | sed 's/[[:space:]]*$//' | awk -F= '{print $1 "=\"" $2 "\""}' > .env.${{ github.event.inputs.environment }}
42+
43+
- name: Load environment variables
44+
run: |
45+
set -a
46+
source .env.${{ github.event.inputs.environment }}
47+
set +a
48+
49+
- name: Charger les variables autrement
50+
run: |
51+
while IFS= read -r line; do
52+
if [[ ! -z "$line" && "$line" != \#* ]]; then
53+
line=$(echo "$line" | sed -E 's/^([^=]+)="(.*)"$/\1=\2/')
54+
export "$line"
55+
echo "$line" >> $GITHUB_ENV
56+
fi
57+
done < .env.${{ github.event.inputs.environment }}
58+
3659
- name: Clone core
3760
uses: actions/checkout@v3
3861
with:
@@ -64,11 +87,12 @@ jobs:
6487
cat ./infrastructure/known-hosts >> $GITHUB_ENV
6588
echo "EOF" >> $GITHUB_ENV
6689
67-
- name: Install SSH Key
90+
- name: Install SSH Key for Prod
6891
uses: shimataro/ssh-key-action@v2
6992
with:
70-
key: ${{ secrets.SSH_KEY }}
93+
key: ${{ secrets.SSH_KEY_PROD }}
7194
known_hosts: ${{ env.KNOWN_HOSTS }}
95+
if: ${{ github.event.inputs.environment == 'production' }}
7296

7397
- name: Unset KNOWN_HOSTS variable
7498
run: |
@@ -95,56 +119,18 @@ jobs:
95119
sleep 10
96120
done
97121
98-
- name: Export all secrets and environment variables
99-
run: |
100-
cd ./${{ github.event.repository.name }}
101-
102-
SECRETS_JSON_WITH_NEWLINES=$(cat<<EOF
103-
${{ toJSON(secrets) }}
104-
EOF)
105-
106-
#
107-
# Secrets & variables with newlines are filtered out automatically
108-
# This includes SSH_KEY and KNOWN_HOSTS
109-
#
110-
while IFS= read -r secret; do
111-
echo "$secret" >> .env.${{ github.event.inputs.environment }}
112-
done < <(
113-
jq -r '
114-
to_entries |
115-
map(
116-
select(.value | test("\n") | not) |
117-
"\(.key)=\"\(.value)\""
118-
) |
119-
.[]' <<< "$SECRETS_JSON_WITH_NEWLINES"
120-
)
121-
122-
VARS_JSON_WITH_NEWLINES=$(cat<<EOF
123-
${{ toJSON(vars) }}
124-
EOF)
125-
126-
while IFS= read -r var; do
127-
echo "$var" >> .env.${{ github.event.inputs.environment }}
128-
done < <(
129-
jq -r '
130-
to_entries |
131-
map(
132-
select(.value | test("\n") | not) |
133-
"\(.key)=\"\(.value)\""
134-
) |
135-
.[]' <<< "$VARS_JSON_WITH_NEWLINES"
136-
)
137-
138122
- name: Deploy to ${{ github.event.inputs.environment }}
139123
run: |
124+
export DOCKER_USERNAME="${{ secrets.DOCKER_USERNAME }}"
125+
export DOCKER_TOKEN="${{ secrets.DOCKER_TOKEN }}"
140126
cd ./${{ github.event.repository.name }}
141127
yarn deploy \
142128
--clear_data=no \
143129
--environment=${{ github.event.inputs.environment }} \
144-
--host=${{ vars.DOMAIN }} \
145-
--ssh_host=${{ vars.SSH_HOST || secrets.SSH_HOST }} \
146-
--ssh_port=${{ vars.SSH_PORT || secrets.SSH_PORT }} \
147-
--ssh_user=${{ secrets.SSH_USER }} \
130+
--host=$DOMAIN \
131+
--ssh_host=$SSH_HOST \
132+
--ssh_port=$SSH_PORT \
133+
--ssh_user=$SSH_USER \
148134
--version=${{ github.event.inputs.core-image-tag }} \
149135
--country_config_version=${{ github.event.inputs.countryconfig-image-tag }} \
150-
--replicas=${{ vars.REPLICAS }}
136+
--replicas=$REPLICAS

.github/workflows/deploy.yml

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
core-image-tag:
1616
description: Core DockerHub image tag
1717
required: true
18-
default: 'v1.6.1'
18+
default: 'v1.6.3'
1919
countryconfig-image-tag:
2020
description: Your Country Config DockerHub image tag
2121
required: true
@@ -31,6 +31,29 @@ jobs:
3131
outcome: ${{ steps.deploy.outcome }}
3232
timeout-minutes: 60
3333
steps:
34+
- name: Set ENV_VAR dynamically
35+
run: echo "ENV_VAR=ENV_${{ github.event.inputs.environment }}" >> $GITHUB_ENV
36+
37+
- name: Create .env file
38+
run: |
39+
echo "${{ vars[env.ENV_VAR] }}" | sed 's/[[:space:]]*$//' | awk -F= '{print $1 "=\"" $2 "\""}' > .env.${{ github.event.inputs.environment }}
40+
41+
- name: Load environment variables
42+
run: |
43+
set -a
44+
source .env.${{ github.event.inputs.environment }}
45+
set +a
46+
47+
- name: Charger les variables autrement
48+
run: |
49+
while IFS= read -r line; do
50+
if [[ ! -z "$line" && "$line" != \#* ]]; then
51+
line=$(echo "$line" | sed -E 's/^([^=]+)="(.*)"$/\1=\2/')
52+
export "$line"
53+
echo "$line" >> $GITHUB_ENV
54+
fi
55+
done < .env.${{ github.event.inputs.environment }}
56+
3457
- name: Clone core
3558
uses: actions/checkout@v3
3659
with:
@@ -62,11 +85,26 @@ jobs:
6285
cat ./infrastructure/known-hosts >> $GITHUB_ENV
6386
echo "EOF" >> $GITHUB_ENV
6487
65-
- name: Install SSH Key
88+
- name: Install SSH Key for QA
89+
uses: shimataro/ssh-key-action@v2
90+
with:
91+
key: ${{ secrets.SSH_KEY_QA }}
92+
known_hosts: ${{ env.KNOWN_HOSTS }}
93+
if: ${{ github.event.inputs.environment == 'qa' }}
94+
95+
- name: Install SSH Key for Staging
96+
uses: shimataro/ssh-key-action@v2
97+
with:
98+
key: ${{ secrets.SSH_KEY_STAGING }}
99+
known_hosts: ${{ env.KNOWN_HOSTS }}
100+
if: ${{ github.event.inputs.environment == 'staging' }}
101+
102+
- name: Install SSH Key for Prod
66103
uses: shimataro/ssh-key-action@v2
67104
with:
68-
key: ${{ secrets.SSH_KEY }}
105+
key: ${{ secrets.SSH_KEY_PROD }}
69106
known_hosts: ${{ env.KNOWN_HOSTS }}
107+
if: ${{ github.event.inputs.environment == 'production' }}
70108

71109
- name: Unset KNOWN_HOSTS variable
72110
run: |
@@ -93,60 +131,22 @@ jobs:
93131
sleep 10
94132
done
95133
96-
- name: Export all secrets and environment variables
97-
run: |
98-
cd ./${{ github.event.repository.name }}
99-
100-
SECRETS_JSON_WITH_NEWLINES=$(cat<<EOF
101-
${{ toJSON(secrets) }}
102-
EOF)
103-
104-
#
105-
# Secrets & variables with newlines are filtered out automatically
106-
# This includes SSH_KEY and KNOWN_HOSTS
107-
#
108-
while IFS= read -r secret; do
109-
echo "$secret" >> .env.${{ github.event.inputs.environment }}
110-
done < <(
111-
jq -r '
112-
to_entries |
113-
map(
114-
select(.value | test("\n") | not) |
115-
"\(.key)=\"\(.value)\""
116-
) |
117-
.[]' <<< "$SECRETS_JSON_WITH_NEWLINES"
118-
)
119-
120-
VARS_JSON_WITH_NEWLINES=$(cat<<EOF
121-
${{ toJSON(vars) }}
122-
EOF)
123-
124-
while IFS= read -r var; do
125-
echo "$var" >> .env.${{ github.event.inputs.environment }}
126-
done < <(
127-
jq -r '
128-
to_entries |
129-
map(
130-
select(.value | test("\n") | not) |
131-
"\(.key)=\"\(.value)\""
132-
) |
133-
.[]' <<< "$VARS_JSON_WITH_NEWLINES"
134-
)
135-
136134
- name: Deploy to ${{ github.event.inputs.environment }}
137135
id: deploy
138136
run: |
137+
export DOCKER_USERNAME="${{ secrets.DOCKER_USERNAME }}"
138+
export DOCKER_TOKEN="${{ secrets.DOCKER_TOKEN }}"
139139
cd ./${{ github.event.repository.name }}
140140
yarn deploy \
141141
--clear_data=no \
142142
--environment=${{ github.event.inputs.environment }} \
143-
--host=${{ vars.DOMAIN }} \
144-
--ssh_host=${{ vars.SSH_HOST || secrets.SSH_HOST }} \
145-
--ssh_port=${{ vars.SSH_PORT || secrets.SSH_PORT }} \
146-
--ssh_user=${{ secrets.SSH_USER }} \
143+
--host=$DOMAIN \
144+
--ssh_host=$SSH_HOST \
145+
--ssh_port=$SSH_PORT \
146+
--ssh_user=$SSH_USER \
147147
--version=${{ github.event.inputs.core-image-tag }} \
148148
--country_config_version=${{ github.event.inputs.countryconfig-image-tag }} \
149-
--replicas=${{ vars.REPLICAS }}
149+
--replicas=$REPLICAS
150150
151151
reset:
152152
needs: deploy
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
#
5+
# OpenCRVS is also distributed under the terms of the Civil Registration
6+
# & Healthcare Disclaimer located at http://opencrvs.org/license.
7+
#
8+
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
9+
name: Extract backup file on environment
10+
11+
on:
12+
workflow_dispatch:
13+
inputs:
14+
backup-destination-environment:
15+
type: choice
16+
description: Environment backup file is located
17+
required: true
18+
default: qa
19+
options:
20+
- qa
21+
- staging
22+
- production
23+
version_label:
24+
description: The version label for the backups
25+
required: true
26+
jobs:
27+
extract-backup-file:
28+
environment: ${{ github.event.inputs.backup-destination-environment }}
29+
runs-on: ubuntu-22.04
30+
env:
31+
BACKUP_DESTINATION_SSH_HOST: ${{ vars.SSH_HOST || secrets.SSH_HOST }}
32+
BACKUP_DESTINATION_SSH_PORT: ${{ vars.SSH_PORT || secrets.SSH_PORT }}
33+
BACKUP_DESTINATION_SSH_USER: ${{ secrets.SSH_USER }}
34+
BACKUP_DESTINATION_SSH_KEY: ${{ secrets.SSH_KEY }}
35+
BACKUP_DESTINATION_DIR: /tmp/backup-${{ github.event.inputs.version_label }}/${{ github.event.inputs.version_label }}
36+
steps:
37+
- name: Clone country config resource package
38+
uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 0
41+
path: './${{ github.event.repository.name }}'
42+
43+
- name: Read known hosts
44+
run: |
45+
cd ${{ github.event.repository.name }}
46+
echo "KNOWN_HOSTS<<EOF" >> $GITHUB_ENV
47+
sed -i -e '$a\' ./infrastructure/known-hosts
48+
cat ./infrastructure/known-hosts >> $GITHUB_ENV
49+
echo "EOF" >> $GITHUB_ENV
50+
51+
- name: Install SSH Key
52+
uses: shimataro/ssh-key-action@v2
53+
with:
54+
key: ${{ env.BACKUP_DESTINATION_SSH_KEY }}
55+
known_hosts: ${{ env.KNOWN_HOSTS }}
56+
- name: Extract backup data in backup environment
57+
run: |
58+
cd ${{ github.event.repository.name }}
59+
scp -P $BACKUP_DESTINATION_SSH_PORT infrastructure/backups/extract-backup.sh $BACKUP_DESTINATION_SSH_USER@$BACKUP_DESTINATION_SSH_HOST:/tmp/
60+
ssh $BACKUP_DESTINATION_SSH_USER@$BACKUP_DESTINATION_SSH_HOST -p $BACKUP_DESTINATION_SSH_PORT "\
61+
sudo bash /tmp/extract-backup.sh \
62+
--label=${{ github.event.inputs.version_label }} \
63+
--backup_raw_files_dir=$BACKUP_DESTINATION_DIR >> /tmp/opencrvs-backup-extract-${{ github.event.inputs.version_label }}.log 2>&1"

.github/workflows/get-secret-from-environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ on:
2727
required: false
2828
SSH_KEY:
2929
required: false
30+
SSH_USER:
31+
required: false
3032

3133
jobs:
3234
check-environment:

0 commit comments

Comments
 (0)