From 12e7761c1f72893e5d505974b653b967c448857d Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Sun, 5 Nov 2017 18:41:00 -0800 Subject: [PATCH] Use Circle CI for faster builds. (#181) Move to Circle CI from Travis CI. --- .circleci/config.yml | 44 +++++++++++++++++++++++++++++++++++++ .travis.yml | 4 +--- .travis/deploy.sh | 17 ++++++++++++++ .travis/deploy_dockerhub.sh | 6 ++--- build.sh | 25 +++++++++++---------- setup_env.sh | 38 ++++++++++++++++++++++++++++++++ tests/generate_tests.sh | 14 ++++-------- 7 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .travis/deploy.sh create mode 100644 setup_env.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..3bf31b0 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,44 @@ +version: '2' + + +jobs: + build: + docker: + - image: circleci/python:3 + steps: + - checkout + - setup_remote_docker + - run: + name: Setup Environment + command: source setup_env.sh + - run: + name: Install Docker Compose + command: sudo pip install docker-compose + + - run: + name: Building Container Images + command: ./build.sh + + - run: + name: Generate Tests + command: bash tests/generate_tests.sh + + - run: + environment: + DB: postgres + name: Postgres Tests + command: bash tests/test.sh + + - run: + environment: + DB: mysql + name: MySQL Test + command: bash tests/test.sh + + - deploy: + environment: + REGISTRY: QUAY + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + bash .travis/deploy.sh + fi diff --git a/.travis.yml b/.travis.yml index 8f345b9..f3e0cda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: install: - docker --version && python --version - sudo pip install docker-compose + - source setup_env.sh - ./build.sh - docker-compose --version @@ -22,8 +23,5 @@ before_script: script: - sh tests/test.sh -after_success: - - sh .travis/deploy_dockerhub.sh - after_script: - docker-compose down diff --git a/.travis/deploy.sh b/.travis/deploy.sh new file mode 100644 index 0000000..bd89d78 --- /dev/null +++ b/.travis/deploy.sh @@ -0,0 +1,17 @@ +#! /bin/bash + +deploy() { + REG_URL=${REGISTRY}_URL + REG_USER=${REGISTRY}_USER + REG_PASS=${REGISTRY}_PASS + docker login -u ${!REG_USER} -p ${!REG_PASS} ${!REG_URL} + docker push ${!REG_URL}/maxking/mailman-web:$1 + docker push ${!REG_URL}/maxking/mailman-core:$1 +} + +if [ ! "$BRANCH" = "master" ] && [ "$PULL_REQUEST" ]; then + echo "Deploy only from master branch. This is $TRAVIS_BRANCH" + exit 0 +fi + +deploy diff --git a/.travis/deploy_dockerhub.sh b/.travis/deploy_dockerhub.sh index 9d1f47d..9c73f09 100644 --- a/.travis/deploy_dockerhub.sh +++ b/.travis/deploy_dockerhub.sh @@ -7,12 +7,12 @@ deploy () { } -if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then +if [ "$EVENT_TYPE" = "cron" ]; then deploy "rolling" -elif [ "$TRAVIS_BRANCH" = "master" ]; then +elif [ "$BRANCH" = "master" ]; then deploy "latest" else # If the branch isn't master and this was not a cron job, no need to deploy. - echo "TRAVIS_EVENT_TYPE = $TRAVIS_EVENT_TYPE, TRAVIS_BRANCH = $TRAVIS_BRANCH" + echo "EVENT_TYPE = $EVENT_TYPE, BRANCH = $BRANCH" exit 0 fi diff --git a/build.sh b/build.sh index f31a4da..707c644 100755 --- a/build.sh +++ b/build.sh @@ -9,8 +9,9 @@ if [ "$1" = "dev" ]; then export DEV=true fi +REG_URL=${REGISTRY}_URL -if [ "$TRAVIS_EVENT_TYPE" = "cron" ] || [ "$DEV" = "true" ] ; then +if [ "$EVENT_TYPE" = "cron" ] || [ "$DEV" = "true" ] ; then python -m pip install python-gitlab # Get the latest commit for repositories and set their reference values to be # used in the development builds. @@ -25,23 +26,25 @@ if [ "$TRAVIS_EVENT_TYPE" = "cron" ] || [ "$DEV" = "true" ] ; then $DOCKER build -f core/Dockerfile.dev \ --build-arg CORE_REF=$CORE_REF \ --build-arg MM3_HK_REF=$MM3_HK_REF \ - -t maxking/mailman-core:rolling core/ + --label version.core="$CORE_REF" \ + --label version.mm3-hk="$MM3_HK_REF" \ + --label version.git_commit="$COMMIT_ID" \ + -t ${!REG_URL}/maxking/mailman-core:rolling core/ # Build the mailman-web image. $DOCKER build -f web/Dockerfile.dev \ + --label version.git_commit="$COMMIT_ID" \ + --label version.postorius="$POSTORIUS_REF" \ + --label version.hyperkitty="$HYPERKITTY_REF" \ + --label version.client="$CLIENT_REF" \ + --label version.dj-mm3="$DJ_MM3_REF" \ --build-arg POSTORIUS_REF=$POSTORIUS_REF \ --build-arg CLIENT_REF=$CLIENT_REF \ --build-arg HYPERKITTY_REF=$HYPERKITTY_REF \ --build-arg DJ_MM3_REF=$DJ_MM3_REF \ - -t maxking/mailman-web:rolling web/ + -t ${!REG_URL}/maxking/mailman-web:rolling web/ else # Do the normal building process. - if [ "$TRAVIS_BRANCH" = "master" ]; then - TAG="latest" - else - TAG="$TRAVIS_BRANCH" - fi - - $DOCKER build -t maxking/mailman-core:$TAG core/ - $DOCKER build -t maxking/mailman-web:$TAG web/ + $DOCKER build -t ${!REG_URL}/maxking/mailman-core:$TAG core/ + $DOCKER build -t ${!REG_URL}/maxking/mailman-web:$TAG web/ fi diff --git a/setup_env.sh b/setup_env.sh new file mode 100644 index 0000000..633b0e3 --- /dev/null +++ b/setup_env.sh @@ -0,0 +1,38 @@ +# Script to setup environment variables. + +set -ex + +set_var () { + echo $1=$2 >> $BASH_ENV + export $1=$2 +} + +setup_env () { + CI_NAME=$1 + # Set the current branch name. + BRANCH_NAME=${CI_NAME}_BRANCH + set_var BRANCH ${!BRANCH_NAME} +} + + +if [ "$TRAVIS" ]; then + # Set environments picked up from Circle CI. + set_var EVENT_TYPE "$TRAVIS_EVENT_TYPE" + set_var COMMIT_ID $TRAVIS_COMMIT + # Setup some generic environment vars. + setup_env TRAVIS +elif [ "$CIRCLECI" ]; then + # Set environments picked up from Circle CI. + set_var EVENT_TYPE "push" + set_var COMMIT_ID $CIRCLE_SHA1 + # Setup some generic environment vars. + setup_env CIRCLE +fi + +if [ "$BRANCH" = "master" ]; then + set_var TAG "latest" +else + set_var TAG "$BRANCH" +fi + +set_var REG_URL ${REGISTRY}_URL diff --git a/tests/generate_tests.sh b/tests/generate_tests.sh index 25284e6..9d322e0 100644 --- a/tests/generate_tests.sh +++ b/tests/generate_tests.sh @@ -1,16 +1,10 @@ #!/bin/sh -if [ "$TRAVIS_EVENT_TYPE" = "cron" ] || [ ! -z $DEV ] ; then - echo "Travis event type is: $TRAVIS_EVENT_TYPE" +if [ "$EVENT_TYPE" = "cron" ] || [ ! -z $DEV ] ; then + echo "Event type is: $EVENT_TYPE" echo "This is a development version build: $DEV" TAG="rolling" -else - if [ "$TRAVIS_BRANCH" = "master" ]; then - TAG="latest" - else - TAG="$TRAVIS_BRANCH" - fi fi @@ -19,10 +13,10 @@ version: '2' services: mailman-core: - image: maxking/mailman-core:$TAG + image: ${!REG_URL}/maxking/mailman-core:$TAG mailman-web: - image: maxking/mailman-web:$TAG + image: ${!REG_URL}/maxking/mailman-web:$TAG environment: - SECRET_KEY=abcdefghijklmnopqrstuv EOF