-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an opinionated action for building OCI-Images that will as an additional output expose a (customisable) OCM-Resource-Fragment (which can be used to generate an OCM-Component-Descriptor.
- Loading branch information
Showing
2 changed files
with
124 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: Build and Push OCI-Image / OCM-Resource | ||
description: | | ||
Builds an OCI Image using `docker/build-push-action@v6`, and exposes a (customisable) | ||
OCM Resource fragment as output (for being added to OCM Component-Descriptor). | ||
For convenience, the action tries to authenticate against target-OCI-Registry using | ||
github.com/gardener/cc-utils/.github/actions/gar-auth. | ||
inputs: | ||
name: | ||
description: | | ||
resource-name (used in OCM Resource Fragment; must be unique within component) | ||
required: true | ||
repository: | ||
description: | | ||
OCI Repository to push to (including registry, but excluding tag) | ||
For example: `europe-docker.pkg.dev/gardener-project/snapshots/my-image` | ||
required: true | ||
version: | ||
description: | | ||
Used for both image-tag, and OCM Resource fragment. | ||
required: true | ||
extra-tags: | ||
description: | | ||
An optional list of additional image-tags (for example: latest) | ||
required: false | ||
ocm_labels: | ||
description: | | ||
An optional list of OCM Labels to add into OCM Resource fragment. | ||
required: false | ||
target: | ||
description: | | ||
docker-build target (similar to `docker build --target`) | ||
required: no | ||
default: null | ||
oci_platforms: | ||
description: | | ||
OCI Platforms to build (comma-separated) | ||
required: false | ||
default: linux/amd64 | ||
dockerfile: | ||
description: | | ||
path to dockerfile to use; relative to `context` | ||
required: false | ||
default: Dockerfile | ||
context: | ||
description: | | ||
passed to build-push-action's `context` | ||
see: | ||
- https://github.com/docker/build-push-action#git-context | ||
- https://github.com/docker/build-push-action#path-context | ||
required: false | ||
outputs: | ||
ocm_resource: | ||
description: | | ||
The OCM Resource fragment | ||
value: ${{ steps.export.outputs.ocm_resource }} | ||
image_reference: | ||
description: | | ||
The (default) target-image-reference | ||
value: ${{ steps.preprocess.outputs.image_reference }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: GAR-Auth | ||
id: auth | ||
uses: gardener/cc-utils/.github/actions/gar-auth@master | ||
- name: Preprocess Parameters | ||
shell: bash | ||
id: preprocess | ||
run: | | ||
echo preparing.. | ||
image_reference=${{ inputs.repository }}:${{ inputs.version }} | ||
echo "image_reference=${image_reference}" >> "${GITHUB_OUTPUT}" | ||
- name: Build and Push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
push: true | ||
platforms: ${{ inputs.oci_platforms }} | ||
tags: ${{ steps.preprocess.outputs.image_reference }} | ||
context: ${{ inputs.context }} | ||
- name: Write OCM Resource fragment | ||
shell: bash | ||
id: export | ||
run: | | ||
r=ocm-resource.yaml | ||
cat << EOF > $r | ||
name: ${{ inputs.name }} | ||
version: ${{ inputs.version }} | ||
type: ociImage | ||
relation: local | ||
access: | ||
type: ociRegistry | ||
imageReference: ${{ steps.preprocess.outputs.image_reference }} | ||
EOF | ||
labels="${{ inputs.ocm_labels }}" | ||
if [ -n "${labels}" ]; then | ||
if ! which python3 &>/dev/null; then | ||
apt install -y python3 python3-pip | ||
pip3 install --no-cache gardener-ocm | ||
fi | ||
echo -e "labels:\n${labels}" >> $r | ||
fi | ||
( | ||
echo 'ocm_resource<<EOF' | ||
cat $r | ||
echo EOF | ||
) >> "${GITHUB_OUTPUT}" | ||
echo "debug: printing ocm_resource" | ||
cat $r | ||
cat ${GITHUB_OUTPUT} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters