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

fix: expose image manifest from build-vm-image task #1147

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Changes from 3 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
32 changes: 24 additions & 8 deletions task/build-vm-image/0.1/build-vm-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ spec:
rsync -ra /entitlement/ "$SSH_HOST:$BUILD_DIR/entitlement/"

# form the --type arguments
IMAGE_TYPES=" --type $IMAGE_TYPE "
IMAGE_TYPE_ARGUMENT=" --type $IMAGE_TYPE "

# this heredoc allows expansions for the image name
# this unquoted heredoc allows expansions for the image name
cat >scripts/script-build.sh <<REMOTESSHEOF
#!/bin/sh
set -e
Expand All @@ -162,11 +162,11 @@ spec:
export BOOTC_BUILDER_IMAGE="$BOOTC_BUILDER_IMAGE"
export SOURCE_IMAGE="$SOURCE_IMAGE"
export TAGGED_AS="$TAGGED_AS"
export IMAGE_TYPES="$IMAGE_TYPES"
export IMAGE_TYPE_ARGUMENT="$IMAGE_TYPE_ARGUMENT"

REMOTESSHEOF

# no expansions in this one, the env vars are evaluated on the remote vm
# this quoted heredoc prevents expansions and command substitutions. the env vars are evaluated on the remote vm
cat >>scripts/script-build.sh <<'REMOTESSHEOF'
echo >config.toml <<EOF
[[blueprint.customizations.user]]
Expand All @@ -183,13 +183,13 @@ spec:
echo "TAGGING IMAGE"
time sudo podman tag $SOURCE_IMAGE $TAGGED_AS
echo "RUNNING BUILD"
echo -e "IMAGE_TYPES = $IMAGE_TYPES"
echo -e "IMAGE_TYPE_ARGUMENT = $IMAGE_TYPE_ARGUMENT"

time sudo podman run --authfile=$BUILD_DIR/.docker/config.json --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t \
-v $(pwd)/config.toml:/config.toml -v $(pwd)/output:/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
-v $BUILD_DIR/entitlement:/etc/pki/entitlement:Z \
$BOOTC_BUILDER_IMAGE $IMAGE_TYPES --local $TAGGED_AS
$BOOTC_BUILDER_IMAGE $IMAGE_TYPE_ARGUMENT --local $TAGGED_AS

# This script is currently using fedora image because buildah in UBI9 does not have the OCI support (no --artifact* switches)
time sudo podman run --authfile=$BUILD_DIR/.docker/config.json --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t \
Expand All @@ -203,10 +203,20 @@ spec:
REMOTESSHEOF

# script-push.sh script is intended run _inside_ podman on the ssh host and requires sudo
# this unquoted heredoc allows expansions for the image name
cat >scripts/script-push.sh <<REMOTESSHEOF
#!/bin/bash
set -ex
dnf -y install buildah pigz

export OUTPUT_IMAGE="$OUTPUT_IMAGE"

REMOTESSHEOF

# this quoted heredoc prevents expansions and command substitutions. the env vars are evaluated on the remote vm
cat >>scripts/script-push.sh <<'REMOTESSHEOF'
dnf -y install buildah pigz jq

# Build an image index of length 1 referring to an image manifest with the content
buildah --storage-driver=vfs manifest create "$OUTPUT_IMAGE"
ralphbean marked this conversation as resolved.
Show resolved Hide resolved

# show contents of /output
Expand All @@ -226,8 +236,14 @@ spec:
buildah --storage-driver=vfs manifest add --arch $(arch) --os linux --artifact --artifact-type application/vnd.diskimage.iso.gzip $OUTPUT_IMAGE /output/bootiso/install.iso.gz
fi
buildah --storage-driver=vfs manifest push --digestfile image-digest --authfile /.docker/config.json --all $OUTPUT_IMAGE

# At this point, we have pushed an image index of length 1 to the registry.
# Next, extract a reference to the image manifest and expose that, throwing away the image index.
IMAGE_INDEX_DIGEST=$(cat image-digest)
MANIFEST_DIGEST=$(buildah manifest inspect --authfile /.docker/config.json $OUTPUT_IMAGE@$IMAGE_INDEX_DIGEST | jq '.manifests[0].digest')
ralphbean marked this conversation as resolved.
Show resolved Hide resolved

echo -n "$OUTPUT_IMAGE" | tee /tekton-results/IMAGE_URL
cat image-digest | tee /tekton-results/IMAGE_DIGEST
echo $MANIFEST_DIGEST | tee /tekton-results/IMAGE_DIGEST
REMOTESSHEOF


Expand Down
Loading