diff --git a/.circleci/config.yml b/.circleci/config.yml index f91812c45..bd95f2c8a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,9 +1,21 @@ -version: 2 +version: 2.1 + +workflows: + build-and-deploy: + jobs: + - build + - push: + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ jobs: build: working_directory: /go/src/go.mozilla.org/sops docker: - image: circleci/golang:1.13 + resource_class: large steps: - checkout - setup_remote_docker @@ -12,10 +24,65 @@ jobs: command: | docker build -t mozilla/sops . docker tag mozilla/sops "mozilla/sops:$CIRCLE_SHA1" + + push: + machine: true + resource_class: large + steps: + - checkout + - run: + name: semver check + command: | + MAJOR=$(echo ${CIRCLE_TAG#v} | cut -d"." -f1) + MINOR=$(echo ${CIRCLE_TAG#v} | cut -d"." -f2) + PATCH=$(echo ${CIRCLE_TAG#v} | cut -d"." -f3) + echo "export MAJOR=${MAJOR}" >> $BASH_ENV + echo "export MINOR=${MINOR}" >> $BASH_ENV + echo "export PATCH=${PATCH}" >> $BASH_ENV + + if [ -z $MAJOR ];then + cat \<< EOF + Failure Info: + + This job uses the semver from the git TAG as the public version to publish. + + - This should only run on workflows triggered by a tag. + - The tag name should be a semver like 'v1.2.3' + - The version should follow conventions documented at https://github.com/fsaintjacques/semver-tool + EOF + exit 1 + fi + - run: + name: Build containers + command: | + docker build -t mozilla/sops . - run: - name: Push containers + name: Tag & Push containers command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - ${GOPATH}/src/go.mozilla.org/sops/bin/ci/deploy_dockerhub.sh "latest" - ${GOPATH}/src/go.mozilla.org/sops/bin/ci/deploy_dockerhub.sh "$CIRCLE_SHA1" + #latest + bin/ci/deploy_dockerhub.sh "latest" + + # by sha + echo "Tag and push mozilla/sops:$CIRCLE_SHA1" + docker tag mozilla/sops "mozilla/sops:$CIRCLE_SHA1" + bin/ci/deploy_dockerhub.sh "$CIRCLE_SHA1" + + # by semver + # v1.2.3 + if [ ! -z $PATCH ];then + echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR.$PATCH" + docker tag mozilla/sops "mozilla/sops:v$MAJOR.$MINOR.$PATCH" + bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR.$PATCH" + fi + # v1.2 + if [ ! -z $MINOR ];then + echo "Tag and Push mozilla/sops:v$MAJOR.$MINOR" + docker tag mozilla/sops "mozilla/sops:v$MAJOR.$MINOR" + bin/ci/deploy_dockerhub.sh "v$MAJOR.$MINOR" fi + # v1 + echo "Tag and Push mozilla/sops:v$MAJOR" + docker tag mozilla/sops "mozilla/sops:v$MAJOR" + bin/ci/deploy_dockerhub.sh "v$MAJOR" + +