Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1d384c8f5 | ||
|
|
b1403046e5 |
@@ -11,8 +11,11 @@ name: image
|
|||||||
# commit: a repo with several images calls this once per image (the calls run in
|
# commit: a repo with several images calls this once per image (the calls run in
|
||||||
# parallel) and all of them get the same tag. Rebuilding a commit re-pushes its tag.
|
# parallel) and all of them get the same tag. Rebuilding a commit re-pushes its tag.
|
||||||
#
|
#
|
||||||
# Images go to <registry>/<project>/<image>, and to docker.io/<dockerhub-username>/<image>
|
# Images go to <registry>/<project>/<image>, and to
|
||||||
# when the Docker Hub secrets are passed.
|
# docker.io/<dockerhub-username>/<project>-<image> (or <dockerhub-image>) when the Docker Hub
|
||||||
|
# secrets are passed.
|
||||||
|
#
|
||||||
|
# After a push, the compressed size per platform is printed to the log and the job summary.
|
||||||
#
|
#
|
||||||
# One image per call: Gitea 1.27.0 can't expand a matrix built from inputs in a called
|
# One image per call: Gitea 1.27.0 can't expand a matrix built from inputs in a called
|
||||||
# workflow (the run is silently not created).
|
# workflow (the run is silently not created).
|
||||||
@@ -45,9 +48,13 @@ on:
|
|||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
image:
|
image:
|
||||||
description: Image name, in Harbor and on Docker Hub.
|
description: Image name in Harbor, and on Docker Hub as <project>-<image>.
|
||||||
type: string
|
type: string
|
||||||
required: true
|
required: true
|
||||||
|
dockerhub-image:
|
||||||
|
description: Docker Hub repository name, defaults to <project>-<image>.
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
context:
|
context:
|
||||||
type: string
|
type: string
|
||||||
default: "."
|
default: "."
|
||||||
@@ -78,7 +85,8 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
registry-token:
|
registry-token:
|
||||||
required: false
|
required: false
|
||||||
# Optional: with both set, the image is also pushed to docker.io/<dockerhub-username>/<image>.
|
# Optional: with both set, the image is also pushed to
|
||||||
|
# docker.io/<dockerhub-username>/<dockerhub-image>.
|
||||||
dockerhub-username:
|
dockerhub-username:
|
||||||
required: false
|
required: false
|
||||||
dockerhub-token:
|
dockerhub-token:
|
||||||
@@ -106,6 +114,7 @@ jobs:
|
|||||||
# Secrets can't be used in `if:` directly, env can.
|
# Secrets can't be used in `if:` directly, env can.
|
||||||
DOCKERHUB: ${{ secrets.dockerhub-username != '' && secrets.dockerhub-token != '' }}
|
DOCKERHUB: ${{ secrets.dockerhub-username != '' && secrets.dockerhub-token != '' }}
|
||||||
DOCKERHUB_USERNAME: ${{ secrets.dockerhub-username }}
|
DOCKERHUB_USERNAME: ${{ secrets.dockerhub-username }}
|
||||||
|
DOCKERHUB_IMAGE: ${{ inputs.dockerhub-image || format('{0}-{1}', inputs.project, inputs.image) }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
|
|
||||||
@@ -117,7 +126,7 @@ jobs:
|
|||||||
images="${IMAGE}"
|
images="${IMAGE}"
|
||||||
if [ "${DOCKERHUB}" = "true" ]; then
|
if [ "${DOCKERHUB}" = "true" ]; then
|
||||||
images="${images}
|
images="${images}
|
||||||
docker.io/${DOCKERHUB_USERNAME}/${{ inputs.image }}"
|
docker.io/${DOCKERHUB_USERNAME}/${DOCKERHUB_IMAGE}"
|
||||||
fi
|
fi
|
||||||
{
|
{
|
||||||
echo "ts=${ts}"
|
echo "ts=${ts}"
|
||||||
@@ -156,7 +165,8 @@ jobs:
|
|||||||
username: ${{ secrets.dockerhub-username }}
|
username: ${{ secrets.dockerhub-username }}
|
||||||
password: ${{ secrets.dockerhub-token }}
|
password: ${{ secrets.dockerhub-token }}
|
||||||
|
|
||||||
- uses: docker/build-push-action@v7
|
- id: build
|
||||||
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: ${{ inputs.context }}
|
context: ${{ inputs.context }}
|
||||||
file: ${{ inputs.dockerfile || format('{0}/Dockerfile', inputs.context) }}
|
file: ${{ inputs.dockerfile || format('{0}/Dockerfile', inputs.context) }}
|
||||||
@@ -167,3 +177,30 @@ jobs:
|
|||||||
build-args: ${{ inputs.build-args }}
|
build-args: ${{ inputs.build-args }}
|
||||||
cache-from: ${{ inputs.cache == 'true' && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }}
|
cache-from: ${{ inputs.cache == 'true' && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }}
|
||||||
cache-to: ${{ inputs.cache == 'true' && inputs.push == 'true' && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }}
|
cache-to: ${{ inputs.cache == 'true' && inputs.push == 'true' && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }}
|
||||||
|
|
||||||
|
# Compressed size per platform (sum of the layer sizes, what a pull downloads), read
|
||||||
|
# back from the registry. Only after a push: a multi-platform build isn't kept locally.
|
||||||
|
- if: inputs.push == 'true'
|
||||||
|
env:
|
||||||
|
DIGEST: ${{ steps.build.outputs.digest }}
|
||||||
|
PLATFORMS: ${{ inputs.platforms }}
|
||||||
|
run: |
|
||||||
|
raw="$(docker buildx imagetools inspect --raw "${IMAGE}@${DIGEST}")"
|
||||||
|
# a single-platform push without attestations is a plain manifest, not an index
|
||||||
|
if echo "${raw}" | jq -e '.manifests' >/dev/null; then
|
||||||
|
list="$(echo "${raw}" | jq -r '.manifests[]
|
||||||
|
| select(.annotations["vnd.docker.reference.type"] != "attestation-manifest")
|
||||||
|
| "\(.platform.os)/\(.platform.architecture)\(if .platform.variant then "/" + .platform.variant else "" end) \(.digest)"')"
|
||||||
|
else
|
||||||
|
list="${PLATFORMS} ${DIGEST}"
|
||||||
|
fi
|
||||||
|
{
|
||||||
|
echo "### ${IMAGE}"
|
||||||
|
echo ""
|
||||||
|
echo "| Platform | Compressed size |"
|
||||||
|
echo "|---|---|"
|
||||||
|
echo "${list}" | while read -r platform digest; do
|
||||||
|
bytes="$(docker buildx imagetools inspect --raw "${IMAGE}@${digest}" | jq '[.layers[].size] | add')"
|
||||||
|
echo "| ${platform} | $(numfmt --to=iec --suffix=B "${bytes}") |"
|
||||||
|
done
|
||||||
|
} | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}"
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ Builds and pushes one image with a uniform tag set from
|
|||||||
|
|
||||||
- `registry`: default `registry.traberph.de`.
|
- `registry`: default `registry.traberph.de`.
|
||||||
- `project` (required): Harbor project, e.g. `public` or `private`.
|
- `project` (required): Harbor project, e.g. `public` or `private`.
|
||||||
- `image` (required): image name, used in Harbor (`<registry>/<project>/<image>`) and on Docker Hub.
|
- `image` (required): image name in Harbor (`<registry>/<project>/<image>`).
|
||||||
|
- `dockerhub-image`: Docker Hub repository name, default `<project>-<image>`. See
|
||||||
|
[Docker Hub](#docker-hub).
|
||||||
- `context`: default `.`.
|
- `context`: default `.`.
|
||||||
- `dockerfile`: default `<context>/Dockerfile`.
|
- `dockerfile`: default `<context>/Dockerfile`.
|
||||||
- `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed.
|
- `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed.
|
||||||
@@ -72,6 +74,12 @@ input of a called workflow arrives as `false`. An expression like
|
|||||||
|
|
||||||
`tag` (the timestamp tag), `version`, `tags` (the full image references).
|
`tag` (the timestamp tag), `version`, `tags` (the full image references).
|
||||||
|
|
||||||
|
### Image size
|
||||||
|
|
||||||
|
After a push, the compressed size of each platform (the sum of its layer sizes, what a pull
|
||||||
|
downloads) is read back from the registry and printed to the log and the job summary. Builds
|
||||||
|
with `push: "false"` skip it: a multi-platform build isn't kept locally.
|
||||||
|
|
||||||
### Tags
|
### Tags
|
||||||
|
|
||||||
| Tag | When |
|
| Tag | When |
|
||||||
@@ -86,9 +94,11 @@ tags instead of producing a newer one.
|
|||||||
### Docker Hub
|
### Docker Hub
|
||||||
|
|
||||||
If `dockerhub-username` and `dockerhub-token` are passed, the image is also pushed with the same
|
If `dockerhub-username` and `dockerhub-token` are passed, the image is also pushed with the same
|
||||||
tags to `docker.io/<dockerhub-username>/<image>`, e.g. `registry.traberph.de/public/homepage` →
|
tags to `docker.io/<dockerhub-username>/<project>-<image>`, e.g.
|
||||||
`docker.io/traberph/homepage`. Only pass them for public images: Docker Hub creates new
|
`registry.traberph.de/public/homepage` → `docker.io/traberph/public-homepage`. Docker Hub has no
|
||||||
repositories as public by default.
|
projects, so the project goes into the name. Set `dockerhub-image` to use another name, e.g.
|
||||||
|
`dockerhub-image: homepage` → `docker.io/traberph/homepage`. Only pass the secrets for public
|
||||||
|
images: Docker Hub creates new repositories as public by default.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
secrets:
|
secrets:
|
||||||
|
|||||||
Reference in New Issue
Block a user