Fixes to make the images sharable
Changing the time on all SRC RPMS to EPOCH So the images will always have the same date on them. This prevents us from getting variance and allows the blobs to be shared. Also now commit each layer and start a new container based on the previous Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
239362b8d0
commit
740a3b60fa
1 changed files with 26 additions and 25 deletions
|
@ -1,4 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script requires an OCI IMAGE Name to pull.
|
||||
# The script generates a SOURCE Image based on the OCI Image
|
||||
# Script must be executed on the same OS or newer as the image.
|
||||
|
@ -9,8 +10,6 @@ CONTEXT_DIR=$2
|
|||
EXTRA_SRC_DIR=$3
|
||||
IMAGE_CTR=$(buildah from ${IMAGE})
|
||||
IMAGE_MNT=$(buildah mount ${IMAGE_CTR})
|
||||
SRC_CTR=$(buildah from scratch)
|
||||
SRC_MNT=$(buildah mount ${SRC_CTR})
|
||||
#
|
||||
# From the executable image, get the RELEASEVER of the image
|
||||
#
|
||||
|
@ -19,33 +18,35 @@ RELEASE=$(rpm -q --queryformat "%{VERSION}\n" --root $IMAGE_MNT -f /etc/os-relea
|
|||
# From the executable image, list the SRC RPMS used to build the image
|
||||
#
|
||||
SRC_RPMS=$(rpm -qa --root ${IMAGE_MNT} --queryformat '%{SOURCERPM}\n' | grep -v '^gpg-pubkey' | sort -u)
|
||||
buildah umount ${IMAGE_CTR}
|
||||
buildah rm ${IMAGE_CTR}
|
||||
|
||||
#
|
||||
# Create directory in source container image for RPMS
|
||||
#
|
||||
mkdir -p ${SRC_RPM_DIR} ${SRC_MNT}/RPMS
|
||||
#
|
||||
# For each SRC_RPMS used to build the executable image, download the SRC RPM
|
||||
# and generate a layer in the SRC RPM.
|
||||
#
|
||||
(cd ${SRC_RPM_DIR};
|
||||
set -x
|
||||
pushd ${SRC_RPM_DIR}
|
||||
export SRC_CTR=$(buildah from scratch)
|
||||
for i in ${SRC_RPMS}; do
|
||||
if [ ! -f $i ]; then
|
||||
RPM=$(echo $i | sed 's/.src.rpm$//g')
|
||||
dnf download --release $RELEASE --source $RPM || continue
|
||||
RPM=$(echo $i | sed 's/.src.rpm$//g')
|
||||
dnf download --release $RELEASE --source $RPM || continue
|
||||
fi
|
||||
cp $i $SRC_MNT/RPMS
|
||||
buildah commit $SRC_CTR $i
|
||||
echo "Adding $i"
|
||||
touch --date='@0' $i
|
||||
buildah add --add-history ${SRC_CTR} $i /RPMS
|
||||
export IMG=$(buildah commit --rm ${SRC_CTR} $i)
|
||||
export SRC_CTR=$(buildah from ${IMG})
|
||||
done
|
||||
)
|
||||
popd
|
||||
#
|
||||
# If the caller specified a context directory,
|
||||
# add it to the CONTEXT DIR in SRC IMAGE
|
||||
#
|
||||
if [ ! -z "${CONTEXT_DIR}" ]; then
|
||||
cp -R ${CONTEXT_DIR} ${SRC_MNT}/CONTEXT
|
||||
buildah commit $SRC_CTR $1_$(echo $(CONTEXT_DIR) | sed 's|/|_|g')
|
||||
buildah add --add-history ${SRC_CTR} ${CONTEXT_DIR} /CONTEXT
|
||||
export IMG=$(buildah commit --rm $SRC_CTR $1_$(echo $(CONTEXT_DIR) | sed 's|/|_|g'))
|
||||
export SRC_CTR=$(buildah from ${IMG})
|
||||
fi
|
||||
|
||||
#
|
||||
|
@ -53,18 +54,18 @@ fi
|
|||
# add it to the CONTEXT DIR in SRC IMAGE
|
||||
#
|
||||
if [ ! -z "${EXTRA_SRC_DIR}" ]; then
|
||||
cp -R ${EXTRA_SRC_DIR} ${SRC_MNT}/EXTRA
|
||||
buildah commit $SRC_CTR $1_$(echo $(EXTRA_SRC_DIR) | sed 's|/|_|g')
|
||||
buildah add --add-history ${SRC_CTR} ${EXTRA_SRC_DIR} /EXTRA
|
||||
export IMG=$(buildah commit --rm $EXTRA_SRC_CTR $1_$(echo $(CONTEXT_DIR) | sed 's|/|_|g'))
|
||||
export SRC_CTR=$(buildah from ${IMG})
|
||||
fi
|
||||
|
||||
# Cleanup and remove source container
|
||||
buildah rm ${SRC_CTR}
|
||||
|
||||
#
|
||||
# Commit the SRC_CTR TO a SRC_IMAGE
|
||||
#
|
||||
buildah commit $SRC_CTR $SRC_IMAGE
|
||||
buildah tag $IMG $SRC_IMAGE
|
||||
|
||||
# Push SRC_IMAGE to Registry
|
||||
# buildah push $SRC_IMAGE REGISTRY_NAME/$SRC_IMAGE
|
||||
|
||||
# Cleanup and remove containers
|
||||
buildah umount ${SRC_CTR} ${IMAGE_CTR}
|
||||
buildah rm ${SRC_CTR} ${IMAGE_CTR}
|
||||
|
|
Loading…
Reference in a new issue