Skip to content

Commit 2b3aef2

Browse files
authored
Run CI tests in docker instead of a machine. (hashicorp#8948)
1 parent 75b2f42 commit 2b3aef2

File tree

149 files changed

+3431
-2428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+3431
-2428
lines changed

.circleci/config.yml

Lines changed: 508 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config/@config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ version: 2.1
33

44
orbs:
55
slack: circleci/slack@3.2.0
6-

.circleci/config/commands/go_test.yml

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ parameters:
1212
save_cache:
1313
type: boolean
1414
default: false
15+
go_image:
16+
type: string
17+
default: "circleci/golang:1.14.7-stretch"
18+
use_docker:
19+
type: boolean
20+
default: false
1521
steps:
1622
- run:
1723
name: Compute test cache key
@@ -27,7 +33,7 @@ steps:
2733
set -x
2834
2935
case "<< parameters.extra_flags >>" in
30-
*-race*) VAULT_CI_GO_TEST_RACE=1;;
36+
*-race*) export VAULT_CI_GO_TEST_RACE=1;;
3137
esac
3238
3339
# Install CircleCI CLI
@@ -37,39 +43,90 @@ steps:
3743
-C /usr/local/bin \
3844
"circleci-cli_${CIRCLECI_CLI_VERSION}_linux_amd64/circleci"
3945
40-
# Split Go tests by prior test times
41-
package_names=$(go list \
42-
-tags "${GO_TAGS}" \
43-
./... \
44-
| grep -v /integ \
45-
| grep -v /vendor/ \
46-
| sort \
47-
| circleci tests split --split-by=timings --timings-type=classname)
46+
USE_DOCKER=0
47+
<<# parameters.use_docker >>
48+
USE_DOCKER=1
49+
<</ parameters.use_docker >>
4850
49-
# Install gotestsum
50-
curl -sSL "https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz" \
51-
| sudo tar --overwrite -xz -C /usr/local/bin gotestsum
51+
# Split Go tests by prior test times. If use_docker is true, only run
52+
# tests that depend on docker, otherwise only those that don't.
53+
if [ $USE_DOCKER == 1 ]; then
54+
package_names=$(go list -test -json ./... |
55+
jq -r 'select(.Deps != null) |
56+
select(any(.Deps[] ; contains("github.com/hashicorp/vault/helper/testhelpers/docker"))) |
57+
.ForTest | select(. != null)' |
58+
sort -u | circleci tests split --split-by=timings --timings-type=classname)
59+
else
60+
package_names=$(go list -test -json ./... |
61+
jq -r 'select(.Deps != null) |
62+
select(all(.Deps[] ; contains("github.com/hashicorp/vault/helper/testhelpers/docker")|not)) |
63+
.ForTest | select(. != null)' |
64+
sort -u | circleci tests split --split-by=timings --timings-type=classname)
65+
fi
66+
67+
# After running tests split step, we are now running the following steps
68+
# in multiple different containers, each getting a different subset of
69+
# the test packages in their package_names variable. Each container
70+
# has its own remote docker VM.
5271
53-
# Run tests
5472
make prep
5573
mkdir -p test-results/go-test
56-
CGO_ENABLED= \
57-
VAULT_ADDR= \
58-
VAULT_TOKEN= \
59-
VAULT_DEV_ROOT_TOKEN_ID= \
60-
VAULT_ACC= \
74+
75+
# Create a docker network for our testcontainer
76+
if [ $USE_DOCKER == 1 ]; then
77+
export TEST_DOCKER_NETWORK_ID=$(docker network list -q -f 'name=vaulttest')
78+
if [ -z $TEST_DOCKER_NETWORK_ID ]; then
79+
TEST_DOCKER_NETWORK_ID=$(docker network create vaulttest)
80+
fi
81+
82+
# Start a docker testcontainer to run the tests in
83+
docker run -d -e TEST_DOCKER_NETWORK_ID \
84+
-e DOCKER_CERT_PATH -e DOCKER_HOST -e DOCKER_MACHINE_NAME -e DOCKER_TLS_VERIFY -e NO_PROXY \
85+
-e VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
86+
--network vaulttest --name \
87+
testcontainer << parameters.go_image >> \
88+
tail -f /dev/null
89+
90+
# Run tests
91+
docker cp << parameters.cache_dir >> testcontainer:/tmp/gocache
92+
docker exec testcontainer sh -c 'mkdir -p /go/src/github.com/hashicorp/vault'
93+
docker cp . testcontainer:/go/src/github.com/hashicorp/vault/
94+
docker cp $DOCKER_CERT_PATH/ testcontainer:$DOCKER_CERT_PATH
95+
96+
docker exec -w /go/src/github.com/hashicorp/vault/ \
97+
-e GO111MODULE -e CIRCLECI -e GOCACHE=/tmp/gocache -e VAULT_CI_GO_TEST_RACE \
98+
testcontainer \
99+
gotestsum --format=short-verbose \
100+
--junitfile test-results/go-test/results.xml \
101+
--jsonfile test-results/go-test/results.json \
102+
-- \
103+
-tags "${GO_TAGS}" \
104+
-timeout=15m \
105+
-parallel=20 \
106+
<< parameters.extra_flags >> \
107+
${package_names}
108+
else
61109
GOCACHE=<< parameters.cache_dir >> \
62-
VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
63-
gotestsum --format=short-verbose \
64-
--junitfile test-results/go-test/results.xml \
65-
--jsonfile test-results/go-test/results.json \
66-
-- \
67-
-tags "${GO_TAGS}" \
68-
-timeout=60m \
69-
-parallel=20 \
70-
<< parameters.extra_flags >> \
71-
${package_names}
110+
gotestsum --format=short-verbose \
111+
--junitfile test-results/go-test/results.xml \
112+
--jsonfile test-results/go-test/results.json \
113+
-- \
114+
-tags "${GO_TAGS}" \
115+
-timeout=60m \
116+
-parallel=20 \
117+
<< parameters.extra_flags >> \
118+
${package_names}
119+
fi
72120
121+
- when:
122+
condition: << parameters.use_docker >>
123+
steps:
124+
- run:
125+
name: Copy test results
126+
when: always
127+
command: |
128+
docker cp testcontainer:/go/src/github.com/hashicorp/vault/test-results .
129+
docker cp testcontainer:/tmp/gocache << parameters.cache_dir >>
73130
- when:
74131
condition: << parameters.save_cache >>
75132
steps:

.circleci/config/executors/@executors.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,21 @@ alpine:
2323
- image: alpine:3.10.2
2424
shell: /bin/sh
2525
working_directory: /go/src/github.com/hashicorp/vault
26+
docker-env-large:
27+
resource_class: large
28+
docker:
29+
- image: "circleci/golang:1.14.7-stretch"
30+
environment:
31+
GO111MODULE: "off"
32+
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
33+
GO_TAGS: ""
34+
working_directory: /go/src/github.com/hashicorp/vault
35+
docker-env-xlarge:
36+
resource_class: xlarge
37+
docker:
38+
- image: "circleci/golang:1.14.7-stretch"
39+
environment:
40+
GO111MODULE: "off"
41+
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
42+
GO_TAGS: ""
43+
working_directory: /go/src/github.com/hashicorp/vault
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
executor: docker-env-xlarge
2+
parallelism: 8
3+
steps:
4+
- check-branch-name
5+
- checkout
6+
- setup_remote_docker:
7+
version: 18.09.3
8+
docker_layer_caching: true
9+
- go_test:
10+
extra_flags: "-race"
11+
log_dir: "/tmp/testlogs"
12+
use_docker: true
13+
- store_artifacts:
14+
path: test-results
15+
- store_test_results:
16+
path: test-results
17+
- store_artifacts:
18+
path: "/tmp/testlogs"

.circleci/config/jobs/test-go-race.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
executor: go-machine
1+
executor: docker-env-xlarge
2+
parallelism: 8
23
steps:
3-
- setup-go
4+
- check-branch-name
45
- checkout
56
- go_test:
67
extra_flags: "-race"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
executor: docker-env-large
2+
parallelism: 8
3+
steps:
4+
- check-branch-name
5+
- checkout
6+
- setup_remote_docker:
7+
version: 18.09.3
8+
docker_layer_caching: true
9+
- go_test:
10+
log_dir: "/tmp/testlogs"
11+
use_docker: true
12+
- store_artifacts:
13+
path: test-results
14+
- store_test_results:
15+
path: test-results
16+
- store_artifacts:
17+
path: "/tmp/testlogs"

.circleci/config/jobs/test-go.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
executor: go-machine
2-
parallelism: 2
1+
executor: docker-env-large
2+
parallelism: 8
33
steps:
44
- check-branch-name
5-
- setup-go
65
- checkout
76
- go_test:
87
log_dir: "/tmp/testlogs"

.circleci/config/workflows/ci.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,34 @@ jobs:
2020
ignore: /pull\/[0-9]+/
2121
- test-go:
2222
requires:
23-
- build-go-dev
23+
- pre-flight-checks
24+
filters:
25+
branches:
26+
# UI and Docs-only branches should skip go tests
27+
ignore:
28+
- /^docs\/.*/
29+
- /^ui\/.*/
30+
- test-go-remote-docker:
31+
requires:
32+
- pre-flight-checks
33+
filters:
34+
branches:
35+
# UI and Docs-only branches should skip go tests
36+
ignore:
37+
- /^docs\/.*/
38+
- /^ui\/.*/
2439
- test-go-race:
2540
requires:
26-
- build-go-dev
41+
- pre-flight-checks
42+
filters:
43+
branches:
44+
# UI and Docs-only branches should skip go tests
45+
ignore:
46+
- /^docs\/.*/
47+
- /^ui\/.*/
48+
- test-go-race-remote-docker:
49+
requires:
50+
- pre-flight-checks
2751
filters:
2852
branches:
2953
# UI and Docs-only branches should skip go tests

builtin/credential/aws/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
)
1919

2020
const amzHeaderPrefix = "X-Amz-"
21+
2122
var defaultAllowedSTSRequestHeaders = []string{
2223
"X-Amz-Date",
2324
"X-Amz-Credential",

0 commit comments

Comments
 (0)