Skip to content

Commit

Permalink
Merge pull request #607 from eddiewebb/circleci-tag
Browse files Browse the repository at this point in the history
Added version to docker tag #542
  • Loading branch information
ajvb committed Jan 23, 2020
2 parents df39dca + 19e44ab commit db9c552
Showing 1 changed file with 72 additions and 5 deletions.
77 changes: 72 additions & 5 deletions .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
Expand All @@ -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"

0 comments on commit db9c552

Please sign in to comment.