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

refactor container tagging. allow to set custom tags #25

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
packages: write
steps:
- name: Build and publish a container
uses: voxpupuli/gha-build-and-publish-a-container@v1
uses: voxpupuli/gha-build-and-publish-a-container@v2
with:
registry: docker.io # Default: ghcr.io
registry_username: foobar # Default: github.repository_owner
Expand All @@ -26,8 +26,13 @@ jobs:
build_context: 'puppetdb' # Default: .
buildfile: Dockerfile.something # Default: Dockerfile
publish: 'false' # Default: 'true'
docker_username: 'someone' # No default
docker_password: 'docker hub pass' # No default
docker_username: 'someone' # No default, can be empty
docker_password: 'docker hub pass' # No default, can be empty
tags: | # No default, can be empty
docker.io/${{ github.repository }}:3.2
docker.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:3.2
ghcr.io/${{ github.repository }}:latest
```

Test container build in ci:
Expand All @@ -41,22 +46,34 @@ jobs:
packages: read
steps:
- name: Test container build
uses: voxpupuli/gha-build-and-publish-a-container@v1
uses: voxpupuli/gha-build-and-publish-a-container@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish: 'false'
tags: ci/test:dummy
```

# Behavior

## Tagging

The `main`-branch will always be tagged with the `development` container-tag.
The git `main`-branch will automatically be tagged with the `development` container-tag, if no custom tags are supplied.
If one does a git-tag like `v1.0.0` this will translate into `1.0.0` container-tag.
The last git-tag also will be tagged with the `latest` container-tag.
If custom tags are supplied, this rules are not valid anymore.
The tags which are supplied will then be used. The tags have to be supplied in a newline seperated list.
The format is: `registry/user/repo:tag-name`.

## Push to hub.docker.com

If you specify a docker_username and a docker_password, the action will do a second registry login.
It will then automatically also log in to docker.io and on push the image gets published on your
primary registry and additionally to hub.docker.com.
It will then automatically also log in to docker.io. To push images to docker.io you have to add tags with the docker.io registry path in front.

f.e.:
```yaml
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ matrix.release }}
docker.io/${{ github.repository }}:${{ github.ref_name }}-${{ matrix.release }}
ghcr.io/${{ github.repository }}:latest
docker.io/${{ github.repository }}:latest
```
6 changes: 4 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ inputs:
description: The username to use for the docker registry.
docker_password:
description: The password to use for the docker registry.
tags:
description: The tags to use for the container. This is a string of tags seperated by a newline.

runs:
using: "composite"
Expand Down Expand Up @@ -62,7 +64,7 @@ runs:

- name: Get the tags
shell: bash
if: ${{ inputs.publish == 'true' }}
if: ${{ inputs.publish == 'true' && inputs.tags == '' }}
run: ${{ github.action_path }}/get_the_tags.py --repo "${{ github.repository }}" --ref "${{ github.ref_name }}" --log DEBUG
id: tags

Expand All @@ -75,6 +77,6 @@ runs:
platforms: ${{ inputs.build_arch }}
push: ${{ inputs.publish == 'true' }}
# if publish is false, tag as test, otherwise use the tags from the previous step
tags: ${{ inputs.publish == 'true' && steps.tags.outputs.tags || 'ci/test:dummy' }}
tags: ${{ inputs.publish == 'true' && steps.tags.outputs.tags || inputs.tags }}
file: ${{ inputs.buildfile }}
build-args: ${{ inputs.build_args }}