-
Notifications
You must be signed in to change notification settings - Fork 71
135 lines (122 loc) · 4.82 KB
/
deploy-prod.yml
File metadata and controls
135 lines (122 loc) · 4.82 KB
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
name: Deploy (production)
run-name: "Deploy to ${{ inputs.environment }} with (core: ${{ inputs.core-image-tag }}, country config: ${{ inputs.countryconfig-image-tag }}, reset: ${{ inputs.reset }})"
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: Environment to deploy to
required: true
default: 'staging'
options:
- production
- staging
core-image-tag:
description: Core DockerHub image tag
required: true
default: 'v1.8.1'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
default: 'latest'
required: false
jobs:
deploy:
environment: ${{ inputs.environment }}
runs-on: ubuntu-24.04
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 ${{ inputs.countryconfig-image-tag }}
if: ${{ inputs.countryconfig-image-tag != 'latest' && inputs.countryconfig-image-tag != '' }}
working-directory: ${{ github.event.repository.name }}
run: git checkout ${{ inputs.countryconfig-image-tag }}
- name: Checkout core branch ${{ inputs.core-image-tag }}
working-directory: opencrvs-core
run: git checkout ${{ inputs.core-image-tag }}
- name: Resolve image tags
working-directory: ${{ github.event.repository.name }}
run: |
if [ '${{ inputs.countryconfig-image-tag }}' == 'latest' ] || [ '${{ inputs.countryconfig-image-tag }}' == '' ]
then
image_tag=`git rev-parse --short=7 HEAD`
message="⚠️ You haven't provided country config image tag, using latest git hash as image tag."
message="$message Please make sure image with tag was built and pushed to your registry"
else
image_tag=${{ inputs.countryconfig-image-tag }}
fi
message="Core image tag: ${{ inputs.core-image-tag }} \n\nCountry config image tag: $image_tag \n\n $message"
echo -e $message | tee -a $GITHUB_STEP_SUMMARY
echo "image_tag=$image_tag" >> $GITHUB_ENV
- name: Read known hosts
working-directory: ${{ github.event.repository.name }}
run: |
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 ghcr.io/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 }}:${{ env.image_tag }}; then
break
fi
sleep 10
done
- name: Export all secrets and environment variables
working-directory: ${{ github.event.repository.name }}
run: |
jq -n -r '
[${{ toJSON(secrets) }}, ${{ toJSON(vars) }}]
| add
| to_entries
| map(select(.value | test("\n") | not))
| map("\(.key)=\"\(.value)\"")
| .[]
' > .env.${{ inputs.environment }}
- name: Use Node.js from .nvmrc
uses: actions/setup-node@v4
with:
node-version-file: ${{ github.event.repository.name }}/.nvmrc
- name: Deploy to ${{ inputs.environment }}
id: deploy
working-directory: ${{ github.event.repository.name }}
run: |
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=${{ env.image_tag }} \
--replicas=${{ vars.REPLICAS }}