From 769db3b352510346acc953a337e445b442d84704 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 08:03:14 +0000 Subject: [PATCH 01/16] Integration tests don't depend on container images --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1a8652576..1b4d2ed21 100644 --- a/Makefile +++ b/Makefile @@ -254,7 +254,7 @@ endif # Test and misc stuff -notebooks-integration-test: $(NOTEBOOKS_UPTODATE) +notebooks-integration-test: DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=notebooks_test' postgres:9.5)"; \ docker run $(RM) \ -v $(shell pwd):/go/src/github.com/weaveworks/service \ @@ -267,7 +267,7 @@ notebooks-integration-test: $(NOTEBOOKS_UPTODATE) test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \ exit $$status -users-integration-test: $(USERS_UPTODATE) $(PROTO_GOS) $(MOCK_GOS) +users-integration-test: $(PROTO_GOS) $(MOCK_GOS) DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=users_test' postgres:9.5)"; \ docker run $(RM) \ -v $(shell pwd):/go/src/github.com/weaveworks/service \ @@ -292,7 +292,7 @@ pubsub-integration-test: test -n "$(CIRCLECI)" || docker rm -f "$$PUBSUB_EMU_CONTAINER"; \ exit $$status -kubectl-service-integration-test: kubectl-service/$(UPTODATE) kubectl-service/grpc/kubectl-service.pb.go +kubectl-service-integration-test: kubectl-service/grpc/kubectl-service.pb.go SVC_CONTAINER="$$(docker run -d -p 4887:4772 -p 8887:80 $(IMAGE_PREFIX)/kubectl-service -dry-run=true)"; \ docker run $(RM) \ -v $(shell pwd):/go/src/github.com/weaveworks/service \ @@ -304,7 +304,7 @@ kubectl-service-integration-test: kubectl-service/$(UPTODATE) kubectl-service/gr test -n "$(CIRCLECI)" || docker rm -f "$$SVC_CONTAINER"; \ exit $$status -gcp-service-integration-test: gcp-service/$(UPTODATE) gcp-service/grpc/gcp-service.pb.go +gcp-service-integration-test: gcp-service/grpc/gcp-service.pb.go SVC_CONTAINER="$$(docker run -d -p 4888:4772 -p 8888:80 $(IMAGE_PREFIX)/gcp-service -dry-run=true)"; \ docker run $(RM) \ -v $(shell pwd):/go/src/github.com/weaveworks/service \ From aed9100879b560bd412375bcc14d81c25711995f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 08:09:24 +0000 Subject: [PATCH 02/16] Non-container builds don't depend on the build image These rules are all in the 'else' side of $(BUILD_IN_CONTAINER) --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1b4d2ed21..8a5a68bb5 100644 --- a/Makefile +++ b/Makefile @@ -208,38 +208,38 @@ flux-integration-test: build/$(UPTODATE) else -$(EXES): build/$(UPTODATE) $(PROTO_GOS) +$(EXES): $(PROTO_GOS) go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) -%.pb.go: build/$(UPTODATE) +%.pb.go: protoc -I ./vendor:./$(@D) --gogoslick_out=plugins=grpc:./$(@D) ./$(patsubst %.pb.go,%.proto,$@) -lint: build/$(UPTODATE) +lint: ./tools/lint . -test: build/$(UPTODATE) $(PROTO_GOS) $(MOCK_GOS) +test: $(PROTO_GOS) $(MOCK_GOS) TESTDIRS=${TESTDIRS} ./tools/test -netgo -no-race -$(MOCK_USERS): build/$(UPTODATE) +$(MOCK_USERS): mockgen -destination=$@ github.com/weaveworks/service/users UsersClient \ && sed -i'' s,github.com/weaveworks/service/vendor/,, $@ -$(MOCK_BILLING_DB): build/$(UPTODATE) $(BILLING_DB)/db.go +$(MOCK_BILLING_DB): $(BILLING_DB)/db.go mockgen -destination=$@ github.com/weaveworks/service/$(BILLING_DB) DB -$(MOCK_BILLING_GRPC): build/$(UPTODATE) +$(MOCK_BILLING_GRPC): mockgen -source=$(BILLING_GRPC) -destination=$@ -package=grpc -$(MOCK_COMMON_GCP_PARTNER_CLIENT): build/$(UPTODATE) +$(MOCK_COMMON_GCP_PARTNER_CLIENT): mockgen -destination=$@ github.com/weaveworks/service/common/gcp/partner API \ && sed -i'' s,github.com/weaveworks/service/vendor/,, $@ -$(MOCK_COMMON_GCP_PARTNER_ACCESS): build/$(UPTODATE) +$(MOCK_COMMON_GCP_PARTNER_ACCESS): mockgen -destination=$@ github.com/weaveworks/service/common/gcp/partner Accessor \ && sed -i'' s,github.com/weaveworks/service/vendor/,, $@ -billing-integration-test: build/$(UPTODATE) $(MOCK_GOS) +billing-integration-test: $(MOCK_GOS) /bin/bash -c "go test -tags 'netgo integration' -timeout 30s $(BILLING_TEST_DIRS)" flux-integration-test: From e66e81c62d32ce43d2499ad5b128024ff33374f4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 08:18:42 +0000 Subject: [PATCH 03/16] Extract variable for Go version for integration tests --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 8a5a68bb5..c59617498 100644 --- a/Makefile +++ b/Makefile @@ -254,6 +254,8 @@ endif # Test and misc stuff +INTEGRATION_TEST_IMAGE=golang:1.9.2-stretch + notebooks-integration-test: DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=notebooks_test' postgres:9.5)"; \ docker run $(RM) \ @@ -261,7 +263,7 @@ notebooks-integration-test: -v $(shell pwd)/notebooks/db/migrations:/migrations \ --workdir /go/src/github.com/weaveworks/service/notebooks \ --link "$$DB_CONTAINER":configs-db.weave.local \ - golang:1.9.2-stretch \ + $(INTEGRATION_TEST_IMAGE) \ /bin/bash -c "go test -tags integration -timeout 30s ./..."; \ status=$$?; \ test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \ @@ -274,7 +276,7 @@ users-integration-test: $(PROTO_GOS) $(MOCK_GOS) -v $(shell pwd)/users/db/migrations:/migrations \ --workdir /go/src/github.com/weaveworks/service/users \ --link "$$DB_CONTAINER":users-db.weave.local \ - golang:1.9.2-stretch \ + $(INTEGRATION_TEST_IMAGE) \ /bin/bash -c "go test -tags integration -timeout 30s ./..."; \ status=$$?; \ test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \ @@ -286,7 +288,7 @@ pubsub-integration-test: -v $(shell pwd):/go/src/github.com/weaveworks/service \ --net=host -p 127.0.0.1:1337:1337 \ --workdir /go/src/github.com/weaveworks/service/common/gcp/pubsub \ - golang:1.9.2-stretch \ + $(INTEGRATION_TEST_IMAGE) \ /bin/bash -c "RUN_MANUAL_TEST=1 go test -tags integration -timeout 30s ./..."; \ status=$$?; \ test -n "$(CIRCLECI)" || docker rm -f "$$PUBSUB_EMU_CONTAINER"; \ @@ -298,7 +300,7 @@ kubectl-service-integration-test: kubectl-service/grpc/kubectl-service.pb.go -v $(shell pwd):/go/src/github.com/weaveworks/service \ --workdir /go/src/github.com/weaveworks/service/kubectl-service \ --link "$$SVC_CONTAINER":kubectl-service.weave.local \ - golang:1.9.2-stretch \ + $(INTEGRATION_TEST_IMAGE) \ /bin/bash -c "go test -tags integration -timeout 30s ./..."; \ status=$$?; \ test -n "$(CIRCLECI)" || docker rm -f "$$SVC_CONTAINER"; \ @@ -310,7 +312,7 @@ gcp-service-integration-test: gcp-service/grpc/gcp-service.pb.go -v $(shell pwd):/go/src/github.com/weaveworks/service \ --workdir /go/src/github.com/weaveworks/service/gcp-service \ --link "$$SVC_CONTAINER":gcp-service.weave.local \ - golang:1.9.2-stretch \ + $(INTEGRATION_TEST_IMAGE) \ /bin/bash -c "go test -tags integration -timeout 30s ./..."; \ status=$$?; \ test -n "$(CIRCLECI)" || docker rm -f "$$SVC_CONTAINER"; \ From f90c1698b9f8b18ae4bdf985ac2e6727e6e51bdd Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 08:35:12 +0000 Subject: [PATCH 04/16] Run billing and flux integration tests the same as others So we don't need to build the build container in the integration test step at CircleCI. Also, consistency. --- Makefile | 78 +++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index c59617498..613f2a92f 100644 --- a/Makefile +++ b/Makefile @@ -176,36 +176,6 @@ $(EXES) test: build/$(UPTODATE) $(PROTO_GOS) -e TESTDIRS=${TESTDIRS} \ $(IMAGE_PREFIX)/build $@ -billing-integration-test: build/$(UPTODATE) - @mkdir -p $(shell pwd)/.pkg - DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=billing_test' postgres:9.5)"; \ - $(SUDO) docker run $(RM) -ti \ - -v $(shell pwd)/.pkg:/go/pkg \ - -v $(shell pwd):/go/src/github.com/weaveworks/service \ - -v $(shell pwd)/billing-api/db/migrations:/migrations \ - --workdir /go/src/github.com/weaveworks/service \ - --link "$$DB_CONTAINER":billing-db.weave.local \ - $(IMAGE_PREFIX)/build $@; \ - status=$$?; \ - test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \ - exit $$status - -flux-integration-test: build/$(UPTODATE) - @mkdir -p $(shell pwd)/.pkg - NATS_CONTAINER="$$(docker run -d nats)"; \ - POSTGRES_CONTAINER="$$(docker run -d postgres)"; \ - $(SUDO) docker run $(RM) -ti \ - -v $(shell pwd)/.pkg:/go/pkg \ - -v $(shell pwd):/go/src/github.com/weaveworks/service \ - -v $(shell pwd)/billing-api/db/migrations:/migrations \ - --workdir /go/src/github.com/weaveworks/service \ - --link "$$NATS_CONTAINER":nats \ - --link "$$POSTGRES_CONTAINER":postgres \ - $(IMAGE_PREFIX)/build $@; \ - status=$$?; \ - test -n "$(CIRCLECI)" || docker rm -f "$$NATS_CONTAINER" "$$POSTGRES_CONTAINER"; \ - exit $$status - else $(EXES): $(PROTO_GOS) @@ -239,23 +209,49 @@ $(MOCK_COMMON_GCP_PARTNER_ACCESS): mockgen -destination=$@ github.com/weaveworks/service/common/gcp/partner Accessor \ && sed -i'' s,github.com/weaveworks/service/vendor/,, $@ -billing-integration-test: $(MOCK_GOS) - /bin/bash -c "go test -tags 'netgo integration' -timeout 30s $(BILLING_TEST_DIRS)" - -flux-integration-test: -# These packages must currently be tested in series because -# otherwise they will all race to run migrations. - /bin/bash -c "go test -tags integration -timeout 30s ./flux-api" - /bin/bash -c "go test -tags integration -timeout 30s ./flux-api/bus/nats" - /bin/bash -c "go test -tags integration -timeout 30s ./flux-api/history/sql" - /bin/bash -c "go test -tags integration -timeout 30s ./flux-api/instance/sql" - endif # Test and misc stuff INTEGRATION_TEST_IMAGE=golang:1.9.2-stretch +billing-integration-test: $(MOCK_GOS) + @mkdir -p $(shell pwd)/.pkg + DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=billing_test' postgres:9.5)"; \ + $(SUDO) docker run $(RM) -ti \ + -v $(shell pwd)/.pkg:/go/pkg \ + -v $(shell pwd):/go/src/github.com/weaveworks/service \ + -v $(shell pwd)/billing-api/db/migrations:/migrations \ + --workdir /go/src/github.com/weaveworks/service \ + --link "$$DB_CONTAINER":billing-db.weave.local \ + $(INTEGRATION_TEST_IMAGE) \ + /bin/bash -c "go test -tags 'netgo integration' -timeout 30s $(BILLING_TEST_DIRS)"; \ + status=$$?; \ + test -n "$(CIRCLECI)" || docker rm -f "$$DB_CONTAINER"; \ + exit $$status + +flux-integration-test: + @mkdir -p $(shell pwd)/.pkg +# These packages must currently be tested in series because +# otherwise they will all race to run migrations. + NATS_CONTAINER="$$(docker run -d nats)"; \ + POSTGRES_CONTAINER="$$(docker run -d postgres)"; \ + $(SUDO) docker run $(RM) -ti \ + -v $(shell pwd)/.pkg:/go/pkg \ + -v $(shell pwd):/go/src/github.com/weaveworks/service \ + -v $(shell pwd)/billing-api/db/migrations:/migrations \ + --workdir /go/src/github.com/weaveworks/service \ + --link "$$NATS_CONTAINER":nats \ + --link "$$POSTGRES_CONTAINER":postgres \ + $(INTEGRATION_TEST_IMAGE) \ + /bin/bash -c "go test -tags integration -timeout 30s ./flux-api && \ + go test -tags integration -timeout 30s ./flux-api/bus/nats &&\ + go test -tags integration -timeout 30s ./flux-api/history/sql &&\ + go test -tags integration -timeout 30s ./flux-api/instance/sql"; \ + status=$$?; \ + test -n "$(CIRCLECI)" || docker rm -f "$$NATS_CONTAINER" "$$POSTGRES_CONTAINER"; \ + exit $$status + notebooks-integration-test: DB_CONTAINER="$$(docker run -d -e 'POSTGRES_DB=notebooks_test' postgres:9.5)"; \ docker run $(RM) \ From f95773b3b49b98a3cb2e7f3d5b2582bb3a6b33a8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 09:03:13 +0000 Subject: [PATCH 05/16] Re-order integration tests to avoid rebuilding images --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 774d9817f..3b6e0a1e4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,6 +93,9 @@ jobs: background: true - run: | cd $SRCDIR + # Notifications comes first because it uses the downloaded images + # subsequent steps will require code generation which would trigger a rebuild + make RM= notification-integration-test make RM= notebooks-integration-test make RM= users-integration-test make RM= billing-integration-test @@ -100,7 +103,6 @@ jobs: make RM= flux-integration-test make RM= kubectl-service-integration-test make RM= gcp-service-integration-test - make RM= notification-integration-test upload: <<: *defaults From 2e7196d7a458c2bfe57a4a3dd6e30f95290760ec Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 2 Jul 2018 09:47:53 +0000 Subject: [PATCH 06/16] Touch .uptodate files after downloading images --- .circleci/config.yml | 1 + Makefile | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b6e0a1e4..743a9c5c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,6 +84,7 @@ jobs: docker tag ${repo_tmp_image} ${image}:latest docker image rm ${repo_tmp_image} done + make touch-uptodate # FIXME: we probably don't need to copy the code and change the working dir - run: echo -e "export GOPATH=$HOME\nexport SRCDIR=$HOME/src/github.com/weaveworks/service\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV - run: mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR diff --git a/Makefile b/Makefile index 613f2a92f..e2ed2f9e3 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,9 @@ images: $(info $(IMAGE_NAMES)) @echo > /dev/null +touch-uptodate: + touch $(UPTODATE_FILES) + all: $(UPTODATE_FILES) # Generating proto code is automated. From 5af7aeabcb57a4b9123ddde79ae58eacc9dedfd4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 19:11:22 +0000 Subject: [PATCH 07/16] Save/restore generated files --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 743a9c5c2..1a7669b3c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,6 +46,16 @@ jobs: docker tag ${tagged_image} ${repo_tmp_image} docker push $repo_tmp_image done + - persist_to_workspace: + root: . + paths: + - users/mock_users/mock_usersclient.go + - users/client/mock_client.go + - billing-api/db/mock_db/mock_db.go + - common/billing/grpc/mock_grpc.go + - common/gcp/partner/mock_partner/mock_access.go + - common/gcp/partner/mock_partner/mock_client.go + test: <<: *defaults steps: @@ -88,6 +98,8 @@ jobs: # FIXME: we probably don't need to copy the code and change the working dir - run: echo -e "export GOPATH=$HOME\nexport SRCDIR=$HOME/src/github.com/weaveworks/service\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV - run: mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR + - attach_workspace: + at: . - run: go get github.com/nats-io/gnatsd - run: command: gnatsd From bb4a44069b4755cd1777bcf1930bebba28e04d4c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 19:30:56 +0000 Subject: [PATCH 08/16] Don't copy source tree elsewhere --- .circleci/config.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a7669b3c..4b8cbb8b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,18 +15,15 @@ jobs: steps: - checkout - run: sudo docker info >/dev/null 2>&1 || sudo service docker start; - # FIXME: we probably don't need to copy the code and change the working dir - - run: echo -e "export GOPATH=$HOME\nexport SRCDIR=$HOME/src/github.com/weaveworks/service\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV - - run: mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR - run: | - cd $SRCDIR/build + cd build ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile touch .uptodate - - run: cd $SRCDIR; make RM= + - run: make - run: | set -e set -o pipefail - cd $SRCDIR; if [ $(./tools/image-tag | grep -e '-WIP$') ]; then + if [ $(./tools/image-tag | grep -e '-WIP$') ]; then echo "WIP build; exiting with error to mark as a failure" git --no-pager diff exit 1 @@ -95,9 +92,6 @@ jobs: docker image rm ${repo_tmp_image} done make touch-uptodate - # FIXME: we probably don't need to copy the code and change the working dir - - run: echo -e "export GOPATH=$HOME\nexport SRCDIR=$HOME/src/github.com/weaveworks/service\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV - - run: mkdir -p $(dirname $SRCDIR) && cp -r $(pwd)/ $SRCDIR - attach_workspace: at: . - run: go get github.com/nats-io/gnatsd @@ -105,7 +99,6 @@ jobs: command: gnatsd background: true - run: | - cd $SRCDIR # Notifications comes first because it uses the downloaded images # subsequent steps will require code generation which would trigger a rebuild make RM= notification-integration-test From 5e1604b5b2029ebd58a7e62113c7dc01b043205c Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 19:40:20 +0000 Subject: [PATCH 09/16] Save/restore build image to CircleCI cache --- .circleci/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4b8cbb8b8..a2b17fa19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,10 +15,17 @@ jobs: steps: - checkout - run: sudo docker info >/dev/null 2>&1 || sudo service docker start; + - restore_cache: + keys: + - build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} - run: | cd build ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile touch .uptodate + - save_cache: + key: build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} + paths: + - docker - run: make - run: | set -e From c528e8286fa078107de34e1b402d81f262f92b96 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 20:56:31 +0000 Subject: [PATCH 10/16] Save more generated files --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a2b17fa19..4999b7cdf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,6 +59,10 @@ jobs: - common/billing/grpc/mock_grpc.go - common/gcp/partner/mock_partner/mock_access.go - common/gcp/partner/mock_partner/mock_client.go + - gcp-service/grpc/gcp-service.pb.go + - users/users.pb.go + - common/billing/grpc/billing.pb.go + - kubectl-service/grpc/kubectl-service.pb.go test: <<: *defaults From 2f80d8f7f549be895d3a4543b00285f3b5e5f3b5 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 21:41:51 +0000 Subject: [PATCH 11/16] Touch generated files so they don't rebuild --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4999b7cdf..c46d4a89a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -110,8 +110,7 @@ jobs: command: gnatsd background: true - run: | - # Notifications comes first because it uses the downloaded images - # subsequent steps will require code generation which would trigger a rebuild + touch users/mock_users/mock_usersclient.go users/client/mock_client.go billing-api/db/mock_db/mock_db.go common/billing/grpc/mock_grpc.go common/gcp/partner/mock_partner/mock_access.go common/gcp/partner/mock_partner/mock_client.go gcp-service/grpc/gcp-service.pb.go users/users.pb.go common/billing/grpc/billing.pb.go kubectl-service/grpc/kubectl-service.pb.go make RM= notification-integration-test make RM= notebooks-integration-test make RM= users-integration-test From 7f82ab452a021fbaecca0e4f26ff9440726bff42 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 21:50:35 +0000 Subject: [PATCH 12/16] Fix cache save path --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c46d4a89a..8fd9e4394 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - save_cache: key: build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} paths: - - docker + - ~/docker - run: make - run: | set -e From 01c13c2f0216414b45a191b2b90bbe1a22771127 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 21:52:11 +0000 Subject: [PATCH 13/16] Touch image-uptodate files after generated files --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fd9e4394..6588af014 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,7 +102,6 @@ jobs: docker tag ${repo_tmp_image} ${image}:latest docker image rm ${repo_tmp_image} done - make touch-uptodate - attach_workspace: at: . - run: go get github.com/nats-io/gnatsd @@ -111,6 +110,7 @@ jobs: background: true - run: | touch users/mock_users/mock_usersclient.go users/client/mock_client.go billing-api/db/mock_db/mock_db.go common/billing/grpc/mock_grpc.go common/gcp/partner/mock_partner/mock_access.go common/gcp/partner/mock_partner/mock_client.go gcp-service/grpc/gcp-service.pb.go users/users.pb.go common/billing/grpc/billing.pb.go kubectl-service/grpc/kubectl-service.pb.go + make touch-uptodate make RM= notification-integration-test make RM= notebooks-integration-test make RM= users-integration-test From a50365a5459e66bfd7f06c104b6fd4b26f637f7b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 22:13:20 +0000 Subject: [PATCH 14/16] Mocks are not built during build step --- .circleci/config.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6588af014..3f199ca5f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,12 +53,7 @@ jobs: - persist_to_workspace: root: . paths: - - users/mock_users/mock_usersclient.go - users/client/mock_client.go - - billing-api/db/mock_db/mock_db.go - - common/billing/grpc/mock_grpc.go - - common/gcp/partner/mock_partner/mock_access.go - - common/gcp/partner/mock_partner/mock_client.go - gcp-service/grpc/gcp-service.pb.go - users/users.pb.go - common/billing/grpc/billing.pb.go @@ -109,7 +104,7 @@ jobs: command: gnatsd background: true - run: | - touch users/mock_users/mock_usersclient.go users/client/mock_client.go billing-api/db/mock_db/mock_db.go common/billing/grpc/mock_grpc.go common/gcp/partner/mock_partner/mock_access.go common/gcp/partner/mock_partner/mock_client.go gcp-service/grpc/gcp-service.pb.go users/users.pb.go common/billing/grpc/billing.pb.go kubectl-service/grpc/kubectl-service.pb.go + touch users/client/mock_client.go gcp-service/grpc/gcp-service.pb.go users/users.pb.go common/billing/grpc/billing.pb.go kubectl-service/grpc/kubectl-service.pb.go make touch-uptodate make RM= notification-integration-test make RM= notebooks-integration-test From c7bcec6d228877f5d1944c9ac2c7428d7fb00cb9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 29 Jul 2018 22:13:47 +0000 Subject: [PATCH 15/16] Run rebuild-image in all steps that use the build container --- .circleci/config.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f199ca5f..7e303094c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,6 +8,12 @@ jobs: <<: *defaults steps: - checkout + - run: + name: Create build image + command: | + cd build + ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile + touch .uptodate - run: make RM= lint build: @@ -18,10 +24,12 @@ jobs: - restore_cache: keys: - build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} - - run: | - cd build - ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile - touch .uptodate + - run: + name: Create build image + command: | + cd build + ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile + touch .uptodate - save_cache: key: build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} paths: @@ -63,6 +71,12 @@ jobs: <<: *defaults steps: - checkout + - run: + name: Create build image + command: | + cd build + ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile + touch .uptodate - run: echo -e "export GOPATH=$HOME\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV # Link the working directory so that it appears in GOPATH. This is required for cover to map coverage statistics to sources. - run: mkdir -p ${GOPATH}/src/github.com/weaveworks && ln -s $(pwd) ${GOPATH}/src/github.com/weaveworks/service From 6118bd1adf2271b0843da243f55329e07faf3fa4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 30 Jul 2018 06:58:14 +0000 Subject: [PATCH 16/16] Run build in 'docker' mode with prebuild image --- .circleci/config.yml | 65 +++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7e303094c..6a2bc5ef8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,40 +1,24 @@ version: 2 + +# https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/ defaults: &defaults - machine: - docker_layer_caching: true - working_directory: ~/weaveworks/service + docker: + - image: weaveworks/service-build:master-8245ec7d + working_directory: /go/src/github.com/weaveworks/service + jobs: lint: <<: *defaults steps: - checkout - - run: - name: Create build image - command: | - cd build - ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile - touch .uptodate - - run: make RM= lint + - run: make BUILD_IN_CONTAINER=false lint build: <<: *defaults steps: - checkout - - run: sudo docker info >/dev/null 2>&1 || sudo service docker start; - - restore_cache: - keys: - - build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} - - run: - name: Create build image - command: | - cd build - ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile - touch .uptodate - - save_cache: - key: build-image-cache-{{ checksum "build/build.sh" }}-{{ checksum "build/Dockerfile" }} - paths: - - ~/docker - - run: make + - setup_remote_docker + - run: make BUILD_IN_CONTAINER=false SUDO= - run: | set -e set -o pipefail @@ -71,17 +55,9 @@ jobs: <<: *defaults steps: - checkout - - run: - name: Create build image - command: | - cd build - ../tools/rebuild-image quay.io/weaveworks/build . build.sh Dockerfile - touch .uptodate - - run: echo -e "export GOPATH=$HOME\nexport PATH=/usr/local/go/bin:$HOME/bin:$PATH" >> $BASH_ENV - # Link the working directory so that it appears in GOPATH. This is required for cover to map coverage statistics to sources. - - run: mkdir -p ${GOPATH}/src/github.com/weaveworks && ln -s $(pwd) ${GOPATH}/src/github.com/weaveworks/service + - setup_remote_docker - run: go get github.com/mattn/goveralls - - run: COVERDIR=./coverage make RM= test + - run: COVERDIR=./coverage make BUILD_IN_CONTAINER=false test - run: ./tools/cover/gather_coverage.sh ./coverage $CIRCLE_WORKING_DIRECTORY/coverage - run: goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=$CIRCLE_WORKING_DIRECTORY/profile.cov -service=circleci || true - run: mkdir /tmp/coverage && cp coverage.* /tmp/coverage @@ -92,6 +68,7 @@ jobs: <<: *defaults steps: - checkout + - setup_remote_docker - &pull-tmp-images run: name: Download docker images build earlier in workflow @@ -120,19 +97,20 @@ jobs: - run: | touch users/client/mock_client.go gcp-service/grpc/gcp-service.pb.go users/users.pb.go common/billing/grpc/billing.pb.go kubectl-service/grpc/kubectl-service.pb.go make touch-uptodate - make RM= notification-integration-test - make RM= notebooks-integration-test - make RM= users-integration-test - make RM= billing-integration-test - make RM= pubsub-integration-test - make RM= flux-integration-test - make RM= kubectl-service-integration-test - make RM= gcp-service-integration-test + make BUILD_IN_CONTAINER=false notification-integration-test + make BUILD_IN_CONTAINER=false notebooks-integration-test + make BUILD_IN_CONTAINER=false users-integration-test + make BUILD_IN_CONTAINER=false billing-integration-test + make BUILD_IN_CONTAINER=false pubsub-integration-test + make BUILD_IN_CONTAINER=false flux-integration-test + make BUILD_IN_CONTAINER=false kubectl-service-integration-test + make BUILD_IN_CONTAINER=false gcp-service-integration-test upload: <<: *defaults steps: - checkout + - setup_remote_docker - <<: *pull-tmp-images - run: name: Publish docker images to final repository @@ -146,6 +124,7 @@ jobs: <<: *defaults steps: - checkout + - setup_remote_docker - <<: *pull-tmp-images - run: name: Dry-run of publishing docker images