-
Notifications
You must be signed in to change notification settings - Fork 12
168 lines (155 loc) · 5.32 KB
/
build-deploy.yaml
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
167
168
name: Build Deploy All
on:
workflow_dispatch:
inputs:
environment:
required: false
description: Specify environment to run on. Valid values are test, production
apps:
required: false
default: aggregator api draft notifier indexer-processor
description: List of application to build (space separated).
push:
branches:
- develop
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ECR_URL: ${{ secrets.AWS_ECR_URL }}
EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME }}
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
jobs:
get-updated-apps:
name: Get Updated Apps
runs-on: ubuntu-latest
outputs:
updated-apps: ${{ steps.updated-apps.outputs.apps }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- id: updated-apps
shell: bash
run: |
array_to_json () {
echo "[$(echo $1 | xargs | sed -e 's| |", "|g;s|.*|"&"|')]"
}
if [[ "${{ github.event.inputs.apps }}" != "" ]]
then
echo "List of apps was provided manually: ${{ github.event.inputs.apps }}"
export UPDATED_APPS=$(array_to_json "${{ github.event.inputs.apps }}")
echo "::set-output name=apps::$UPDATED_APPS"
exit 0
fi
echo "::set-output name=apps::[\"aggregator\", \"api\", \"notifier\", \"draft\", \"indexer-processor\"]"
get-environment:
name: Get Environment
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.get-environment.outputs.environment }}
tag: ${{ steps.get-environment.outputs.tag }}
steps:
- name: get environment
id: get-environment
shell: bash
run: |
if [[ "${{ github.ref }}" =~ ^refs/heads/develop ]]
then
echo "::set-output name=environment::test"
fi
if [[ "${{ github.event.inputs.environment }}" != "" ]]
then
echo "input environment was provided: ${{ github.event.inputs.environment }}"
echo "::set-output name=environment::${{ github.event.inputs.environment }}"
fi
if [[ "${{ inputs.tag }}" != "" ]]
then
echo "input tag was provided: ${{ inputs.tag }}"
echo "::set-output name=tag::${{ inputs.tag }}"
else
echo "tag was not provided, using commit sha: ${{ github.sha }}"
echo "::set-output name=tag::${{ github.sha }}"
fi
build-images:
name: Build Image
strategy:
matrix:
app: ${{ fromJSON(needs.get-updated-apps.outputs.updated-apps) }}
runs-on: ubuntu-latest
needs:
- get-updated-apps
steps:
- uses: actions/checkout@v2
- name: Set Environment
run: |
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV
- name: Docker Build Publish
env:
APP_NAME: ${{ matrix.app }}
uses: ./.github/actions/docker-build-publish
helm-deploy:
name: Helm Deploy
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.get-updated-apps.outputs.updated-apps) }}
fail-fast: false
needs:
- get-updated-apps
- get-environment
- build-images
environment:
name: ${{ needs.get-environment.outputs.environment }}
steps:
- uses: actions/checkout@v2
- name: Set Environment
run: |
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV
cat ".github/env.${{ needs.get-environment.outputs.environment }}" | grep -E -v '^\ *#' >>$GITHUB_ENV
- name: Helm Deploy
uses: near-daos/github-actions/deploy@main
with:
name: astro-${{ matrix.app }}
namespace: ${{ env.DEPLOYMENT_NAMESPACE }}
tag: ${{ needs.get-environment.outputs.tag }}
chart_directory: apps/${{ matrix.app }}/deployment/app-chart
debug: "true"
- name: Tag Previous Image
uses: tmknom/retag-ecr-action@v1
with:
repository-name: astro-${{ matrix.app }}
source-tag: ${{ needs.get-environment.outputs.environment }}-current
destination-tag: ${{ needs.get-environment.outputs.environment }}-previous
- name: Tag Current Image
uses: tmknom/retag-ecr-action@v1
with:
repository-name: astro-${{ matrix.app }}
source-tag: ${{ needs.get-environment.outputs.tag }}
destination-tag: ${{ needs.get-environment.outputs.environment }}-current
# experimental sleep to nail down issue with tests failing after deploy
wait-for-aggregator:
name: Wait For Aggregator
runs-on: ubuntu-latest
if: needs.get-environment.outputs.environment == 'test'
needs:
- helm-deploy
- get-environment
steps:
- name: sleep
run: |
sleep 300
run-autotests:
name: Run Autotests
needs:
- helm-deploy
- get-environment
- wait-for-aggregator
if: needs.get-environment.outputs.environment == 'test'
uses: near-daos/astro-api-gateway/.github/workflows/run-autotests.yaml@develop
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NEAR_ACCOUNT_ID: ${{ secrets.NEAR_ACCOUNT_ID }}
NEAR_PUBLIC_KEY: ${{ secrets.NEAR_PUBLIC_KEY }}
NEAR_PRIVATE_KEY: ${{ secrets.NEAR_PRIVATE_KEY }}
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}