-
Notifications
You must be signed in to change notification settings - Fork 2
216 lines (214 loc) · 8.35 KB
/
workflow-node.yaml
File metadata and controls
216 lines (214 loc) · 8.35 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
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
214
215
216
name: Node Workflow
# Standard workflow for any NodeJS based projects.
on:
workflow_call:
inputs:
mainline_branch:
default: "master"
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to the master branch."
type: string
repo_url:
default: "harbor.devops.k8s.rcsb.org"
description: "The URL of the remote Docker image repository."
type: string
repo_project:
required: true
description: "The name of the project or organization in the remote Docker image repository."
type: string
docker_image_name:
required: true
description: "The name of the Docker image to create."
type: string
do_staging_build:
default: "false"
description: "Build, tag, and push a docker image with the staging tag on commits to the mainline branch."
type: string
restart_staging_deployment:
default: "false"
description: "Restart the staging K8s deployments for this application on commits to the mainline branch."
type: string
staging_k8s_deployment_name:
required: false
description: "The name of the deployment in the K8s staging namespace to restart. Needed if restart_staging_deployment is true."
type: string
do_production_build:
default: "true"
description: "Build, tag, and push a docker image with the production tag on commits to the mainline branch."
type: string
restart_production_deployment:
default: "false"
description: "Restart the production K8s deployment for this application on commits to the mainline branch."
type: string
production_k8s_deployment_name:
required: false
description: "The names of the deployment in the K8s production namespace to restart. Needed if restart_production_deployment is true."
type: string
production_k8s_namespace_name:
default: "production"
description: "The namespace of the production deployment in K8s for restarts. Needed if restart_production_deployment is true."
type: string
node_version:
default: "16"
description: "The nodejs version of the runner to use. Defaults to 16."
type: string
workflow_dispatch:
inputs:
mainline_branch:
default: "master"
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to the master branch."
repo_url:
default: "harbor.devops.k8s.rcsb.org"
description: "The URL of the remote Docker image repository."
repo_project:
required: true
description: "The name of the project or organization in the remote Docker image repository."
docker_image_name:
required: true
description: "The name of the Docker image to create."
do_staging_build:
default: "false"
description: "Build, tag, and push a docker image with the staging tag on commits to the mainline branch."
do_production_build:
default: "true"
description: "Build, tag, and push a docker image with the production tag on commits to the mainline branch."
production_k8s_namespace_name:
default: "production"
description: "The namespace of the production deployment in K8s for restarts. Needed if restart_production_deployment is true."
type: string
node_version:
default: "16"
description: "The nodejs version of the runner to use. Defaults to 16."
jobs:
# Build jobs
debug:
name: "Debug conditionals"
runs-on:
- "self-hosted"
- "node-${{ inputs.node_version }}"
steps:
- name: "Output inputs and refs"
run: |
echo "=== Check branch conditionals"
echo "github.ref_name: ${{ github.ref_name }}"
echo "inputs.mainline_branch: ${{ inputs.mainline_branch }}"
echo "Is github.ref_name == inputs.mainline_branch: ${{ github.ref_name == inputs.mainline_branch }}"
echo "=== Check event conditionals"
echo "github.event_name: ${{ github.event_name }}"
echo "Is github.event_name != 'pull_request': ${{ github.event_name != 'pull_request' }}"
echo "=== Check environment conditionals"
echo "inputs.do_staging_build: ${{ inputs.do_staging_build }}"
echo "inputs.restart_staging_deployment: ${{ inputs.restart_staging_deployment }}"
echo "inputs.staging_k8s_deployment_name: ${{ inputs.staging_k8s_deployment_name }}"
echo "inputs.do_production_build: ${{ inputs.do_production_build }}"
echo "inputs.restart_production_deployment: ${{ inputs.restart_production_deployment }}"
echo "inputs.production_k8s_deployment_name: ${{ inputs.production_k8s_deployment_name }}"
echo "inputs.production_k8s_namespace_name: ${{ inputs.production_k8s_namespace_name }}"
build_npm:
name: "Build via NPM"
uses: ./.github/workflows/run_npm.yaml
with:
script: "build"
node_version: ${{ inputs.node_version }}
lint_npm:
name: "Lint via NPM"
uses: ./.github/workflows/run_npm.yaml
with:
script: "lint"
node_version: ${{ inputs.node_version }}
lint_docker:
name: "Lint Dockerfile"
uses: ./.github/workflows/lint_docker.yaml
# Test jobs
test_npm:
name: "Run unit tests via NPM"
needs:
- build_npm
- lint_npm
- lint_docker
uses: ./.github/workflows/run_npm.yaml
with:
script: "test"
node_version: ${{ inputs.node_version }}
build_docker:
name: "Build docker image"
needs:
- build_npm
- lint_npm
- lint_docker
uses: ./.github/workflows/build_docker.yaml
with:
repo_url: "${{ inputs.repo_url }}"
repo_project: "${{ inputs.repo_project }}"
docker_image_name: "${{ inputs.docker_image_name }}"
# Staging jobs
build_docker_staging:
name: "Push docker image with staging tag"
if: |
inputs.do_staging_build == 'true' &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request'
needs:
- test_npm
- build_docker
uses: ./.github/workflows/retag_docker.yaml
with:
repo_url: "${{ inputs.repo_url }}"
repo_project: "${{ inputs.repo_project }}"
docker_image_name: "${{ inputs.docker_image_name }}"
old_tag: "${{ github.ref_name }}"
new_tag: "staging"
restart_staging_k8s_deployment:
name: "Restart deployment in K8s staging namespace"
if: |
inputs.restart_staging_deployment == 'true' &&
inputs.staging_k8s_deployment_name &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request'
needs:
- build_docker_staging
uses: ./.github/workflows/restart_k8s_deployment.yaml
strategy:
fail-fast: false
matrix:
region: [west, east]
with:
deployment_name: "${{ inputs.staging_k8s_deployment_name }}"
namespace: "staging"
region: "${{ matrix.region }}"
# Production jobs
build_docker_production:
name: "Push docker image with production tag"
if: |
inputs.do_production_build == 'true' &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request'
needs:
- test_npm
- build_docker
uses: ./.github/workflows/retag_docker.yaml
with:
repo_url: "${{ inputs.repo_url }}"
repo_project: "${{ inputs.repo_project }}"
docker_image_name: "${{ inputs.docker_image_name }}"
old_tag: "${{ github.ref_name }}"
new_tag: "production"
restart_production_k8s_deployment:
name: "Restart deployment in K8s production namespace"
if: |
inputs.restart_production_deployment == 'true' &&
inputs.production_k8s_deployment_name &&
inputs.production_k8s_namespace_name &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request' &&
always()
needs:
- build_docker_production
uses: ./.github/workflows/restart_k8s_deployment.yaml
strategy:
fail-fast: false
matrix:
region: [ west, east ]
with:
deployment_name: "${{ inputs.production_k8s_deployment_name }}"
namespace: "${{ inputs.production_k8s_namespace_name }}"
region: "${{ matrix.region }}"