Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more reliable dev version tagging #1424

Merged
merged 6 commits into from
Nov 13, 2024

Conversation

robbkidd
Copy link
Member

@robbkidd robbkidd commented Nov 12, 2024

Which problem is this PR solving?

  • Image builds in Circle were still using the job ID as the version.

Short description of the changes

  • Reliably set the version regardless of where the image build is being run.
  • Moves the image tagging logic to below the version-determination logic. Now the dev-build tagging can reuse the determined dev version instead of using the CircleCI build ID.
  • Sets some defaults for environment variables to appease the nounset shell rule when this script is run outside of CI.

Example Outputs

Dev build in Dev

❯ ./build-docker.sh
++ git describe --tags '--match=v[0-9]*' --always
+ VERSION=2.8.2-58-g264d4af
… 
+ GOFLAGS=-ldflags=-X=main.BuildID=2.8.2-58-g264d4af
… 
+ ./ko publish --tags 2.8.2-55-gcc8c2a2 …
… 
2024/11/12 13:58:26 Adding tag 2.8.2-55-gcc8c2a2
… 

Dev build off branch in CI

#!/bin/bash -eo pipefail
./build-docker.sh
…
+ GOFLAGS=-ldflags=-X=main.BuildID=2.8.2-58-g264d4af-ci13888
…
2024/11/12 18:34:40 Adding tag 2.8.2-58-g264d4af-ci13888
2024/11/12 18:34:40 Adding tag branch-robb.use-new-dev-version-as-tag-for-dev-builds
… 

Dev build off branch in simulated CI

❯ CIRCLE_BUILD_NUM=8675309 CIRCLE_BRANCH=$(git rev-parse --abbrev-ref HEAD) ./build-docker.sh
++ git describe --tags '--match=v[0-9]*' --always
+ VERSION=v2.8.2-55-gcc8c2a2
… 
+ GOFLAGS=-ldflags=-X=main.BuildID=2.8.2-58-g264d4af-ci8675309
… 
+ ./ko publish --tags 2.8.2-55-gcc8c2a2-ci8675309,branch-robb.use-new-dev-version-as-tag-for-dev-builds 
… 
2024/11/12 14:02:32 Adding tag 2.8.2-55-gcc8c2a2-ci8675309
2024/11/12 14:02:32 Adding tag branch-robb.use-new-dev-version-as-tag-for-dev-builds
… 

Dev build off main in simulated CI

❯ CIRCLE_BUILD_NUM=8675309 CIRCLE_BRANCH=main ./build-docker.sh
… 
+ GOFLAGS=-ldflags=-X=main.BuildID=2.8.2-58-g264d4af-ci8675309
… 
2024/11/12 14:13:54 Adding tag 2.8.2-55-gcc8c2a2-ci8675309
2024/11/12 14:13:54 Adding tag branch-main
2024/11/12 14:13:54 Adding tag latest
… 

Tagged release build off main in simulated CI

❯ CIRCLE_BUILD_NUM=8675309 CIRCLE_BRANCH=main CIRCLE_TAG=v999.99.9 ./build-docker.sh
…
+ GOFLAGS=-ldflags=-X=main.BuildID=999.99.9
… 
2024/11/12 14:16:32 Adding tag 999
2024/11/12 14:16:32 Adding tag 999.99
2024/11/12 14:16:32 Adding tag 999.99.9
2024/11/12 14:16:32 Adding tag latest
…

This moves the image tagging logic to below the version-determination
logic. Now the dev-build tagging can reuse the determined dev version
instead of using the CircleCI build ID.
CIRCLE_BRANCH can default to nothing if not set.

If CIRCLE_SHA1 is not set, we can use git to get the current commit ID.
This helps when someone wants to run the script outside of CI.
Regardless of whether the image build is occurring in CI, set a version
tag on the image.
@robbkidd robbkidd requested a review from a team as a code owner November 12, 2024 18:33
Copy link
Contributor

@kentquirk kentquirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks plausible, although I haven't run it.

Copy link
Member Author

@kentquirk I should definitely add some sample run outputs to the PR description!

@robbkidd
Copy link
Member Author

I notice the dev builds (current logic on main and the new logic currently in this PR) have a v prefix for the in-app main.BuildID and the release builds do not. I should probably make that consistent.

@MikeGoldsmith MikeGoldsmith merged commit 9f2924c into main Nov 13, 2024
6 checks passed
@MikeGoldsmith MikeGoldsmith deleted the robb.use-new-dev-version-as-tag-for-dev-builds branch November 13, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants