|
| 1 | +defaults: &defaults |
| 2 | + machine: true |
| 3 | + environment: |
| 4 | + GRUNTWORK_INSTALLER_VERSION: v0.0.21 |
| 5 | + TERRATEST_LOG_PARSER_VERSION: v0.13.13 |
| 6 | + KUBERGRUNT_VERSION: v0.1.4 |
| 7 | + MODULE_CI_VERSION: v0.13.3 |
| 8 | + TERRAFORM_VERSION: 0.11.8 |
| 9 | + TERRAGRUNT_VERSION: NONE |
| 10 | + PACKER_VERSION: NONE |
| 11 | + GOLANG_VERSION: 1.11.2 |
| 12 | + K8S_VERSION: v1.10.0 # Same as EKS |
| 13 | + KUBECONFIG: /home/circleci/.kube/config |
| 14 | + MINIKUBE_VERSION: v0.28.2 # See https://github.com/kubernetes/minikube/issues/2704 |
| 15 | + MINIKUBE_WANTUPDATENOTIFICATION: "false" |
| 16 | + MINIKUBE_WANTREPORTERRORPROMPT: "false" |
| 17 | + MINIKUBE_HOME: /home/circleci |
| 18 | + CHANGE_MINIKUBE_NONE_USER: "true" |
| 19 | + |
| 20 | +# Install and setup minikube |
| 21 | +# https://github.com/kubernetes/minikube#linux-continuous-integration-without-vm-support |
| 22 | +setup_minikube: &setup_minikube |
| 23 | + name: install kubectl and minikube |
| 24 | + command: | |
| 25 | + # install kubectl |
| 26 | + curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl |
| 27 | + chmod +x kubectl |
| 28 | + sudo mv kubectl /usr/local/bin/ |
| 29 | + mkdir -p ${HOME}/.kube |
| 30 | + touch ${HOME}/.kube/config |
| 31 | +
|
| 32 | + # Install minikube |
| 33 | + curl -Lo minikube https://github.com/kubernetes/minikube/releases/download/${MINIKUBE_VERSION}/minikube-linux-amd64 |
| 34 | + chmod +x minikube |
| 35 | + sudo mv minikube /usr/local/bin/ |
| 36 | +
|
| 37 | + # start minikube and wait for it |
| 38 | + # Ignore warnings on minikube start command, as it will log a warning due to using deprecated localkube |
| 39 | + # bootstrapper. However, the localkube bootstrapper is necessary to run on CircleCI which doesn't have |
| 40 | + # systemd. |
| 41 | + sudo -E minikube start --vm-driver=none --kubernetes-version=${K8S_VERSION} --bootstrapper=localkube |
| 42 | + # this for loop waits until kubectl can access the api server that Minikube has created |
| 43 | + $( |
| 44 | + for i in {1..150}; do # timeout for 5 minutes |
| 45 | + kubectl get po &> /dev/null |
| 46 | + if [ $? -ne 1 ]; then |
| 47 | + break |
| 48 | + fi |
| 49 | + sleep 2 |
| 50 | + done |
| 51 | + true |
| 52 | + ) |
| 53 | +
|
| 54 | +install_gruntwork_utils: &install_gruntwork_utils |
| 55 | + name: install gruntwork utils |
| 56 | + command: | |
| 57 | + curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" |
| 58 | + gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/module-ci" --tag "${MODULE_CI_VERSION}" |
| 59 | + gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}" |
| 60 | + configure-environment-for-gruntwork-module \ |
| 61 | + --circle-ci-2-machine-executor \ |
| 62 | + --terraform-version ${TERRAFORM_VERSION} \ |
| 63 | + --terragrunt-version ${TERRAGRUNT_VERSION} \ |
| 64 | + --packer-version ${PACKER_VERSION} \ |
| 65 | + --use-go-dep \ |
| 66 | + --go-version ${GOLANG_VERSION} \ |
| 67 | + --go-src-path test \ |
| 68 | +
|
| 69 | +
|
| 70 | +version: 2 |
| 71 | +jobs: |
| 72 | + setup: |
| 73 | + <<: *defaults |
| 74 | + steps: |
| 75 | + - checkout |
| 76 | + - restore_cache: |
| 77 | + keys: |
| 78 | + - dep-{{ checksum "test/Gopkg.lock" }} |
| 79 | + |
| 80 | + # Install gruntwork utilities |
| 81 | + - run: |
| 82 | + <<: *install_gruntwork_utils |
| 83 | + |
| 84 | + - save_cache: |
| 85 | + key: dep-{{ checksum "test/Gopkg.lock" }} |
| 86 | + paths: |
| 87 | + - ./test/vendor |
| 88 | + |
| 89 | + # Fail the build if the pre-commit hooks don't pass. Note: if you run pre-commit install locally, these hooks will |
| 90 | + # execute automatically every time before you commit, ensuring the build never fails at this step! |
| 91 | + - run: pip install pre-commit==1.11.2 |
| 92 | + - run: pre-commit install |
| 93 | + - run: pre-commit run --all-files |
| 94 | + |
| 95 | + - persist_to_workspace: |
| 96 | + root: /home/circleci |
| 97 | + paths: |
| 98 | + - project |
| 99 | + - terraform |
| 100 | + - packer |
| 101 | + |
| 102 | + integration_tests: |
| 103 | + <<: *defaults |
| 104 | + steps: |
| 105 | + - attach_workspace: |
| 106 | + at: /home/circleci |
| 107 | + |
| 108 | + # The weird way you have to set PATH in Circle 2.0 |
| 109 | + - run: echo 'export PATH=$HOME/terraform:$HOME/packer:$PATH' >> $BASH_ENV |
| 110 | + |
| 111 | + - run: |
| 112 | + <<: *install_gruntwork_utils |
| 113 | + |
| 114 | + - run: |
| 115 | + <<: *setup_minikube |
| 116 | + |
| 117 | + - run: |
| 118 | + name: Install kubergrunt |
| 119 | + command: gruntwork-install --binary-name "kubergrunt" --repo "https://github.com/gruntwork-io/kubergrunt" --tag "${KUBERGRUNT_VERSION}" |
| 120 | + |
| 121 | + # Execute main terratests |
| 122 | + - run: |
| 123 | + name: run integration tests |
| 124 | + command: | |
| 125 | + mkdir -p /tmp/logs |
| 126 | + run-go-tests --path test --timeout 60m | tee /tmp/logs/all.log |
| 127 | + no_output_timeout: 3600s |
| 128 | + |
| 129 | + - run: |
| 130 | + command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs |
| 131 | + when: always |
| 132 | + - store_artifacts: |
| 133 | + path: /tmp/logs |
| 134 | + - store_test_results: |
| 135 | + path: /tmp/logs |
| 136 | + |
| 137 | +workflows: |
| 138 | + version: 2 |
| 139 | + test-and-deploy: |
| 140 | + jobs: |
| 141 | + - setup: |
| 142 | + filters: |
| 143 | + tags: |
| 144 | + only: /^v.*/ |
| 145 | + |
| 146 | + - integration_tests: |
| 147 | + requires: |
| 148 | + - setup |
| 149 | + filters: |
| 150 | + tags: |
| 151 | + only: /^v.*/ |
0 commit comments