Skip to content

Commit e7e7451

Browse files
authored
Add extra_build_tag Input (#6)
1 parent 747deba commit e7e7451

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

.github/workflows/image-publish.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,22 @@ This GitHub Actions workflow builds and pushes Docker images to Docker Hub, GitH
3939

4040
#### Miscellaneous Build Configuration
4141

42-
| Name | Required | Description |
43-
|-----------------------|----------|--------------------------------------------------------------------------------------|
44-
| `free_disk_space` | no | `true` to make space on GitHub runner before building image |
45-
| `build_platforms_csv` | no | Target build platforms. Default: `linux/amd64,linux/arm64`<br>Example: `linux/arm64` |
42+
| Name | Required | Description |
43+
|-----------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
44+
| `free_disk_space` | no | `true` to make space on GitHub runner before building image |
45+
| `build_platforms_csv` | no | Target build platforms. Default: `linux/amd64,linux/arm64`<br>Example: `linux/arm64` |
46+
| `extra_build_tag` | no | Use this custom tag **in addition** to auto-generated tags.<br>Useful with `workflow_dispatch` to override static tags like `dev`, `test`, or `unstable`. Example: `${{ github.event_name == 'workflow_dispatch' && github.event.inputs.my_tag \|\| '' }}` |
4647

4748
## Secrets
4849

4950
Depending on the `mode`, secret(s) may be required:
5051

51-
#### If using DockerHub
52+
### Container Registry Authentication
5253

53-
| Name | Required | Description |
54-
|---------------------|-------------------------------|---------------------|
55-
| `registry_username` | ✅, if building for Docker Hub | Docker Hub username |
56-
| `registry_token` | ✅, if building for Docker Hub | Docker Hub token |
57-
58-
#### If using the GitHub Container Registry (ghcr.io)
59-
60-
| Name | Required | Description |
61-
|------------------|------------------------------|------------------------------------------------|
62-
| `registry_token` | ✅, if building for `ghcr.io` | GitHub token for authenticating with `ghcr.io` |
54+
| Name | Required | Description | Notes |
55+
|---------------------|-------------------------------------------------|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
56+
| `registry_username` | ✅, if registry requires authentication username | Username for the container registry. | Ignored for `ghcr.io` (uses `${{ github.actor }}`). |
57+
| `registry_token` | ✅, if registry requires authentication | Token/password for the container registry. | Not needed for `ghcr.io` (defaults to `${{ secrets.GITHUB_TOKEN }}`), unless publishing to a third-party repository. |
6358

6459
#### If interacting with CVMFS
6560

@@ -92,7 +87,7 @@ jobs:
9287
registry_token: ${{ secrets.DOCKERHUB_TOKEN }}
9388
```
9489
95-
Build for ghcr.io + CVMFS:
90+
Build for `ghcr.io` + CVMFS:
9691

9792
```yaml
9893
jobs:
@@ -108,7 +103,6 @@ jobs:
108103
mode: CVMFS_BUILD
109104
cvmfs_dest_dir: myorg
110105
secrets:
111-
registry_token: ${{ secrets.GITHUB_TOKEN }}
112106
cvmfs_github_token: ${{ secrets.CVMFS_PAT }}
113107
```
114108

.github/workflows/image-publish.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ on:
6060
required: false
6161
type: string
6262
default: "linux/amd64,linux/arm64"
63+
extra_build_tag:
64+
description: |
65+
IF BUILDING IMAGE (else, var is ignored):
66+
If provided, use this tag in addition to the normally automatically generated tags based on GHA trigger event.
67+
NOTE: this is useful in combination with a manual 'workflow_dispatch' to
68+
overwrite static tags, ex: 'dev', 'test', 'unstable', etc.
69+
EXAMPLE: '$ {{ github.event_name == 'workflow_dispatch' && github.event.inputs.my_tag || '' }}' (no space after $)
70+
required: false
71+
type: string
72+
default: ""
73+
6374
secrets:
6475
registry_username:
6576
description: |
@@ -73,7 +84,6 @@ on:
7384
IF USING PUBLISHING TO A CONTAINER REGISTRY (else, var is ignored):
7485
The token/password needed for publishing the image to a container registry.
7586
EXAMPLE: use $ {{ secrets.DOCKERHUB_TOKEN }} (no space after $)
76-
EXAMPLE: use $ {{ secrets.GITHUB_TOKEN }} (no space after $)
7787
required: false
7888
cvmfs_github_token:
7989
description: |
@@ -199,6 +209,7 @@ jobs:
199209
echo '```'
200210
echo "${{ inputs.cvmfs_remove_tags }}"
201211
echo '```'
212+
echo "- \`extra_build_tag\` = ${{ inputs.extra_build_tag || 'null' }}"
202213
echo ""
203214
204215
[[ "${{ steps.set.outputs.do-build-and-publish-image }}" == 'true' ]] && echo "### 📋 Build Config"
@@ -251,7 +262,6 @@ jobs:
251262
matrix:
252263
include: ${{ fromJson(needs.gameplan.outputs.build-platform-matrix) }}
253264
runs-on: ${{ matrix.runner }}
254-
name: Build+publish image (${{ matrix.platform }})
255265
steps:
256266
- uses: actions/checkout@v4
257267
with:
@@ -265,7 +275,7 @@ jobs:
265275
username: ${{ inputs.image_registry == 'ghcr.io' && github.actor || secrets.registry_username }}
266276
password: ${{ inputs.image_registry == 'ghcr.io' && secrets.GITHUB_TOKEN || secrets.registry_token }}
267277

268-
# VERY BASIC METADATA - tagging occurs in 'tag-published-images' (job)
278+
# VERY BASIC METADATA - tagging occurs in 'tag-and-merge-published-images' (job)
269279
- id: docker_meta
270280
uses: docker/metadata-action@v5
271281
with:
@@ -309,7 +319,7 @@ jobs:
309319
retention-days: 1
310320

311321

312-
tag-published-images: # now, tag the image(s) just published -- if multiple images, this merges under a single manifest
322+
tag-and-merge-published-images: # now, tag the image(s) just published -- if multiple images, this merges under a single manifest
313323
if: needs.gameplan.outputs.do-build-and-publish-image == 'true'
314324
needs: [
315325
gameplan,
@@ -340,9 +350,22 @@ jobs:
340350
images: |
341351
${{ inputs.image_registry }}/${{ inputs.image_namespace }}/${{ inputs.image_name }}
342352
tags: |
343-
# running on: branch
353+
# CUSTOM TAG: using 'extra_build_tag'\
354+
# example: dev
355+
type=raw,value=${{ inputs.extra_build_tag }},enable=${{ inputs.extra_build_tag != '' }}
356+
357+
# RUNNING ON: branch
358+
# -> verbatim branch name
359+
# example: main
360+
# example: foo
361+
type=ref,event=branch
362+
# -> SHA suffix
363+
# example: main-1a2b3c
364+
# example: foo-4d5e6f
344365
type=sha,prefix={{branch}}-,enable=${{ github.ref_type == 'branch' }}
345-
# running on: new tag
366+
367+
# RUNNING ON: new tag
368+
# example: v1 + v1.2 + v1.2.3
346369
type=semver,pattern={{major}},enable=${{ github.ref_type == 'tag' }}
347370
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref_type == 'tag' }}
348371
type=semver,pattern={{major}}.{{minor}}.{{patch}},enable=${{ github.ref_type == 'tag' }}
@@ -384,15 +407,15 @@ jobs:
384407
needs: [
385408
gameplan,
386409
remove-from-cvmfs, # needed b/c cvmfs removals need to happen before builds
387-
tag-published-images, # needed for retrieving images
410+
tag-and-merge-published-images, # needed for retrieving images
388411
]
389412
runs-on: ubuntu-latest
390413
steps:
391414
- uses: WIPACrepo/[email protected]
392415
with:
393416
github_token: ${{ secrets.cvmfs_github_token }}
394417
dest_dir: ${{ inputs.cvmfs_dest_dir }}
395-
build_images: ${{ needs.tag-published-images.outputs.tags }}
418+
build_images: ${{ needs.tag-and-merge-published-images.outputs.tags }}
396419

397420
final-summary:
398421
if: always()
@@ -401,7 +424,7 @@ jobs:
401424
gameplan,
402425
remove-from-cvmfs,
403426
build-w-platform-and-publish-by-sha,
404-
tag-published-images,
427+
tag-and-merge-published-images,
405428
build-on-cvmfs,
406429
]
407430
runs-on: ubuntu-latest
@@ -428,7 +451,7 @@ jobs:
428451
if [[ "${{ needs.gameplan.outputs.do-build-and-publish-image }}" == "true" ]]; then
429452
echo "## 🔢 Tags Published"
430453
echo '```'
431-
echo "${{ needs.tag-published-images.outputs.tags }}"
454+
echo "${{ needs.tag-and-merge-published-images.outputs.tags }}"
432455
echo '```'
433456
echo ""
434457
echo "## 🔍 Platform Digests"

0 commit comments

Comments
 (0)