From 2d189d5378068dadc6ee3891050f44b1bf624763 Mon Sep 17 00:00:00 2001 From: Blake Imsland Date: Wed, 19 Apr 2017 10:23:14 -0700 Subject: [PATCH] Update Circle CI for our workflow - Use new master / rc release release strategy (#440) - Migrate Circle CI 2.0 (#488, #502) --- .circleci/config.yml | 134 +++++++++++++++++++++++++++++++++++++++++++ bin/alias | 12 ++++ bin/deploy | 19 ++++++ circle.yml | 38 ------------ 4 files changed, 165 insertions(+), 38 deletions(-) create mode 100644 .circleci/config.yml create mode 100755 bin/alias create mode 100755 bin/deploy delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000000..0e5f20bd78 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,134 @@ +# These environment variables must be set in CircleCI UI +# +# DOCKERHUB_REPO - docker hub repo, format: / +# DOCKER_USER +# DOCKER_PASS +# + +version: 2 +jobs: + build: + docker: + - image: docker:18.02.0-ce + working_directory: ~/mozilla/redash + steps: + - checkout + - setup_remote_docker + - run: + command: docker build -t app:build . + no_output_timeout: 20m + + test: + docker: + - image: circleci/node:6.14.3-stretch + - image: redis + - image: circleci/postgres:10-alpine-postgis + working_directory: ~/mozilla/redash + steps: + - checkout + - run: mkdir -p /tmp/test-reports/pytest + - run: sudo apt-get update + - run: sudo apt-get install -y python-pip python-dev + - run: sudo apt-get install -y redis-tools redis-server + - run: sudo pip install --upgrade setuptools + - run: sudo pip install -r requirements_dev.txt + - run: sudo pip install -r requirements.txt + - run: sudo npm install + - run: sudo npm run build + - run: + command: pytest --junitxml=/tmp/test-reports/pytest/junit.xml tests/ + environment: + REDASH_REDIS_URL: redis://localhost:6379/0 + REDASH_DATABASE_URL: "postgresql://postgres@localhost/postgres" + - store_artifacts: + path: /tmp/test-reports/ + destination: tr1 + - store_test_results: + path: /tmp/test-reports/ + + deploy-master: + machine: + enable: true + working_directory: ~/mozilla/redash + steps: + - checkout + - run: + name: Deploy to Dockerhub + no_output_timeout: 20m + command: | + ./bin/deploy "master" + + deploy-rc: + machine: + enable: true + working_directory: ~/mozilla/redash + steps: + - checkout + - run: + name: Deploy to Dockerhub + no_output_timeout: 20m + command: | + ./bin/deploy "rc" + + deploy-milestone: + machine: + enable: true + working_directory: ~/mozilla/redash + steps: + - checkout + - run: + name: Deploy milestone to Dockerhub + no_output_timeout: 20m + command: | + ./bin/deploy "$CIRCLE_TAG" + ./bin/alias "$CIRCLE_TAG" "latest" + + +workflows: + version: 2 + build-test-deploy: + jobs: + - build: + filters: + tags: + only: /.*/ + branches: + ignore: + - gh-pages + + - test: + filters: + tags: + only: /.*/ + branches: + ignore: + - gh-pages + + - deploy-master: + requires: + - test + filters: + tags: + only: /.*/ + branches: + only: + - master + + - deploy-rc: + requires: + - test + filters: + tags: + only: /.*/ + branches: + only: + - release + + - deploy-milestone: + requires: + - test + filters: + tags: + only: /^m[0-9]+(\.[0-9]+)?$/ + branches: + ignore: /.*/ diff --git a/bin/alias b/bin/alias new file mode 100755 index 0000000000..1d4a32a19b --- /dev/null +++ b/bin/alias @@ -0,0 +1,12 @@ +#!/bin/bash + +set -eo pipefail + +[ ! -z $DOCKERHUB_REPO ] && [ $# -eq 2 ] + +VERSION="$1" +ALIAS="$2" + +docker login -u $DOCKER_USER -p $DOCKER_PASS +docker tag $DOCKERHUB_REPO:$VERSION $DOCKERHUB_REPO:$ALIAS +docker push $DOCKERHUB_REPO:$ALIAS diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 0000000000..2bdb54ed4d --- /dev/null +++ b/bin/deploy @@ -0,0 +1,19 @@ +#!/bin/bash + +set -eo pipefail + +[ ! -z $DOCKERHUB_REPO ] && [ $# -eq 1 ] + +VERSION="$1" + +printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ + "$CIRCLE_SHA1" \ + "$VERSION" \ + "$CIRCLE_PROJECT_USERNAME" \ + "$CIRCLE_PROJECT_REPONAME" \ + "$CIRCLE_BUILD_URL" \ +> version.json + +docker login -u $DOCKER_USER -p $DOCKER_PASS +docker build -t $DOCKERHUB_REPO:$VERSION . +docker push $DOCKERHUB_REPO:$VERSION diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 28f5f48c6c..0000000000 --- a/circle.yml +++ /dev/null @@ -1,38 +0,0 @@ -machine: - services: - - docker - - redis - node: - version: - 6.9.1 -dependencies: - override: - - pip install --upgrade setuptools - - pip install -r requirements_dev.txt - - pip install -r requirements.txt - - npm install - - npm run build - cache_directories: - - node_modules/ -test: - override: - - pytest --junitxml=$CIRCLE_TEST_REPORTS/junit.xml tests/ -deployment: - tarball: - branch: [master, /release.*/] - commands: - - bin/pack - docker: - tag: /v[0-9]+(\.[0-9\-a-z]+)*/ - commands: - - bin/pack - - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS - - docker build -t redash/redash:$(./manage.py version | sed -e "s/\+/./") . - - docker push redash/redash:$(./manage.py version | sed -e "s/\+/./") -notify: - webhooks: - - url: https://webhooks.gitter.im/e/895d09c3165a0913ac2f -general: - branches: - ignore: - - gh-pages