-
Notifications
You must be signed in to change notification settings - Fork 6
213 lines (213 loc) · 7.87 KB
/
deploy-app.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Full CI/CD pipeline
# Use this to this to launch the workflow manually.
on: workflow_dispatch
# Uncomment the following lines to execute the job automatically.
#on:
# push:
# branches: [main]
env:
PLAYGROUND_PAT: ${{ secrets.PLAYGROUND_PAT}} #TODO: Store your PAT in this secret, or point to the correct one if it has a different name.
TARGET_DOCKER_REGISTRY: napptive #TODO: This should be your docker hub account.
PLAYGROUND_ACCOUNT_NAME: dhiguero #TODO: This should be your NAPPTIVE username.
jobs:
build:
name: Unit and Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '17'
- run: npm install
- run: npm test
upload-docker-revision:
needs: build
name: Push docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker Login
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKER_HUB_USER}}
password: ${{secrets.DOCKER_HUB_TOKEN}}
- name: Build and push Docker images
run: make docker-push
upload-app-def-revision:
needs: upload-docker-revision
name: Push the application definitions to the NAPPTIVE catalog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Render Kubernetes OAM files
run: make k8s
- name: Get Version
id: version
run: echo "::set-output name=version::$(cat version)"
- name: Push the application to the catalog
uses: napptive-actions/[email protected]
with:
applicationPath: ./build/k8s/todoapp
namespace: "napptive"
applicationName: "example-app-nodejs"
tag: ${{ steps.version.outputs.version }}
- name: Push the acceptance test runner to the catalog
uses: napptive-actions/[email protected]
with:
applicationPath: ./build/k8s/todoat
namespace: "napptive"
applicationName: "example-app-nodejs-at"
tag: ${{ steps.version.outputs.version }}
prepare-acceptance-test-env:
needs: [upload-app-def-revision, upload-docker-revision]
name: Prepare the environment to launch AT
runs-on: ubuntu-latest
outputs:
envname: ${{ steps.envname.outputs.envname }}
steps:
- uses: actions/checkout@v2
- name: Get Version
id: version
run: echo "::set-output name=version::$(cat version)"
- name: Set environment name
id: envname
run: echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-at-${GITHUB_RUN_ID}"
- name: Create test environment
uses: napptive-actions/[email protected]
with:
cmd: "env create ${{steps.envname.outputs.envname }}"
launch-acceptance-tests:
needs: prepare-acceptance-test-env
name: Launch the acceptance tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Version
id: get-version
run: echo "::set-output name=version::$(cat version)"
- name: Deploy the TODO app from the catalog
uses: napptive-actions/[email protected]
with:
appName: napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: Wait for TODO app
uses: napptive-actions/[email protected]
with:
cmd: "apps wait example-app-nodejs"
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: Deploy the TODO app AT runner from the catalog
uses: napptive-actions/[email protected]
with:
appName: napptive/example-app-nodejs-at:${{ steps.get-version.outputs.version }}
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: Wait for the test runner
uses: napptive-actions/[email protected]
continue-on-error: true
id: wait-at
with:
cmd: "apps wait example-app-nodejs-at --logContains TEST_SUCCESS --timeout=30s"
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: AT success
id: at-success
run: echo '::set-output name=at-result::true'
if: steps.wait-at.outcome == 'success'
- name: AT failure
id: at-failure
run: echo '::set-output name=at-result::false'
if: steps.wait-at.outcome == 'failure'
cleanup-acceptance-test-env:
if: ${{ always() }}
needs: [prepare-acceptance-test-env, launch-acceptance-tests]
name: Cleanup acceptance test environment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Remove todo app
uses: napptive-actions/[email protected]
continue-on-error: true
with:
cmd: "apps remove example-app-nodejs"
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: Remove AT app
uses: napptive-actions/[email protected]
continue-on-error: true
with:
cmd: "apps remove example-app-nodejs-at"
environment: ${{needs.prepare-acceptance-test-env.outputs.envname}}
- name: Cleanup test environment
uses: napptive-actions/[email protected]
continue-on-error: true
with:
cmd: "env remove ${{needs.prepare-acceptance-test-env.outputs.envname}}"
create-prod-env:
needs: [launch-acceptance-tests]
name: Create the production environment
runs-on: ubuntu-latest
outputs:
envname: ${{ steps.envname.outputs.envname }}
steps:
- uses: actions/checkout@v2
- name: Set environment name
id: envname
run: echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-app-prod"
- name: Create production environment
uses: napptive-actions/[email protected]
continue-on-error: true
with:
cmd: "env create ${{steps.envname.outputs.envname }}"
check-app-deployed:
needs: [create-prod-env]
name: Check if the application is deployed
runs-on: ubuntu-latest
outputs:
not-found: ${{ steps.not-found.outputs.not-found }}
found: ${{ steps.found.outputs.found }}
steps:
- uses: actions/checkout@v2
- name: Check if the app exists
uses: napptive-actions/[email protected]
continue-on-error: true
id: check
with:
cmd: "apps info example-app-nodejs"
environment: ${{needs.create-prod-env.outputs.envname}}
- name: Set App not found
id: not-found
run: echo '::set-output name=not-found::true'
if: steps.check.outcome != 'success'
- name: Set App found
id: found
run: echo '::set-output name=found::true'
if: steps.check.outcome != 'failure'
deploy-app:
name: Deploy application into production
needs: [create-prod-env, check-app-deployed]
runs-on: ubuntu-latest
if: ${{needs.check-app-deployed.outputs.not-found == 'true'}}
steps:
- uses: actions/checkout@v2
- name: Get Version
id: get-version
run: echo "::set-output name=version::$(cat version)"
- name: Deploy the app from the catalog
uses: napptive-actions/[email protected]
with:
appName: napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
environment: ${{needs.create-prod-env.outputs.envname}}
update-app:
name: Update application
needs: [create-prod-env, check-app-deployed]
runs-on: ubuntu-latest
if: ${{needs.check-app-deployed.outputs.found == 'true'}}
steps:
- uses: actions/checkout@v2
- name: Make scripts executable
run: chmod +x updateImage.sh
- name: Get Version
id: version
run: echo "::set-output name=version::$(cat version)"
- name: Deploy new version of the application
run: ./updateImage.sh
env:
VERSION: ${{ steps.version.outputs.version }}
ENV_NAME: ${{needs.create-prod-env.outputs.envname}}