-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (151 loc) · 5.33 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Deploy (development)
run-name: Deploy to ${{ github.event.inputs.environment }} with reset=${{ github.event.inputs.reset }} core=${{ github.event.inputs.core-image-tag }} country config=${{ github.event.inputs.countryconfig-image-tag }}
on:
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.4.1'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
required: true
reset:
type: boolean
description: Reset the environment
default: false
jobs:
deploy:
environment: ${{ github.event.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 ${{ github.event.inputs.countryconfig-image-tag }}
cd ../
- name: Checkout core branch
run: |
cd opencrvs-core
git checkout ${{ github.event.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:${{ github.event.inputs.core-image-tag }}; then
break
fi
sleep 10
done
while true; do
if docker manifest inspect ${{ secrets.DOCKERHUB_ACCOUNT }}/${{ secrets.DOCKERHUB_REPO }}:${{ github.event.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.${{ github.event.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.${{ github.event.inputs.environment }}
done < <(
jq -r '
to_entries |
map(
select(.value | test("\n") | not) |
"\(.key)=\"\(.value)\""
) |
.[]' <<< "$VARS_JSON_WITH_NEWLINES"
)
- name: Deploy to ${{ github.event.inputs.environment }}
id: deploy
run: |
cd ./${{ github.event.repository.name }}
yarn deploy \
--clear_data=no \
--environment=${{ github.event.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=${{ github.event.inputs.core-image-tag }} \
--country_config_version=${{ github.event.inputs.countryconfig-image-tag }} \
--replicas=${{ vars.REPLICAS }}
reset:
needs: deploy
if: ${{ github.event.inputs.reset == 'true' && needs.deploy.outputs.outcome == 'success' }}
uses: ./.github/workflows/clear-environment.yml
with:
environment: ${{ github.event.inputs.environment }}
secrets: inherit
seed-data:
needs: reset
if: ${{ github.event.inputs.reset == 'true' && needs.reset.outputs.outcome == 'success' }}
uses: ./.github/workflows/seed-data.yml
with:
environment: ${{ github.event.inputs.environment }}
core-image-tag: ${{ github.event.inputs.core-image-tag }}
secrets: inherit