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

Add date-based docker image tag #71

Merged
merged 1 commit into from
Apr 23, 2024
Merged

Add date-based docker image tag #71

merged 1 commit into from
Apr 23, 2024

Conversation

hbruch
Copy link
Collaborator

@hbruch hbruch commented Apr 23, 2024

This PR introduces date-based image tags (Y-%m-%dT%H-%M) for docker images built on the main branch.

@hbruch hbruch requested a review from derhuerst April 23, 2024 13:14
Copy link
Member

@derhuerst derhuerst left a comment

Choose a reason for hiding this comment

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

The changes look good, but I have some minor remarks.

Instead of the modifying the environment, you could also use GitHub's output feature if you want, which is a bit more verbose:

    - name: determine date-time-based tag
      id: docker-img-tag
      run: |
        echo "::set-output name=tag::$(date +%Y-%m-%dT%H-%M)"
          tags: |
            ghcr.io/${{github.repository}}:latest
            ghcr.io/${{github.repository}}:${{steps.docker-img-tag.outputs.tag}}

@@ -27,12 +27,17 @@ jobs:
username: ${{ github.actor }}
password: ${{ github.token }}

- name: set date-based tag
run: |
echo "DATE_TAG=$(date +%Y-%m-%dT%H-%M)" >> $GITHUB_ENV
Copy link
Member

Choose a reason for hiding this comment

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

Given that the tag contains hours and minutes, let's call the variable DATE_TIME_TAG.

Although I couldn't provoke a collision with Bash-builtin syntax, I'd say it's better to be on the safe side and put the format string into single quotes.

Suggested change
echo "DATE_TAG=$(date +%Y-%m-%dT%H-%M)" >> $GITHUB_ENV
echo "DATE_TIME_TAG=$(date '+%Y-%m-%dT%H-%M')" >> $GITHUB_ENV

- name: build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ env.DATE_TAG }}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ghcr.io/${{ github.repository }}:${{ env.DATE_TAG }}
ghcr.io/${{ github.repository }}:${{ env.DATE_TIME_TAG }}

@hbruch hbruch merged commit 12d16d9 into main Apr 23, 2024
2 checks passed
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.

2 participants