Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3270 from weaveworks/circle20
Browse files Browse the repository at this point in the history
Convert CI build to CircleCI 2.0

Fix #3255
  • Loading branch information
brb authored Aug 2, 2018
2 parents e669ac6 + e64656d commit dcaf77a
Show file tree
Hide file tree
Showing 19 changed files with 195 additions and 218 deletions.
115 changes: 115 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
version: 2
defaults: &defaults
docker:
- image: weaveworks/weavebuild:circle20-2e6504d3
working_directory: /go/src/github.com/weaveworks/weave

jobs:
lint:
<<: *defaults
steps:
- checkout
- run: git submodule update --init
- run: make DEBUG=1 BUILD_IN_CONTAINER=false lint

unit-test:
<<: *defaults
parallelism: 2
steps:
- checkout
- run: COVERDIR=test/coverage make BUILD_IN_CONTAINER=false tests
- persist_to_workspace:
root: .
paths:
- test/coverage

build:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- run: git submodule update --init
- run: make COVERAGE=true BUILD_IN_CONTAINER=false SUDO= exes all
- persist_to_workspace:
root: .
paths:
- weave.tar.gz
- tools/runner/runner
- test/tls/tls

smoke-tests:
machine:
image: circleci/classic:201709-01
working_directory: /home/circleci/src/github.com/weaveworks/weave
environment:
SRCDIR: /home/circleci/src/github.com/weaveworks/weave
CIRCLE_ARTIFACTS: /tmp/artifacts
parallelism: 2
steps:
- checkout
- run: mkdir $CIRCLE_ARTIFACTS
- run: git submodule update --init
- attach_workspace:
at: .
# kick off creation of test VMs
- run: bin/provision_test_vms.sh
# when VMs are ready, copy built software to them
- run: bin/circle-test-pre
- run:
command: bin/circle-test-smoke
no_output_timeout: 360s
# Destroy testing VMs:
- run:
command: bin/circle-destroy-vms
background: true
- persist_to_workspace:
root: .
paths:
- test/coverage
- store_artifacts:
path: /tmp/artifacts

gen-coverage:
<<: *defaults
environment:
CIRCLE_ARTIFACTS: /tmp/artifacts
steps:
- checkout
- run: mkdir $CIRCLE_ARTIFACTS
- attach_workspace:
at: .
- run: cd test; ./gen_coverage_reports.sh
- run: goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=test/profile.cov -service=circleci
- run: cp test/coverage.* $CIRCLE_ARTIFACTS
- store_artifacts:
path: /tmp/artifacts

deploy:
<<: *defaults
steps:
- setup_remote_docker
# Rebuild without coverage and push to dockerhub
- deploy: bin/circle-deploy-master

workflows:
version: 2
build_test:
jobs:
- lint
- unit-test
- build
- smoke-tests:
requires:
- lint
- unit-test
- build
- gen-coverage:
requires:
- unit-test
- smoke-tests
- deploy:
requires:
- smoke-tests
filters:
branches:
only: master
1 change: 0 additions & 1 deletion .lintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# avoid breaking the build on make lint:
bin/circle-deploy-issues
bin/circle-deploy-master
bin/circle-teardown-pre
bin/circle-test-teardown
bin/circle-test-unit
bin/install-wordepress
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ endif
# It also makes sure the multiarch hooks are reqistered in the kernel so the QEMU emulation works
$(BUILD_UPTODATE): build/*
$(SUDO) docker build -t $(BUILD_IMAGE) build/
$(SUDO) docker tag $(BUILD_IMAGE) $(BUILD_IMAGE):$(shell tools/image-tag)
$(SUDO) docker run --rm --privileged multiarch/qemu-user-static:register --reset
touch $@

Expand Down
17 changes: 0 additions & 17 deletions bin/circle-dependencies-post

This file was deleted.

36 changes: 0 additions & 36 deletions bin/circle-dependencies-post-sources

This file was deleted.

14 changes: 5 additions & 9 deletions bin/circle-deploy-master
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

set -e

source "$STATE"

if [ -n "$TEST_AND_PUBLISH" ] ; then
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
cd $SRCDIR
make clean-bin
# CircleCI doesn't let us install the qemu module to do ARM docker builds
make publish ALL_ARCHITECTURES=amd64 UPDATE_LATEST=latest-only
fi
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
cd $SRCDIR
make clean-bin
# CircleCI doesn't let us install the qemu module to do ARM docker builds
make publish ALL_ARCHITECTURES=amd64 UPDATE_LATEST=latest-only SUDO= BUILD_IN_CONTAINER=false
7 changes: 7 additions & 0 deletions bin/circle-destroy-vms
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

source "$SRCDIR/bin/circle-env"
cd "$SRCDIR/test"
./run-integration-tests.sh destroy
11 changes: 11 additions & 0 deletions bin/circle-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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_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
13 changes: 0 additions & 13 deletions bin/circle-teardown-pre

This file was deleted.

29 changes: 14 additions & 15 deletions bin/circle-test-pre
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ function signal_failure() {
}
trap signal_failure ERR

source "$STATE"
source "$(dirname "$0")/wait_for.sh"

if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
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"
# 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"

# Upload built binaries to testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh setup >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
echo "OK" >"$TEST_VMS_READY_LOCK_FILE"
echo "Test VMs now ready. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
fi
# Upload built binaries to testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh setup
echo "OK" >"$TEST_VMS_READY_LOCK_FILE"
echo "Test VMs now ready. $(date)."
29 changes: 14 additions & 15 deletions bin/circle-test-smoke
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

set -e

source "$STATE"
source "$(dirname "$0")/wait_for.sh"

if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}

# 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"
source "$SRCDIR/bin/circle-env"

# Run integration tests:
export COVERAGE=true
export WEAVE_NET_SANITY_CHECKS_FILES="$CIRCLE_ARTIFACTS/weave_net_sanity_check_*.log"
cd "$SRCDIR/test" # Ensures we generate code coverage files in the right folder, and use the Terraform state of previously provisionned VMs.
./run-integration-tests.sh test
fi
# 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"

# Run integration tests:
export COVERAGE=true
export WEAVE_NET_SANITY_CHECKS_FILES="$CIRCLE_ARTIFACTS/weave_net_sanity_check_*.log"
cd "$SRCDIR/test" # Ensures we generate code coverage files in the right folder, and use the Terraform state of previously provisionned VMs.
./run-integration-tests.sh test
10 changes: 0 additions & 10 deletions bin/circle-test-teardown

This file was deleted.

11 changes: 0 additions & 11 deletions bin/circle-test-unit

This file was deleted.

33 changes: 15 additions & 18 deletions bin/provision_test_vms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ function signal_failure() {
}
trap signal_failure ERR

source "$STATE"

function install_terraform() {
curl -fsS https://releases.hashicorp.com/terraform/0.8.5/terraform_0.8.5_linux_amd64.zip | gunzip >terraform && chmod +x terraform && sudo mv terraform /usr/bin
}
Expand All @@ -20,24 +18,23 @@ 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"
}

if [ -n "$TEST_AND_PUBLISH" ]; then
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
exit 1
}
[ -n "$SECRET_KEY" ] || {
echo "Cannot run smoke tests: no secret key"
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
install_terraform
install_ansible

# Only attempt to create GCP image in first container, wait for it to be created otherwise:
[ "$CIRCLE_NODE_INDEX" != "0" ] && export CREATE_IMAGE=0
# Only attempt to create GCP image in first container, wait for it to be created otherwise:
[ "$CIRCLE_NODE_INDEX" != "0" ] && export CREATE_IMAGE=0

# Provision and configure testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh configure >>"$TEST_VMS_SETUP_OUTPUT_FILE" 2>&1
echo "OK" >"$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
echo "Test VMs now provisioned and configured. $(date)." >>"$TEST_VMS_SETUP_OUTPUT_FILE"
fi
# Provision and configure testing VMs:
cd "$SRCDIR/test" # Ensures we generate Terraform state files in the right folder, for later use by integration tests.
./run-integration-tests.sh configure
echo "OK" >"$TEST_VMS_PROV_AND_CONF_LOCK_FILE"
echo "Test VMs now provisioned and configured. $(date)."
2 changes: 1 addition & 1 deletion bin/wait_for.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ wait_for() {
if ! ((i % 10)); then echo "[$i seconds]: Waiting for $lock_file to be created..."; fi
sleep 1
done
echo "Timed out waiting for test VMs to be ready. See details in: $TEST_VMS_SETUP_OUTPUT_FILE" >&2
echo "Timed out waiting for test VMs to be ready." >&2
return 1
}
Loading

0 comments on commit dcaf77a

Please sign in to comment.