Created
December 6, 2023 20:20
-
-
Save bentito/d54749933d88af7558c0145f2f7498fc to your computer and use it in GitHub Desktop.
print operator bundle Dockerfiles
This file contains hidden or 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
#!/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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when run with an RH operator bundle image ref: