Skip to content

Commit

Permalink
Merge pull request #3333 from weaveworks/circle-2.0
Browse files Browse the repository at this point in the history
Move to CircleCI 2.0
  • Loading branch information
bboreham authored Sep 1, 2018
2 parents 65bdb14 + d9e88c0 commit fda40b8
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 137 deletions.
178 changes: 178 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
version: 2

defaults: &defaults
working_directory: /go/src/github.com/weaveworks/scope
docker:
- image: weaveworks/scope-backend-build:circle-2.0-4ad2f14

client-defaults: &client-defaults
working_directory: /home/weave/scope
docker:
- image: weaveworks/scope-ui-build:circle-2.0-1734def7

workflows:
version: 2
test_and_deploy:
jobs:
- lint
- unit-test
- client-build
- client-test:
requires:
- client-build
- xplatform-build:
requires:
- build
- build:
requires:
- client-build
- integration-tests:
requires:
- lint
- unit-test
- build
- deploy:
filters:
branches:
only: master
requires:
- client-test
- integration-tests

jobs:
lint:
<<: *defaults
steps:
- checkout
- run: make BUILD_IN_CONTAINER=false lint

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

# Create client/build/index.html
client-build:
<<: *client-defaults
steps:
- checkout
# Convoluted set of steps here to mimic Makefile actions of bind-mounting different dirs into container
- run: mv client/app /home/weave/
- run: cd /home/weave; mkdir build ; yarn run build ; mv build scope/client
- run: cd /home/weave; mkdir build-external; yarn run build-external; mv build-external scope/client
- run: cd /home/weave; mkdir tmp ; yarn run bundle ; mv tmp scope
- persist_to_workspace:
root: /home/weave/scope
paths:
- client/build/
- client/build-external/
- tmp/weave-scope.tgz

client-test:
<<: *client-defaults
steps:
- checkout
- run: |
mv client/app client/test /home/weave/
cd /home/weave; yarn run lint
cd /home/weave; yarn test
xplatform-build:
<<: *defaults
steps:
- checkout
- run: GOARCH=arm make BUILD_IN_CONTAINER=false GO_BUILD_INSTALL_DEPS= prog/scope
- run: GOOS=darwin make BUILD_IN_CONTAINER=false GO_BUILD_INSTALL_DEPS= prog/scope

build:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: .
- run: make BUILD_IN_CONTAINER=false SUDO= static all
- run: cd extras; make BUILD_IN_CONTAINER=false
- run: make -C tools/runner
- persist_to_workspace:
root: .
paths:
- scope.tar
- cloud-agent.tar
- tools/runner/runner
- prog/externalui/
- prog/staticui/
- report/report.codecgen.go
- render/detailed/detailed.codecgen.go

