Merge pull request #57 from milescrabill/minimal-circle-config

convert to minimal circle config
This commit is contained in:
Miles Crabill 2018-05-17 16:41:27 -07:00 коммит произвёл GitHub
Родитель f1cfb6f39b b01938b481
Коммит 6b9fc082fe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 17 добавлений и 71 удалений

Просмотреть файл

@ -1,16 +1,13 @@
version: 2
jobs:
build:
machine: true
working_directory: ~/speaktome
build_and_push:
docker:
- image: docker:stable
environment:
APP_NAME: "speaktome"
steps:
- run:
name: Install essential packages
command: |
sudo apt-get update
sudo apt-get install -y ca-certificates curl build-essential make git
- checkout
- setup_remote_docker
- run:
name: Create version.json
@ -18,43 +15,29 @@ jobs:
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
"$CIRCLE_SHA1" \
"`git describe`" \
"$CIRCLE_TAG" \
"$CIRCLE_PROJECT_USERNAME" \
"$CIRCLE_PROJECT_REPONAME" \
"$CIRCLE_BUILD_URL" > version.json
- store_artifacts:
path: version.json
- run:
name: Build Docker image
command: |
docker info
make build
docker build -t ${APP_NAME}:build .
- run:
name: Run the app
command: make run
background: true
- run:
name: Run tests
command: echo "sleep 5 && make test"
- deploy:
name: Push to Dockerhub
command: |
# set DOCKER_DEPLOY=true in Circle UI to push to Dockerhub
export DOCKER_DEPLOY="${DOCKER_DEPLOY:-false}"
if [ "${CIRCLE_BRANCH}" == "master" ]; then
bin/ci/deploy-dockerhub.sh latest
echo "${DOCKER_PASSWORD}" | docker login -u="${DOCKER_USERNAME}" --password-stdin
export DOCKER_IMAGE="mozilla/${APP_NAME}:latest"
if [ -n "${CIRCLE_TAG}" ]; then
export DOCKER_IMAGE="mozilla/${APP_NAME}:${CIRCLE_TAG}"
fi
# $CIRCLE_TAG doesn't exist anymore
set +e
git describe --exact-match
if [ $? == 0 ]; then
bin/ci/deploy-dockerhub.sh "`git describe`"
if [ "${CIRCLE_BRANCH}" == "master" ]; then
docker tag "${APP_NAME}:build" "${DOCKER_IMAGE}"
docker push "${DOCKER_IMAGE}"
fi
workflows:
@ -68,9 +51,9 @@ workflows:
# see: https://circleci.com/docs/2.0/workflows/#git-tag-job-execution
build-test-push:
build_and_push:
jobs:
- build:
- build_and_push:
filters:
tags:
only: /.*/

Просмотреть файл

@ -1,37 +0,0 @@
#!/bin/bash
# THIS IS MEANT TO BE RUN BY CI
set -e
# Usage: retry MAX CMD...
# Retry CMD up to MAX times. If it fails MAX times, returns failure.
# Example: retry 3 docker push "mozilla/speaktome:$TAG"
function retry() {
max=$1
shift
count=1
until "$@"; do
count=$((count + 1))
if [[ $count -gt $max ]]; then
return 1
fi
echo "$count / $max"
done
return 0
}
if [[ "$DOCKER_DEPLOY" == "true" ]]; then
# configure docker creds
retry 3 docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
# docker tag and push git branch to dockerhub
if [ -n "$1" ]; then
[ "$1" == master ] && TAG=latest || TAG="$1"
docker tag speech-proxy:build "mozilla/speaktome:$TAG" ||
(echo "Couldn't tag speech-proxy:build as mozilla/speaktome:$TAG" && false)
retry 3 docker push "mozilla/speaktome:$TAG" ||
(echo "Couldn't push mozilla/speaktome:$TAG" && false)
echo "Pushed mozilla/speaktome:$TAG"
fi
fi