From 8620d0ae4fd394c1906e8620fd9335fcf7d0c2d6 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 8 Oct 2017 13:07:33 +0000 Subject: [PATCH] Change CircleCI config to 2.0 version Environment variables are moved out to a script, because CircleCI 2.0 does not support expansion of '$foo' in 'env' section. --- .circleci/config.yml | 117 +++++++++++++++++--------------------- bin/circle-destroy-vms | 7 +++ bin/circle-env | 12 ++++ bin/circle-test-pre | 2 + bin/circle-test-smoke | 2 + bin/provision_test_vms.sh | 3 +- 6 files changed, 76 insertions(+), 67 deletions(-) create mode 100755 bin/circle-destroy-vms create mode 100644 bin/circle-env diff --git a/.circleci/config.yml b/.circleci/config.yml index e1cd0983..2e687623 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,66 +1,51 @@ -general: - branches: - ignore: - - gh\-pages - -machine: - pre: - - curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 - services: - - docker - environment: - GOPATH: /home/ubuntu:$GOPATH - SRCDIR: /home/ubuntu/src/github.com/weaveworks/weave - PATH: $PATH:$HOME/.local/bin:/opt/google-cloud-sdk/bin - CLOUDSDK_CORE_DISABLE_PROMPTS: 1 - STATE: /home/ubuntu/state.env - # Base name of VMs for integration tests: - NAME: test-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX - TEST_VMS_SETUP_OUTPUT_FILE: $CIRCLE_ARTIFACTS/test_vms_setup_output.txt - TEST_VMS_PROV_AND_CONF_LOCK_FILE: $CIRCLE_ARTIFACTS/test_vms_provisioned_and_configured.txt - TEST_VMS_READY_LOCK_FILE: $CIRCLE_ARTIFACTS/test_vms_ready.txt - # Google Cloud Platorm images for integration tests: - USE_IMAGE: 1 - DISK_NAME_PREFIX: test-$CIRCLE_BUILD_NUM-0 - -dependencies: - cache_directories: - - "~/docker" - post: - - bin/circle-dependencies-post-sources - # Provision & configure testing VMs: - - "while [ ! -d $SRCDIR ]; do sleep 1; done; $SRCDIR/bin/provision_test_vms.sh": - parallel: true - background: true - - bin/circle-dependencies-post - -test: - pre: - - "$SRCDIR/bin/circle-test-pre": - parallel: true - background: true - override: - - "$SRCDIR/bin/circle-test-unit": - parallel: true - - "$SRCDIR/bin/circle-test-smoke": - parallel: true - timeout: 360 - post: - - "$SRCDIR/bin/circle-test-teardown": - parallel: true - -teardown: - pre: - # Destroy testing VMs: - - "cd $SRCDIR/test && ./run-integration-tests.sh destroy": - parallel: true - background: true - - "$SRCDIR/bin/circle-teardown-pre": - parallel: true - -deployment: - master: - branch: master - owner: weaveworks - commands: - - "$SRCDIR/bin/circle-deploy-master" +version: 2 +jobs: + build: + machine: + image: circleci/classic:201709-01 + environment: + GOPATH: /home/circleci + SRCDIR: /home/circleci/src/github.com/weaveworks/weave + CIRCLE_ARTIFACTS: /tmp/artifacts + parallelism: 2 + steps: + - checkout + - run: mkdir $CIRCLE_ARTIFACTS + # copy source dir and submodule update --init + - run: bin/circle-dependencies-post-sources + - restore_cache: + key: v1-cache-{{ checksum "build/Dockerfile" }}-{{ checksum "build/build.sh" }} + # kick off creation of test VMs + - run: + command: bin/provision_test_vms.sh + background: true + # create build image and make all + - run: bin/circle-dependencies-post + - save_cache: + key: v1-cache-{{ checksum "build/Dockerfile" }}-{{ checksum "build/build.sh" }} + paths: + - "~/docker" + # when VMs are ready, copy built software to them + - run: + command: bin/circle-test-pre + background: true + - run: bin/circle-test-unit + - run: + command: bin/circle-test-smoke + no_output_timeout: 360s + # Generate code coverage reports + - run: bin/circle-test-teardown + # Destroy testing VMs: + - run: + command: bin/circle-destroy-vms + background: true + # run goveralls; copy coverage reports to artifacts dir + - deploy: + command: $SRCDIR/bin/circle-teardown-pre + - store_artifacts: + path: /tmp/artifacts + - deploy: + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + bin/circle-deploy-master + fi diff --git a/bin/circle-destroy-vms b/bin/circle-destroy-vms new file mode 100755 index 00000000..853d3c38 --- /dev/null +++ b/bin/circle-destroy-vms @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +source "$SRCDIR/bin/circle-env" +cd "$SRCDIR/test" +./run-integration-tests.sh destroy diff --git a/bin/circle-env b/bin/circle-env new file mode 100644 index 00000000..d7b95b5e --- /dev/null +++ b/bin/circle-env @@ -0,0 +1,12 @@ +# Set environment variables here because CircleCI can't expand $FOO in 'env' section + +export PATH="$PATH:$HOME/.local/bin:/opt/google-cloud-sdk/bin" +export CLOUDSDK_CORE_DISABLE_PROMPTS=1 +# Base name of VMs for integration tests: +export NAME=test-$CIRCLE_BUILD_NUM-$CIRCLE_NODE_INDEX +export TEST_VMS_SETUP_OUTPUT_FILE=$CIRCLE_ARTIFACTS/test_vms_setup_output.txt +export TEST_VMS_PROV_AND_CONF_LOCK_FILE=$CIRCLE_ARTIFACTS/test_vms_provisioned_and_configured.txt +export TEST_VMS_READY_LOCK_FILE=$CIRCLE_ARTIFACTS/test_vms_ready.txt +# Google Cloud Platorm images for integration tests: +export USE_IMAGE=1 +export DISK_NAME_PREFIX=test-$CIRCLE_BUILD_NUM-0 diff --git a/bin/circle-test-pre b/bin/circle-test-pre index 1fa0dc49..e3ae7649 100755 --- a/bin/circle-test-pre +++ b/bin/circle-test-pre @@ -16,6 +16,8 @@ source "$(dirname "$0")/wait_for.sh" exit 1 } +source "$SRCDIR/bin/circle-env" + # Provisioning from image typically take 90 seconds, # but if we are creating a GCP image, it can take more than 10 minutes: wait_for 900 "$TEST_VMS_PROV_AND_CONF_LOCK_FILE" diff --git a/bin/circle-test-smoke b/bin/circle-test-smoke index 8f2cf5f3..d14cce51 100755 --- a/bin/circle-test-smoke +++ b/bin/circle-test-smoke @@ -9,6 +9,8 @@ source "$(dirname "$0")/wait_for.sh" exit 1 } +source "$SRCDIR/bin/circle-env" + # Provisioning from image typically take 90 seconds, # but if we are creating a GCP image, it can take more than 10 minutes: wait_for 900 "$TEST_VMS_READY_LOCK_FILE" diff --git a/bin/provision_test_vms.sh b/bin/provision_test_vms.sh index 70978f14..2c0c3755 100755 --- a/bin/provision_test_vms.sh +++ b/bin/provision_test_vms.sh @@ -18,7 +18,6 @@ function install_ansible() { sudo apt-get install -qq -y python-pip python-dev libffi-dev libssl-dev \ && pip install --user -U setuptools cffi \ && pip install --user ansible - export PATH="$PATH:$HOME/.local/bin" } [ -n "$SECRET_KEY" ] || { @@ -26,6 +25,8 @@ function install_ansible() { exit 1 } +source "$SRCDIR/bin/circle-env" + install_terraform >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1 install_ansible >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1