integration-tests:
machine:
image: circleci/classic:201709-01
working_directory: /home/circleci/src/github.com/weaveworks/scope
environment:
CIRCLE_ARTIFACTS: /tmp/artifacts
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
GOPATH: /home/circleci/
parallelism: 2
steps:
- checkout
- attach_workspace:
at: .
- run: |
sudo apt-get update
sudo apt-get install python-pip jq pv
- run: mkdir $CIRCLE_ARTIFACTS
# kick off creation of test VMs
- run: test -z "$SECRET_PASSWORD" || bin/setup-circleci-secrets "$SECRET_PASSWORD"
- run: test -z "$SECRET_PASSWORD" || (cd integration; ./gce.sh make_template)
- run: test -z "$SECRET_PASSWORD" || (cd integration; ./gce.sh setup && eval $(./gce.sh hosts); ./setup.sh)
- run: make deps; touch tools/runner/runner
# Run all integration tests
- run:
command: test -z "$SECRET_PASSWORD" || (cd integration; eval $(./gce.sh hosts); ./run_all.sh)
no_output_timeout: 5m
# Destroy testing VMs:
- run:
command: test -z "$SECRET_PASSWORD" || (cd integration; ./gce.sh destroy)
background: true
# Code coverage
- run: ./tools/cover/gather_coverage.sh ./coverage
- run: goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=profile.cov -service=circleci
- run: cp coverage.* */*.codecgen.go $CIRCLE_ARTIFACTS
- store_artifacts:
path: /tmp/artifacts

deploy:
<<: *defaults
environment:
IMAGES: scope cloud-agent
steps:
- checkout
- setup_remote_docker
- attach_workspace:
at: .
- run: |
pip install awscli
docker load -i scope.tar
docker load -i cloud-agent.tar
- run: |
test -z "${DOCKER_USER}" && exit 0
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
for IMAGE in $IMAGES; do
test "${DOCKER_ORGANIZATION:-$DOCKER_USER}" = "weaveworks" || docker tag weaveworks/$IMAGE:latest ${DOCKER_ORGANIZATION:-$DOCKER_USER}/$IMAGE:latest
docker tag weaveworks/$IMAGE:latest ${DOCKER_ORGANIZATION:-$DOCKER_USER}/$IMAGE:$(./tools/image-tag)
docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/$IMAGE:latest
docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/$IMAGE:$(./tools/image-tag)
done
- run: |
test -z "${QUAY_USER}" && exit 0
docker login -e '.' -u "$QUAY_USER" -p "$QUAY_PASSWORD" quay.io
docker tag weaveworks/scope:$(./tools/image-tag) "quay.io/${QUAY_ORGANIZATION}/scope:$(./tools/image-tag)"
docker push "quay.io/${QUAY_ORGANIZATION}/scope:$(./tools/image-tag)"
- run: test -z "${UI_BUCKET_KEY_ID}" || (make BUILD_IN_CONTAINER=false ui-upload ui-pkg-upload)
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $(SCOPE_EXE) $(RUNSVINIT) lint tests shell prog/staticui/staticui.go prog/extern

else

$(SCOPE_EXE): $(SCOPE_BACKEND_BUILD_UPTODATE)
$(SCOPE_EXE):
time $(GO) build $(GO_BUILD_FLAGS) -o $@ ./$(@D)
@strings $@ | grep cgo_stub\\\.go >/dev/null || { \
rm $@; \
Expand All @@ -118,24 +118,24 @@ $(CODECGEN_EXE): $(CODECGEN_DIR)/*.go
mkdir -p $(@D)
$(GO_HOST) build $(GO_BUILD_FLAGS) -o $@ ./$(CODECGEN_DIR)

$(RUNSVINIT): $(SCOPE_BACKEND_BUILD_UPTODATE)
$(RUNSVINIT):
time $(GO) build $(GO_BUILD_FLAGS) -o $@ ./$(@D)

shell: $(SCOPE_BACKEND_BUILD_UPTODATE)
shell:
/bin/bash

tests: $(SCOPE_BACKEND_BUILD_UPTODATE) $(CODECGEN_TARGETS) prog/staticui/staticui.go prog/externalui/externalui.go
tests: $(CODECGEN_TARGETS) prog/staticui/staticui.go prog/externalui/externalui.go
./tools/test -no-go-get -tags $(GO_BUILD_TAGS)

lint: $(SCOPE_BACKEND_BUILD_UPTODATE)
lint:
./tools/lint
./tools/shell-lint tools

prog/staticui/staticui.go: $(SCOPE_BACKEND_BUILD_UPTODATE)
prog/staticui/staticui.go:
mkdir -p prog/staticui
esc -o $@ -pkg staticui -prefix client/build client/build

prog/externalui/externalui.go: $(SCOPE_BACKEND_BUILD_UPTODATE)
prog/externalui/externalui.go:
mkdir -p prog/externalui
esc -o $@ -pkg externalui -prefix client/build-external -include '\.html$$' client/build-external

Expand Down Expand Up @@ -195,10 +195,12 @@ endif

$(SCOPE_UI_BUILD_UPTODATE): client/Dockerfile client/package.json client/webpack.local.config.js client/webpack.production.config.js client/server.js client/.eslintrc
$(SUDO) docker build -t $(SCOPE_UI_BUILD_IMAGE) client
$(SUDO) docker tag $(SCOPE_UI_BUILD_IMAGE) $(SCOPE_UI_BUILD_IMAGE):$(IMAGE_TAG)
touch $@

$(SCOPE_BACKEND_BUILD_UPTODATE): backend/*
$(SUDO) docker build -t $(SCOPE_BACKEND_BUILD_IMAGE) backend
$(SUDO) docker tag $(SCOPE_BACKEND_BUILD_IMAGE) $(SCOPE_BACKEND_BUILD_IMAGE):$(IMAGE_TAG)
touch $@

ui-upload: client/build-external/index.html
Expand Down
33 changes: 21 additions & 12 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ RUN set -eux; \
export arch_val="$(dpkg --print-architecture)"; \
apt-get update && \
if [ "$arch_val" = "amd64" ]; then \
apt-get install -y libpcap-dev python-requests time file shellcheck git gcc-arm-linux-gnueabihf curl build-essential python-pip; \
apt-get install -y libpcap-dev time file shellcheck git gcc-arm-linux-gnueabihf curl build-essential python-pip; \
else \
apt-get install -y libpcap-dev python-requests time file shellcheck git curl build-essential python-pip; \
apt-get install -y libpcap-dev time file shellcheck git curl build-essential python-pip; \
fi; \
\
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand All @@ -16,16 +16,8 @@ RUN go clean -i net && \
export arch_val="$(dpkg --print-architecture)"; \
if [ "$arch_val" != "ppc64el" ]; then \
go install -race -tags netgo std; \
fi;
RUN export arch_val="$(dpkg --print-architecture)"; \
if [ "$arch_val" = "amd64" ]; then \
curl -fsSL -o shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
chmod +x shfmt && \
mv shfmt /usr/bin; \
fi;
# Skipped installing shfmt, as the version v1.3.0 isn't supported for ppc64le
# and the later version of shfmt doesn't work with the application well
RUN go get -tags netgo \
fi; \
go get -tags netgo \
github.com/fzipp/gocyclo \
github.com/golang/lint/golint \
github.com/kisielk/errcheck \
Expand All @@ -34,7 +26,24 @@ RUN go get -tags netgo \
github.com/client9/misspell/cmd/misspell && \
chmod a+wr --recursive /usr/local/go && \
rm -rf /go/pkg/ /go/src/

# Only install shfmt on amd64, as the version v1.3.0 isn't supported for ppc64le
# and the later version of shfmt doesn't work with the application well
RUN export arch_val="$(dpkg --print-architecture)"; \
if [ "$arch_val" = "amd64" ]; then \
curl -fsSL -o shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
chmod +x shfmt && \
mv shfmt /usr/bin; \
fi;

RUN pip install yapf==0.16.2 flake8==3.3.0 requests==2.19.1

# Install Docker (client only)
ENV DOCKERVERSION=17.03.2-ce
RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz && \
tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 -C /usr/local/bin docker/docker && \
rm docker-${DOCKERVERSION}.tgz

COPY build.sh /
ENTRYPOINT ["/build.sh"]

Expand Down
Loading

0 comments on commit fda40b8

Please sign in to comment.