From 49de4ed28b0132dabac462299bf9d31254ce5e1c Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Fri, 9 Mar 2018 11:27:00 +0100 Subject: [PATCH] build: upgrades build pipeline from CircleCI 1.0 -> 2.0 (#11162) build: upgrades build pipeline from CircleCI 1.0 -> 2.0 --- circle.yml | 188 +++++++++++++++++++++++--------- scripts/build/build.sh | 3 - scripts/circle-test-backend.sh | 3 - scripts/circle-test-frontend.sh | 6 - scripts/webpack/webpack.test.js | 2 +- 5 files changed, 135 insertions(+), 67 deletions(-) diff --git a/circle.yml b/circle.yml index b429911ceb8..c8caa3696c2 100644 --- a/circle.yml +++ b/circle.yml @@ -1,57 +1,137 @@ -machine: - node: - version: 6.11.4 - python: - version: 2.7.3 - services: - - docker - environment: - GOPATH: "/home/ubuntu/.go_workspace" - ORG_PATH: "github.com/grafana" - REPO_PATH: "${ORG_PATH}/grafana" - GODIST: "go1.10.linux-amd64.tar.gz" - post: - - mkdir -p ~/download - - mkdir -p ~/docker - - test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST - - sudo rm -rf /usr/local/go - - sudo tar -C /usr/local -xzf download/$GODIST +version: 2 -dependencies: - cache_directories: - - "~/docker" - - "~/download" - override: - - rm -rf ${GOPATH}/src/${REPO_PATH} - - mkdir -p ${GOPATH}/src/${ORG_PATH} - - cp -r ~/grafana ${GOPATH}/src/${ORG_PATH} - pre: - - pip install awscli - - sudo apt-get update; sudo apt-get install rpm; sudo apt-get install expect - - ./scripts/build/build_container.sh +jobs: + test-frontend: + docker: + - image: circleci/node:6.11.4 + steps: + - checkout + - run: + name: install yarn + command: 'sudo npm install -g yarn --quiet' + - restore_cache: + key: dependency-cache-{{ checksum "yarn.lock" }} + # Could we skip this step if the cache has been restored? `[ -d node_modules ] || yarn install ...` should be able to apply to build step as well + - run: + name: yarn install + command: 'yarn install --pure-lockfile --no-progress' + - save_cache: + key: dependency-cache-{{ checksum "yarn.lock" }} + paths: + - node_modules + - run: + name: frontend tests + command: './scripts/circle-test-frontend.sh' -test: - override: - - bash scripts/circle-test-frontend.sh - - bash scripts/circle-test-backend.sh + test-backend: + docker: + - image: circleci/golang:1.10 + working_directory: /go/src/github.com/grafana/grafana + steps: + - checkout + - run: + name: build backend and run go tests + command: './scripts/circle-test-backend.sh' -deployment: - gh_branch: - branch: master - commands: - - ./scripts/build/deploy.sh - - ./scripts/build/sign_packages.sh - - go run build.go sha-dist - - aws s3 sync ./dist s3://$BUCKET_NAME/master - - ./scripts/trigger_windows_build.sh ${APPVEYOR_TOKEN} ${CIRCLE_SHA1} master - - ./scripts/trigger_docker_build.sh ${TRIGGER_GRAFANA_PACKER_CIRCLECI_TOKEN} - - go run ./scripts/build/publish.go -apiKey ${GRAFANA_COM_API_KEY} - gh_tag: - tag: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ - commands: - - ./scripts/build/deploy.sh - - ./scripts/build/sign_packages.sh - - go run build.go sha-dist - - aws s3 sync ./dist s3://$BUCKET_NAME/release - - ./scripts/trigger_windows_build.sh ${APPVEYOR_TOKEN} ${CIRCLE_SHA1} release - - ./scripts/trigger_docker_build.sh ${TRIGGER_GRAFANA_PACKER_CIRCLECI_TOKEN} ${CIRCLE_TAG} + build: + docker: + - image: grafana/build-container:v0.1 + working_directory: /go/src/github.com/grafana/grafana + steps: + - checkout + - run: + name: build and package grafana + command: './scripts/build/build.sh' + - run: + name: sign packages + command: './scripts/build/sign_packages.sh' + - run: + name: sha-sum packages + command: 'go run build.go sha-dist' + - run: + name: Build Grafana.com publisher + command: 'go build -o scripts/publish scripts/build/publish.go' + - persist_to_workspace: + root: . + paths: + - dist/grafana* + - scripts/*.sh + - scripts/publish + + deploy-master: + docker: + - image: circleci/python:2.7-stretch + working_directory: /go/src/github.com/grafana/grafana + steps: + - attach_workspace: + at: . + - run: + name: install awscli + command: 'sudo pip install awscli' + - run: + name: deploy to s3 + command: 'aws s3 sync ./dist s3://$BUCKET_NAME/master' + - run: + name: Trigger Windows build + command: './scripts/trigger_windows_build.sh ${APPVEYOR_TOKEN} ${CIRCLE_SHA1} master' + - run: + name: Trigger Docker build + command: './scripts/trigger_docker_build.sh ${TRIGGER_GRAFANA_PACKER_CIRCLECI_TOKEN}' + - run: + name: Publish to Grafana.com + command: './scripts/publish -apiKey ${GRAFANA_COM_API_KEY}' + + deploy-release: + docker: + - image: circleci/python:2.7-stretch + working_directory: /go/src/github.com/grafana/grafana + steps: + - attach_workspace: + at: dist + - run: + name: install awscli + command: 'sudo pip install awscli' + - run: + name: deploy to s3 + command: 'aws s3 sync ./dist s3://$BUCKET_NAME/release' + - run: + name: Trigger Windows build + command: './scripts/trigger_windows_build.sh ${APPVEYOR_TOKEN} ${CIRCLE_SHA1} release' + - run: + name: Trigger Docker build + command: './scripts/trigger_docker_build.sh ${TRIGGER_GRAFANA_PACKER_CIRCLECI_TOKEN} ${CIRCLE_TAG}' + +workflows: + version: 2 + test-and-build: + jobs: + - build: + filters: + tags: + only: /.*/ + - test-frontend: + filters: + tags: + only: /.*/ + - test-backend: + filters: + tags: + only: /.*/ + - deploy-master: + requires: + - test-backend + - test-frontend + - build + filters: + branches: + only: master + - deploy-release: + requires: + - test-backend + - test-frontend + - build + filters: + branches: + ignore: /.*/ + tags: + only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ diff --git a/scripts/build/build.sh b/scripts/build/build.sh index 4f16ee240c4..369d434d4f5 100755 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -21,9 +21,6 @@ fi yarn install --pure-lockfile --no-progress source /etc/profile.d/rvm.sh -rvm use 2.1.9 --default - -gem install fpm -v 1.4 echo "current dir: $(pwd)" diff --git a/scripts/circle-test-backend.sh b/scripts/circle-test-backend.sh index 4e639f82007..a63d6354fa6 100755 --- a/scripts/circle-test-backend.sh +++ b/scripts/circle-test-backend.sh @@ -10,15 +10,12 @@ function exit_if_fail { fi } -cd /home/ubuntu/.go_workspace/src/github.com/grafana/grafana - echo "running go fmt" exit_if_fail test -z "$(gofmt -s -l ./pkg | tee /dev/stderr)" echo "running go vet" exit_if_fail test -z "$(go vet ./pkg/... | tee /dev/stderr)" -cd ~/dev/go/src/github.com/grafana/grafana echo "building backend with install to cache pkgs" exit_if_fail time go install ./pkg/cmd/grafana-server diff --git a/scripts/circle-test-frontend.sh b/scripts/circle-test-frontend.sh index 6a8684b4006..9857e00f70d 100755 --- a/scripts/circle-test-frontend.sh +++ b/scripts/circle-test-frontend.sh @@ -10,12 +10,6 @@ function exit_if_fail { fi } -cd /home/ubuntu/.go_workspace/src/github.com/grafana/grafana - -rm -rf node_modules -npm install -g yarn --quiet -yarn install --pure-lockfile --no-progress - exit_if_fail npm run test:coverage exit_if_fail npm run build diff --git a/scripts/webpack/webpack.test.js b/scripts/webpack/webpack.test.js index f30c7876185..b1e8ddf2471 100644 --- a/scripts/webpack/webpack.test.js +++ b/scripts/webpack/webpack.test.js @@ -16,7 +16,7 @@ config = merge(common, { new webpack.SourceMapDevToolPlugin({ filename: null, // if no value is provided the sourcemap is inlined test: /\.(ts|js)($|\?)/i // process .js and .ts files only - }) + }), ] });