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

Quick: Update Makefile to support git branches #801

Merged
merged 4 commits into from
Feb 9, 2024

Conversation

rstijerina
Copy link
Member

Overview

This PR adds a new variable to the Makefile context: DOCKER_IMAGE_BRANCH

This variable will correspond to the git tag for the commit if it exists, else the branch name for the commit, with special characters replaced with -.

Copy link
Member

@wesleyboar wesleyboar left a comment

Choose a reason for hiding this comment

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

Questions

  1. How can I test this awesome?
  2. Is it already used on a another repo successfully?
  3. If so, does it's Jenkins build have code I can copy that will output the tag instead of the commit hash?

My thoughts on № 1 (testing):

  1. I tag the latest commit of this branch.
  2. I run a Jenkins build using the tag.
  3. I check DockerHub for image.
  4. I test deploy some guinea pig CMS.

Makefile Show resolved Hide resolved
@rstijerina
Copy link
Member Author

Questions

  1. How can I test this awesome?
  2. Is it already used on a another repo successfully?
  3. If so, does it's Jenkins build have code I can copy that will output the tag instead of the commit hash?

My thoughts on № 1 (testing):

  1. I tag the latest commit of this branch.
  2. I run a Jenkins build using the tag.
  3. I check DockerHub for image.
  4. I test deploy some guinea pig CMS.
  1. Yes, perfect testing steps.
  2. Yes, Core-Portal
  3. Jenkins build requires no edits. It will output both the tag and commit hash

Copy link
Member

@wesleyboar wesleyboar left a comment

Choose a reason for hiding this comment

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

Test success.

  1. Build.
  2. Deploy.
  3. Open.
  4. See git describe is v4.6.0-18-g783b7fbd.
  5. See …/site.css comment has v4.6.0-18-g783b7fbd.

Copy link
Member

Choose a reason for hiding this comment

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

@rstijerina, I must wait until the end of the build (which can be long) before I see docker tag output.1

How could I see that output sooner? So I could copy-paste to Core-Portal-Deployments during build.

+	echo "Building '`$(DOCKER_IMAGE_BRANCH)`'…"
	docker build -t $(DOCKER_IMAGE) \
-	docker build -t $(DOCKER_IMAGE) \
+	docker build -t $(DOCKER_IMAGE_BRANCH) \

Footnotes

  1. docker tag taccwma/core-cms:783b7fb taccwma/core-cms:test-update-makefile-support-branch-tags

Copy link
Member Author

Choose a reason for hiding this comment

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

@wesleyboar Good suggestion. We could add DOCKER_IMAGE_BRANCH=... and echo "Building '$(DOCKER_IMAGE_BRANCH)'…" to the Jenkins build as well

Copy link
Member

Choose a reason for hiding this comment

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

I dunno about putting same script snippet in Makefile and Jenkins. If after using this a while, I feel the urge, then I'll think on a shared code solution or give in to copy-paste.

Copy link
Collaborator

@taoteg taoteg Feb 9, 2024

Choose a reason for hiding this comment

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

In the jenkins build console output, you can see what the tag is going to be at the very top (before STEP 1 begins) in these lines (copied from your build job above - https://jenkins01.tacc.utexas.edu/job/Core_CMS_Build/1375/console):

Previous HEAD position was cadaf60... chore: v4.7.2 (#800)
HEAD is now at 783b7fb... rearrange vars

then a few lines later:

docker build -t taccwma/core-cms:783b7fb \
	--target production \
	--build-arg PROJECT_NAME="" \
	--build-arg BUILD_ID="v4.6.0-18-g783b7fb" \
	--build-arg NEEDS_DEMO="true" \
	-f ./Dockerfile .

which is the same things you will see in STEP 25:

Building "Core" styles:
Tagging CSS version as @tacc/core-cms v4.6.0-18-g783b7fb | MIT | github.com/TACC/Core-CMS

and reflects what you get at the end of the build pipe if it is successful:

Step 28/28 : COPY --from=node_build /code/ /code
 ---> 2bbb8033c87f
Successfully built 2bbb8033c87f
Successfully tagged taccwma/core-cms:783b7fb

Does that help?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this doesn't include the special char replacement done by the DOCKER_IMAGE_BRANCH var

Copy link
Collaborator

@taoteg taoteg Feb 9, 2024

Choose a reason for hiding this comment

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

Looks like this (in the beginning):

Fetching origin
+ git checkout test-update-makefile-support-branch-tags
Previous HEAD position was cadaf60... chore: v4.7.2 (#800)
HEAD is now at 783b7fb... rearrange vars
+ git describe --exact-match --tags HEAD
test-update-makefile-support-branch-tags

still matches this output (at the very end):

docker push taccwma/core-cms:test-update-makefile-support-branch-tags
The push refers to repository [docker.io/taccwma/core-cms]
...
test-update-makefile-support-branch-tags: digest: sha256:6f28e24b0d468bd71a8d5fb4da2beb0bdc19e0620c1c07992c8b8a91ed4ca52c size: 3691
+ '[' test-update-makefile-support-branch-tags == main ']'

Is that because Wes names things well and therefore there was no real conversion of special characters from the value in the .env file (CMS_TAG=test-update-makefile-support-branch-tags # v4.8.0 candidate)?

Copy link
Member Author

Choose a reason for hiding this comment

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

But if the branch was test/update-makefile-support-branch-tags, that would not match with it being converted to test-update-makefile-support-branch-tags by the DOCKER_IMAGE_BRANCH var

Is that because Wes names things well and therefore there was no real conversion of special characters from the value

yeah, exactly

Copy link
Member

@wesleyboar wesleyboar Feb 9, 2024

Choose a reason for hiding this comment

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

@taoteg was right to look at other lines. What I want (most of the time) is available reliably enough via:

+ git describe --exact-match --tags HEAD
v4.8.0

Not a branch name, but it matches when I build via tag.

When I next need to build by branch, I [may return to] this.

@wesleyboar wesleyboar merged commit 206d939 into main Feb 9, 2024
@wesleyboar wesleyboar deleted the quick/update-makefile-support-branch-tags branch February 9, 2024 17:34
Makefile Show resolved Hide resolved
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