Use Circle CI for faster builds. (#181)

Move to Circle CI from Travis CI.
This commit is contained in:
Abhilash Raj
2017-11-05 18:41:00 -08:00
committed by GitHub
parent 389d166f2b
commit 12e7761c1f
7 changed files with 121 additions and 27 deletions

44
.circleci/config.yml Normal file
View File

@@ -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

View File

@@ -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

17
.travis/deploy.sh Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

38
setup_env.sh Normal file
View File

@@ -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

View File

@@ -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