I’m using CircleCI to build Docker images. I’m confused about how to do tag based deployments with 2.0.
I was using CircleCI 1.0 in such a way that only a semver tag (like 1.0.6
) was triggering a build. I’ve migrated the build to 2.0, however I don’t know how can I achieve the same tag based behaviour.
I’d like to:
- Only run the build command if a semver tag
/[0-9]+(\.[0-9]+)*/
has been pushed to the master branch. - When a semver tag has been pushed, I need access to the current tag, like how I could simply use
$CIRCLE_TAG
in 1.0.
Here is my old config:
machine:
services:
- docker
environment:
image_user: hyperknot
image_repo: baseimage16
image_root: image
general:
branches:
only:
- skip
dependencies:
override:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- "docker build --rm=false -t $image_user/$image_repo:build_cache .":
pwd: $image_root
test:
override:
- exit 0
deployment:
hub:
tag: /[0-9]+(\.[0-9]+)*/
commands:
- pip install -U docker-squash 'docker < 3' --disable-pip-version-check
- docker-squash -t $image_user/$image_repo:$CIRCLE_TAG $image_user/$image_repo:build_cache
- docker images
- docker push $image_user/$image_repo:$CIRCLE_TAG
and new config:
version: 2
jobs:
build:
environment:
image_user: hyperknot
image_repo: baseimage16
docker:
- image: circleci/python:3.7
steps:
- checkout
- setup_remote_docker
- run: env
- run: docker version
- run:
command: docker build -t $image_user/$image_repo:build_cache .
working_directory: image
- run: sudo pip install docker-squash --disable-pip-version-check
- run: docker-squash -t $image_user/$image_repo:$CIRCLE_TAG $image_user/$image_repo:build_cache
- run: docker images
- run: docker push $image_user/$image_repo:$CIRCLE_TAG
What do I need to add to the config? How can I access a $CIRCLE_TAG
like variable in 2.0?