From b4a5edb4c19917323caf9bcfd69a1ff57999f1e2 Mon Sep 17 00:00:00 2001 From: John Schnake Date: Wed, 9 Oct 2019 11:57:02 -0500 Subject: [PATCH] Move image pushing into CircleCI - Moves/updates the travis deploy script to work on circleCI. - Added DOCKERHUB_TOKEN via web UI to circleCI - runs publishing of images on master branch and on tags like v.* - minor change to naming to clarify job purposes Ref: #926 Signed-off-by: John Schnake --- .circleci/config.yml | 22 ++++++++++++++++++---- scripts/ci/publish.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 scripts/ci/publish.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e03347e1b..5906c4acb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,10 +18,16 @@ jobs: name: "Check README in sync" command: ./scripts/ci/check_readme_in_sync.sh - build: + build_and_publish: + machine: + enabled: true + steps: + - checkout + - run: ./scripts/publish.sh + + build_and_test: machine: enabled: true - docker_layer_caching: true steps: - checkout - run: @@ -61,8 +67,16 @@ jobs: workflows: version: 2 - build_and_test: + checks: jobs: - check_go_mod - check_readme_sync - - build + - build_and_test + - build_and_publish: + requires: + - build_and_test + filters: + branches: + only: master + tags: + only: /^v.*/ \ No newline at end of file diff --git a/scripts/ci/publish.sh b/scripts/ci/publish.sh new file mode 100644 index 000000000..b09485324 --- /dev/null +++ b/scripts/ci/publish.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Don't fail silently when a step doesn't succeed +set -e + +if [ -z "$CIRCLECI" ]; then + echo "this script is intended to be run only on travis" >&2 + exit 1 +fi + +function goreleaser() { + curl -sL https://git.io/goreleaser | bash +} + +function image_push() { + echo ${DOCKERHUB_TOKEN} | docker login --username sonobuoybot --password-stdin + IMAGE_BRANCH="$CIRCLE_BRANCH" make container push +} + +if [ ! -z "$CIRCLE_TAG" ]; then + if [ "$(./sonobuoy version --short)" != "$CIRCLE_TAG" ]; then + echo "sonobuoy version does not match tagged version!" >&2 + echo "sonobuoy short version is $(./sonobuoy version --short)" >&2 + echo "tag is $CIRCLE_TAG" >&2 + echo "sonobuoy full version info is $(./sonobuoy version)" >&2 + exit 1 + fi + + goreleaser --skip-validate + image_push +fi + +if [ "$CIRCLE_BRANCH" == "master" ]; then + image_push +fi \ No newline at end of file