Skip to content

Instantly share code, notes, and snippets.

@bentito
Created December 6, 2023 20:20
Show Gist options
  • Save bentito/d54749933d88af7558c0145f2f7498fc to your computer and use it in GitHub Desktop.
Save bentito/d54749933d88af7558c0145f2f7498fc to your computer and use it in GitHub Desktop.
print operator bundle Dockerfiles
#!/bin/bash
# Check if an image reference is provided
if [ -z "$1" ]; then
echo "Usage: $0 <image-reference>"
exit 1
fi
IMAGE_REF=$1
# Create a temporary directory
TMP_DIR=$(mktemp -d)
OCI_DIR="${TMP_DIR}/oci"
# Function to clean up temporary directory
cleanup() {
echo "Cleaning up temporary files..."
rm -rf "${TMP_DIR}"
}
# Ensure cleanup on script exit
trap cleanup EXIT
# Use skopeo inspect to get layer SHAs
LAYER_SHAS=$(skopeo inspect "${IMAGE_REF}" | jq -r '.Layers[]')
# Check if jq command succeeded
if [ $? -ne 0 ]; then
echo "Failed to inspect the image or parse JSON"
exit 1
fi
# Copy the image to local OCI layout
skopeo copy "${IMAGE_REF}" "oci:${OCI_DIR}"
# Process each layer
for LAYER_SHA in $LAYER_SHAS; do
LAYER_FILE="${OCI_DIR}/blobs/sha256/${LAYER_SHA##sha256:}"
if [ -f "${LAYER_FILE}" ]; then
# Create a temporary directory for this layer
LAYER_TMP_DIR=$(mktemp -d)
# Extract layer
tar -xf "${LAYER_FILE}" -C "${LAYER_TMP_DIR}"
# Look for Dockerfile in the extracted layer
DOCKERFILE=$(find "${LAYER_TMP_DIR}" -type f -name "Dockerfile*")
if [ ! -z "${DOCKERFILE}" ]; then
echo "Found Dockerfile in layer ${LAYER_SHA}: ${DOCKERFILE}"
cat "${DOCKERFILE}"
fi
# Clean up layer temporary directory
rm -rf "${LAYER_TMP_DIR}"
fi
done
echo "Done."
@bentito
Copy link
Author

bentito commented Dec 6, 2023

when run with an RH operator bundle image ref:

$ ./print_operator_dockerfile.sh docker://registry.redhat.io/quay/quay-operator-bundle@sha256:a97a63899d23e23d039ea36bd575c018d7b6295b7942b15a8bded52f09736bda
Getting image source signatures
Copying blob 2ba0fc40f09c done   |
Copying config 633abe6657 done   |
Writing manifest to image destination
Found Dockerfile in layer sha256:2ba0fc40f09c8c50b9f054331a0da3d1e74a590d93e22668633cfe6160cb1ccd: /var/folders/g9/fm9njmrj1zqg9h6tk3z0rzdh0000gn/T/tmp.Y2DRPeQXGD/root/buildinfo/Dockerfile-quay-quay-operator-bundle-v3.8.11-20
FROM scratch

LABEL com.redhat.delivery.operator.bundle=true
LABEL com.redhat.delivery.openshift.ocp.versions="v4.8"
LABEL com.redhat.openshift.versions="v4.8"
LABEL com.redhat.delivery.backport=false

LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=quay-operator
LABEL operators.operatorframework.io.bundle.channels.v1=stable-3.8
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable-3.8

LABEL com.redhat.component="quay-operator-bundle-container"
LABEL name="quay/quay-operator-bundle"
LABEL summary="Quay Operator bundle container image"
LABEL description="Operator bundle for Quay Operator"
LABEL maintainer="Red Hat <support@redhat.com>"
LABEL version=v3.8.11
LABEL io.k8s.display-name="Red Hat Quay Operator Bundle"
LABEL io.openshift.tags="quay"

COPY bundle/manifests/*.yaml /manifests/
COPY bundle/manifests/metadata/annotations.yaml /metadata/annotations.yaml

LABEL release=20

ADD quay-operator-bundle-container-v3.8.11-20.json /root/buildinfo/content_manifests/quay-operator-bundle-container-v3.8.11-20.json
LABEL "com.redhat.license_terms"="https://www.redhat.com/agreements" "distribution-scope"="public" "vendor"="Red Hat, Inc." "build-date"="2023-08-07T23:21:46" "architecture"="x86_64" "vcs-type"="git" "vcs-ref"="f6eb857b8bd8768d51a311bc274f53ce7856ae04" "io.k8s.description"="Operator bundle for Quay Operator" "url"="https://access.redhat.com/containers/#/registry.access.redhat.com/quay/quay-operator-bundle/images/v3.8.11-20"
Done.
Cleaning up temporary files...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment