forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.yml
144 lines (127 loc) · 5.91 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
version: 2
jobs:
build:
# We need to run Docker Compose with volumes, which isn't supported by CircleCI's Docker executor, so we have to use
# the machine executor instead.
machine: true
environment:
TERRAFORM_VERSION: 0.11.8
GRUNTWORK_INSTALLER_VERSION: v0.0.21
K8S_VERSION: v1.10.0 # Same as EKS
KUBECONFIG: /home/circleci/.kube/config
MINIKUBE_VERSION: v0.28.2 # See https://github.com/kubernetes/minikube/issues/2704
MINIKUBE_WANTUPDATENOTIFICATION: "false"
MINIKUBE_WANTREPORTERRORPROMPT: "false"
MINIKUBE_HOME: /home/circleci
CHANGE_MINIKUBE_NONE_USER: "true"
steps:
- checkout
# The weird way you have to set PATH in Circle 2.0
- run: echo 'export PATH=$HOME/.local/bin:$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV
# Make GCP Service Account creds available as a file
- run: echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
- run: echo 'export GOOGLE_APPLICATION_CREDENTIALS=${HOME}/gcloud-service-key.json' >> $BASH_ENV
# Install Gruntwork and HashiCorp dependencies
- restore_cache:
keys:
- v1-external-dep
- v1-dep-{{ checksum "Gopkg.lock" }}
# Use the Gruntwork Installer to install the gruntwork-module-circleci-helpers
- run: curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version ${GRUNTWORK_INSTALLER_VERSION}
- run: gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.13.2"
- run: configure-environment-for-gruntwork-module --circle-ci-2-machine-executor --go-src-path . --use-go-dep --terraform-version ${TERRAFORM_VERSION}
# Install and setup minikube
# https://github.com/kubernetes/minikube#linux-continuous-integration-without-vm-support
- run:
name: install kubectl
command: |
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
- run:
name: install minikube
command: |
curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_VERSION}/minikube-linux-amd64
chmod +x minikube
sudo mv minikube /usr/local/bin/
- run:
name: start minikube and wait for it
command: |
# Ignore warnings on minikube start command, as it will log a warning due to using deprecated localkube
# bootstrapper. However, the localkube bootstrapper is necessary to run on CircleCI which doesn't have
# systemd.
sudo -E minikube start --vm-driver=none --kubernetes-version=${K8S_VERSION} --bootstrapper=localkube
# this for loop waits until kubectl can access the api server that Minikube has created
$(
for i in {1..150}; do # timeout for 5 minutes
kubectl get po &> /dev/null
if [ $? -ne 1 ]; then
break
fi
sleep 2
done
true
)
- save_cache:
key: v1-external-dep
paths:
- $HOME/terraform
- $HOME/packer
- save_cache:
key: v1-dep-{{ checksum "Gopkg.lock" }}
paths:
- $HOME/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/test/vendor
# Run pre-commit hooks and fail the build if any hook finds required changes.
- run: go get golang.org/x/tools/cmd/goimports
- run: pip install pre-commit==1.11.2
- run: pre-commit install
- run: pre-commit run --all-files
# Run the tests. Note that we set the "-p 1" flag to tell Go to run tests in each package sequentially. Without
# this, Go buffers all log output until all packages are done, which with slower running tests can cause CircleCI
# to kill the build after more than 10 minutes without log output.
- run: mkdir -p /tmp/logs
- run: run-go-tests --packages "-p 1 ./..." | tee /tmp/logs/test_output.log
# Build any binaries that need to be built
# We always want to build the binaries, because we will use the terratest_log_parser to parse out the test output
# during a failure.
- run:
command: GO_ENABLED=0 build-go-binaries --circle-ci-2 --app-name terratest_log_parser --src-path ../.go_workspace/src/github.com/gruntwork-io/terratest/cmd/terratest_log_parser --dest-path ./cmd/bin --ld-flags "-X main.VERSION=$CIRCLE_TAG -extldflags '-static'"
when: always
- persist_to_workspace:
root: .
paths: cmd/bin
- run:
command: ./cmd/bin/terratest_log_parser_linux_amd64 --testlog /tmp/logs/test_output.log --outputdir /tmp/logs
when: always
# Store test result and log artifacts for browsing purposes
- store_artifacts:
path: /tmp/logs
- store_test_results:
path: /tmp/logs
deploy:
machine: true
steps:
- checkout
- attach_workspace:
at: .
- run: curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version v0.0.21
- run: gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "v0.13.2"
- run: upload-github-release-assets cmd/bin/*
workflows:
version: 2
build-and-test:
jobs:
- build:
filters:
tags:
only: /^v.*/
- deploy:
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/