This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 388
/
config.yml
275 lines (238 loc) · 8.63 KB
/
config.yml
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
version: 2.1
orbs:
slack: circleci/slack@3.4.2
executors:
go:
docker:
- image: circleci/golang:1.14
environment:
- TEST_RESULTS: /tmp/test-results
jobs:
unit-helm2:
docker:
# This image is built from test/docker/Test.dockerfile
# helm2 must use 0.3.0 version of the image
- image: hashicorpdev/consul-helm-test:0.3.0
steps:
- checkout
- run:
name: Run Unit Tests
command: bats ./test/unit
unit-helm3:
docker:
- image: hashicorpdev/consul-helm-test:0.6.0
steps:
- checkout
- run:
name: Run Unit Tests
command: bats ./test/unit
go-fmt-and-vet:
executor: go
steps:
- checkout
# Restore go module cache if there is one
- restore_cache:
keys:
- consul-helm-modcache-v1-{{ checksum "test/acceptance/go.mod" }}
- run:
name: go mod download
working_directory: test/acceptance
command: go mod download
# Save go module cache if the go.mod file has changed
- save_cache:
key: consul-helm-modcache-v1-{{ checksum "test/acceptance/go.mod" }}
paths:
- "/go/pkg/mod"
# check go fmt output because it does not report non-zero when there are fmt changes
- run:
name: check go fmt
command: |
files=$(go fmt ./...)
if [ -n "$files" ]; then
echo "The following file(s) do not conform to go fmt:"
echo "$files"
exit 1
fi
- run:
name: go vet
working_directory: test/acceptance
command: go vet ./...
unit-acceptance-framework:
executor: go
steps:
- checkout
# Restore go module cache if there is one
- restore_cache:
keys:
- consul-helm-modcache-v1-{{ checksum "test/acceptance/go.mod" }}
- run: mkdir -p $TEST_RESULTS
- run:
name: Run tests
working_directory: test/acceptance/framework
command: |
gotestsum --junitfile $TEST_RESULTS/gotestsum-report.xml ./... -- -p 4
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
acceptance:
environment:
- TEST_RESULTS: /tmp/test-results
docker:
# This image is build from test/docker/Test.dockerfile
- image: hashicorpdev/consul-helm-test:0.5.0
steps:
- run:
name: Exit if forked PR
command: |
if [ -n "$CIRCLE_PR_NUMBER" ]; then
echo "Skipping acceptance tests for forked PRs; marking step successful."
circleci step halt
fi
- checkout
- run:
name: terraform init & apply
working_directory: test/terraform/gke
command: |
terraform init
echo "${GOOGLE_CREDENTIALS}" | gcloud auth activate-service-account --key-file=-
terraform apply -var project=${CLOUDSDK_CORE_PROJECT} -var init_cli=true -var cluster_count=2 -auto-approve
# Restore go module cache if there is one
- restore_cache:
keys:
- consul-helm-modcache-v1-{{ checksum "test/acceptance/go.mod" }}
- run: mkdir -p $TEST_RESULTS
- run:
name: Run acceptance tests
working_directory: test/acceptance/tests
no_output_timeout: 30m
command: |
eval "$(echo export primary_kubeconfig=$(terraform output -state ../../terraform/gke/terraform.tfstate -json | jq -r .kubeconfigs.value[0]))"
eval "$(echo export secondary_kubeconfig=$(terraform output -state ../../terraform/gke/terraform.tfstate -json | jq -r .kubeconfigs.value[1]))"
gotestsum --junitfile "$TEST_RESULTS/gotestsum-report.xml" -- ./... -p 1 -timeout 20m -failfast \
-enable-enterprise \
-enable-multi-cluster \
-kubeconfig="$primary_kubeconfig" \
-secondary-kubeconfig="$secondary_kubeconfig" \
-debug-directory="$TEST_RESULTS/debug" \
-consul-k8s-image=hashicorpdev/consul-k8s:latest
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
- run:
name: terraform destroy
working_directory: test/terraform/gke
command: |
terraform destroy -var project=${CLOUDSDK_CORE_PROJECT} -auto-approve
when: always
acceptance-openshift:
environment:
- TEST_RESULTS: /tmp/test-results
- OC_PRIMARY_NAME: consul-helm-test-2757871175
- OC_SECONDARY_NAME: consul-helm-test-3737660519
docker:
# This image is build from test/docker/Test.dockerfile
- image: hashicorpdev/consul-helm-test:0.6.0
steps:
- checkout
- run:
name: openshift login
command: |
az login --service-principal -u "$ARM_CLIENT_ID" -p "$ARM_CLIENT_SECRET" --tenant "$ARM_TENANT_ID" > /dev/null
for cluster_name in "$OC_PRIMARY_NAME" "$OC_SECONDARY_NAME"; do
apiServer=$(az aro show -g "$cluster_name" -n "$cluster_name" --query apiserverProfile.url -o tsv)
kubeUser=$(az aro list-credentials -g "$cluster_name" -n "$cluster_name" | jq -r .kubeadminUsername)
kubePassword=$(az aro list-credentials -g "$cluster_name" -n "$cluster_name" | jq -r .kubeadminPassword)
KUBECONFIG="$HOME/.kube/$cluster_name" oc login "$apiServer" -u "$kubeUser" -p "$kubePassword"
KUBECONFIG="$HOME/.kube/$cluster_name" oc project consul
done
# Restore go module cache if there is one
- restore_cache:
keys:
- consul-helm-modcache-v1-{{ checksum "test/acceptance/go.mod" }}
- run: mkdir -p $TEST_RESULTS
- run:
name: Run acceptance tests
working_directory: test/acceptance/tests
no_output_timeout: 30m
command: |
gotestsum --junitfile "$TEST_RESULTS/gotestsum-report.xml" -- ./... -p 1 -timeout 30m -failfast \
-enable-openshift \
-enable-enterprise \
-enable-multi-cluster \
-kubeconfig="$HOME/.kube/$OC_PRIMARY_NAME" \
-secondary-kubeconfig="$HOME/.kube/$OC_SECONDARY_NAME" \
-debug-directory="$TEST_RESULTS/debug" \
-consul-k8s-image=hashicorpdev/consul-k8s:latest
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
update-helm-charts-index:
docker:
- image: circleci/golang:latest
steps:
- checkout
- run:
name: verify Chart version matches tag version
command: |
GO111MODULE=on go get github.com/mikefarah/yq/v2
git_tag=$(echo "${CIRCLE_TAG#v}")
chart_tag=$(yq r Chart.yaml version)
if [ "${git_tag}" != "${chart_tag}" ]; then
echo "chart version (${chart_tag}) did not match git version (${git_tag})"
exit 1
fi
- run:
name: update helm-charts index
command: |
curl --show-error --silent --fail --user "${CIRCLE_TOKEN}:" \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d "{\"branch\": \"master\",\"parameters\":{\"SOURCE_REPO\": \"${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}\",\"SOURCE_TAG\": \"${CIRCLE_TAG}\"}}" \
"${CIRCLE_ENDPOINT}/${CIRCLE_PROJECT}/pipeline"
- slack/status:
fail_only: true
failure_message: "Failed to trigger an update to the helm charts index. Check the logs at: ${CIRCLE_BUILD_URL}"
workflows:
version: 2
test:
jobs:
- go-fmt-and-vet
- unit-acceptance-framework:
requires:
- go-fmt-and-vet
- unit-helm2
- unit-helm3
# - acceptance:
# requires:
# - unit-helm2
# - unit-helm3
# - unit-acceptance-framework
- acceptance-openshift:
requires:
- unit-helm2
- unit-helm3
- unit-acceptance-framework
# todo: uncomment before merging the PR
# nightly-acceptance-tests:
# triggers:
# - schedule:
# cron: "0 0 * * *"
# filters:
# branches:
# only:
# - master
# jobs:
# - acceptance-openshift
update-helm-charts-index:
jobs:
- update-helm-charts-index:
context: helm-charts-trigger
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/