question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build tagged images on git tags

See original GitHub issue

Currently our workflow looks like this:

release-image:
  stage: deploy
  script:
    - docker build -t "$CONTAINER_RELEASE_IMAGE"
      --build-arg DJANGO_ENV=production -f docker/django/Dockerfile .
    - docker push "$CONTAINER_RELEASE_IMAGE"
  only:
    - master
  environment:
    name: production  # used to track time with 'cycle analytics'

Where CONTAINER_RELEASE_IMAGE equals to "$REGISTRY/$GROUP_NAME/$PROJECT_NAME:latest".

But, that an anti-pattern. Because we always use latest for version numbers. There’s no default way to build versioned images like: "$REGISTRY/$GROUP_NAME/$PROJECT_NAME:3.5".

And I suggest to fix it with git tag. I already use it in our workflow, we just need to set appropriate tag names when new tag is pushed. We can use CI_COMMIT_TAG with a simple condition. https://docs.gitlab.com/ee/ci/variables/

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sobolevncommented, Nov 21, 2018

This might help to integrate several services together. There are usecases when other images require different image versions.

Like microservices, frontend/backed, etc. I will experiment with it soon enough.

1reaction
AlwxSincommented, Jan 14, 2019

I’d also suggest to use anchors like this

.release-image: &release-image
  stage: deploy
    script:
    - docker build -t "$CONTAINER_RELEASE_IMAGE:$TAG_NAME"
      --build-arg DJANGO_ENV=production -f docker/django/Dockerfile .
    - docker push "$CONTAINER_RELEASE_IMAGE:$TAG_NAME"
  environment:
    name: production  # used to track time with 'cycle analytics'


# Releasing image, when tests pass (only one at a time):
release-latest-image:
  <<: *release-image
  variables:
    TAG_NAME: latest
  only:
    - master
    
release-tagged-image:
  <<: *release-image
  variables:
    TAG_NAME: $CI_COMMIT_TAG
  only:
    - tags
Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Docker images for git tags (releases) on CI #70 - GitHub
On every new git tag, we should build a Docker image with tag matching git tag without leading v , and also tag...
Read more >
Git - Tagging - Git SCM
In this section, you'll learn how to list existing tags, how to create and delete tags, and what the different types of tags...
Read more >
Add a tag to a Docker image if there's a git tag using GitHub ...
The first step generates the list of tags and the second build/push. if $GITHUB_REF starts by refs/tags/ it is a tag and as...
Read more >
How do you tag docker images? - Andy Dote
An interesting question came up at work today: how do you tag your Docker images? In previous projects, I've always used a short...
Read more >
Github Tags - Tools QA
Tags are much more than tagging the commits as we did in Git. ... Now the image of the repository you see is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found