From e5cb89c6a3b7799bb8d593c0d9ee0c3fbc8f5003 Mon Sep 17 00:00:00 2001 From: Julien Vehent Date: Thu, 12 Oct 2017 16:47:26 -0400 Subject: [PATCH] add circleci config to build docker containers --- .circleci/config.yml | 25 +++++++++++++++++++++++++ bin/ci/deploy_dockerhub.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 bin/ci/deploy_dockerhub.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..18ed44d4e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,25 @@ +version: 2 +jobs: + build: + working_directory: /go/src/github.com/mozilla/sops + docker: + - image: circleci/golang:1.8 + steps: + - checkout + - run: + name: Build Sops + command: make + - setup_remote_docker + - run: + name: Build containers + command: | + docker build -t mozilla/sops . + docker tag mozilla/sops "mozilla/sops:$CIRCLE_SHA1" + - run: + name: Push containers + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + ./bin/ci/deploy_dockerhub.sh "latest" + ./bin/ci/deploy_dockerhub.sh "$CIRCLE_SHA1" + fi + diff --git a/bin/ci/deploy_dockerhub.sh b/bin/ci/deploy_dockerhub.sh new file mode 100644 index 000000000..89a7dc310 --- /dev/null +++ b/bin/ci/deploy_dockerhub.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# THIS IS MEANT TO BE RUN BY CI + +set -e +set +x + +# Usage: retry MAX CMD... +# Retry CMD up to MAX times. If it fails MAX times, returns failure. +# Example: retry 3 docker push "mozilla/sops:$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 + retry 3 docker push "mozilla/sops:$1" || + (echo "Couldn't push mozilla/sops:$1" && false) + echo "Pushed mozilla/sops:$1" + fi +fi