1
+ name : Full CI/CD pipeline
2
+ # Use this to this to launch the workflow manually.
3
+ on : workflow_dispatch
4
+ # Uncomment the following lines to execute the job automatically.
5
+ # on:
6
+ # push:
7
+ # branches: [main]
8
+ env :
9
+ PLAYGROUND_PAT : ${{ secrets.PLAYGROUND_PRODUCTION_PAT}} # TODO: Store your PAT in this secret, or point to the correct one if it has a different name.
10
+ TARGET_DOCKER_REGISTRY : napptive # TODO: This should be your docker hub account.
11
+ PLAYGROUND_ACCOUNT_NAME : dhiguero # TODO: This should be your NAPPTIVE username.
12
+ jobs :
13
+ build :
14
+ name : Unit and Integration Tests
15
+ runs-on : ubuntu-latest
16
+ steps :
17
+ - uses : actions/checkout@v2
18
+ - uses : actions/setup-node@v2
19
+ with :
20
+ node-version : ' 17'
21
+ - run : npm install
22
+ - run : npm test
23
+ upload-docker-revision :
24
+ needs : build
25
+ name : Push docker images
26
+ runs-on : ubuntu-latest
27
+ steps :
28
+ - uses : actions/checkout@v2
29
+ - name : Docker Login
30
+ uses : docker/login-action@v1
31
+ with :
32
+ username : ${{secrets.DOCKER_HUB_USER}}
33
+ password : ${{secrets.DOCKER_HUB_TOKEN}}
34
+ - name : Build and push Docker images
35
+ run : make docker-push
36
+ upload-app-def-revision :
37
+ needs : upload-docker-revision
38
+ name : Push the application definitions to the NAPPTIVE catalog
39
+ runs-on : ubuntu-latest
40
+ steps :
41
+ - uses : actions/checkout@v2
42
+ - name : Render Kubernetes OAM files
43
+ run : make k8s
44
+ - name : Get Version
45
+ id : version
46
+ run : echo "::set-output name=version::$(cat version)"
47
+ - name : Push the application to the catalog
48
+ uses :
napptive-actions/[email protected]
49
+ with :
50
+ applicationPath : ./build/k8s/todoapp
51
+ namespace : " napptive"
52
+ applicationName : " example-app-nodejs"
53
+ tag : ${{ steps.version.outputs.version }}
54
+ - name : Push the acceptance test runner to the catalog
55
+ uses :
napptive-actions/[email protected]
56
+ with :
57
+ applicationPath : ./build/k8s/todoat
58
+ namespace : " napptive"
59
+ applicationName : " example-app-nodejs-at"
60
+ tag : ${{ steps.version.outputs.version }}
61
+ prepare-acceptance-test-env :
62
+ needs : [upload-app-def-revision, upload-docker-revision]
63
+ name : Prepare the environment to launch AT
64
+ runs-on : ubuntu-latest
65
+ outputs :
66
+ envname : ${{ steps.envname.outputs.envname }}
67
+ steps :
68
+ - uses : actions/checkout@v2
69
+ - name : Get Version
70
+ id : version
71
+ run : echo "::set-output name=version::$(cat version)"
72
+ - name : Set environment name
73
+ id : envname
74
+ run : echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-at-${GITHUB_RUN_ID}"
75
+ - name : Create test environment
76
+ uses :
napptive-actions/[email protected]
77
+ with :
78
+ cmd : " env create ${{steps.envname.outputs.envname }}"
79
+ launch-acceptance-tests :
80
+ needs : prepare-acceptance-test-env
81
+ name : Launch the acceptance tests
82
+ runs-on : ubuntu-latest
83
+ steps :
84
+ - uses : actions/checkout@v2
85
+ - name : Get Version
86
+ id : get-version
87
+ run : echo "::set-output name=version::$(cat version)"
88
+ - name : Deploy the TODO app from the catalog
89
+ uses :
napptive-actions/[email protected]
90
+ with :
91
+ appName : napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
92
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
93
+ - name : Wait for TODO app
94
+ uses :
napptive-actions/[email protected]
95
+ with :
96
+ cmd : " apps wait example-app-nodejs"
97
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
98
+ - name : Deploy the TODO app AT runner from the catalog
99
+ uses :
napptive-actions/[email protected]
100
+ with :
101
+ appName : napptive/example-app-nodejs-at:${{ steps.get-version.outputs.version }}
102
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
103
+ - name : Wait for the test runner
104
+ uses :
napptive-actions/[email protected]
105
+ continue-on-error : true
106
+ id : wait-at
107
+ with :
108
+ cmd : " apps wait example-app-nodejs-at --logContains TEST_SUCCESS --timeout=30s"
109
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
110
+ - name : AT success
111
+ id : at-success
112
+ run : echo '::set-output name=at-result::true'
113
+ if : steps.wait-at.outcome == 'success'
114
+ - name : AT failure
115
+ id : at-failure
116
+ run : echo '::set-output name=at-result::false'
117
+ if : steps.wait-at.outcome == 'failure'
118
+ cleanup-acceptance-test-env :
119
+ if : ${{ always() }}
120
+ needs : [prepare-acceptance-test-env, launch-acceptance-tests]
121
+ name : Cleanup acceptance test environment
122
+ runs-on : ubuntu-latest
123
+ steps :
124
+ - uses : actions/checkout@v2
125
+ - name : Remove todo app
126
+ uses :
napptive-actions/[email protected]
127
+ continue-on-error : true
128
+ with :
129
+ cmd : " apps remove example-app-nodejs"
130
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
131
+ - name : Remove AT app
132
+ uses :
napptive-actions/[email protected]
133
+ continue-on-error : true
134
+ with :
135
+ cmd : " apps remove example-app-nodejs-at"
136
+ environment : ${{needs.prepare-acceptance-test-env.outputs.envname}}
137
+ - name : Cleanup test environment
138
+ uses :
napptive-actions/[email protected]
139
+ continue-on-error : true
140
+ with :
141
+ cmd : " env remove ${{needs.prepare-acceptance-test-env.outputs.envname}}"
142
+ create-prod-env :
143
+ needs : [launch-acceptance-tests]
144
+ name : Create the production environment
145
+ runs-on : ubuntu-latest
146
+ outputs :
147
+ envname : ${{ steps.envname.outputs.envname }}
148
+ steps :
149
+ - uses : actions/checkout@v2
150
+ - name : Set environment name
151
+ id : envname
152
+ run : echo "::set-output name=envname::${PLAYGROUND_ACCOUNT_NAME}/todo-app-prod"
153
+ - name : Create production environment
154
+ uses :
napptive-actions/[email protected]
155
+ continue-on-error : true
156
+ with :
157
+ cmd : " env create ${{steps.envname.outputs.envname }}"
158
+ check-app-deployed :
159
+ needs : [create-prod-env]
160
+ name : Check if the application is deployed
161
+ runs-on : ubuntu-latest
162
+ outputs :
163
+ not-found : ${{ steps.not-found.outputs.not-found }}
164
+ found : ${{ steps.found.outputs.found }}
165
+ steps :
166
+ - uses : actions/checkout@v2
167
+ - name : Check if the app exists
168
+ uses :
napptive-actions/[email protected]
169
+ continue-on-error : true
170
+ id : check
171
+ with :
172
+ cmd : " apps info example-app-nodejs"
173
+ environment : ${{needs.create-prod-env.outputs.envname}}
174
+ - name : Set App not found
175
+ id : not-found
176
+ run : echo '::set-output name=not-found::true'
177
+ if : steps.check.outcome != 'success'
178
+ - name : Set App found
179
+ id : found
180
+ run : echo '::set-output name=found::true'
181
+ if : steps.check.outcome != 'failure'
182
+ deploy-app :
183
+ name : Deploy application into production
184
+ needs : [create-prod-env, check-app-deployed]
185
+ runs-on : ubuntu-latest
186
+ if : ${{needs.check-app-deployed.outputs.not-found == 'true'}}
187
+ steps :
188
+ - uses : actions/checkout@v2
189
+ - name : Get Version
190
+ id : get-version
191
+ run : echo "::set-output name=version::$(cat version)"
192
+ - name : Deploy the app from the catalog
193
+ uses :
napptive-actions/[email protected]
194
+ with :
195
+ appName : napptive/example-app-nodejs:${{ steps.get-version.outputs.version }}
196
+ environment : ${{needs.create-prod-env.outputs.envname}}
197
+ update-app :
198
+ name : Update application
199
+ needs : [create-prod-env, check-app-deployed]
200
+ runs-on : ubuntu-latest
201
+ if : ${{needs.check-app-deployed.outputs.found == 'true'}}
202
+ steps :
203
+ - uses : actions/checkout@v2
204
+ - name : Make scripts executable
205
+ run : chmod +x updateImage.sh
206
+ - name : Get Version
207
+ id : version
208
+ run : echo "::set-output name=version::$(cat version)"
209
+ - name : Deploy new version of the application
210
+ run : ./updateImage.sh
211
+ env :
212
+ VERSION : ${{ steps.version.outputs.version }}
213
+ ENV_NAME : ${{needs.create-prod-env.outputs.envname}}
0 commit comments