Merge pull request #964 from tobiasge/better-base-image-check

Simplified base image check
This commit is contained in:
Tobias Genannt 2023-03-16 09:46:35 +01:00 committed by GitHub
commit c001b88a81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View File

@ -6,11 +6,6 @@ get_image_label() {
skopeo inspect "docker://$image" | jq -r ".Labels[\"$label\"]" skopeo inspect "docker://$image" | jq -r ".Labels[\"$label\"]"
} }
get_image_layers() {
local image=$1
skopeo inspect "docker://$image" | jq -r ".Layers"
}
get_image_last_layer() { get_image_last_layer() {
local image=$1 local image=$1
skopeo inspect "docker://$image" | jq -r ".Layers | last" skopeo inspect "docker://$image" | jq -r ".Layers | last"

View File

@ -324,11 +324,11 @@ else
source ./build-functions/get-public-image-config.sh source ./build-functions/get-public-image-config.sh
echo "Checking labels for '${FINAL_DOCKER_TAG}'" echo "Checking labels for '${FINAL_DOCKER_TAG}'"
BASE_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM}") BASE_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM}")
mapfile -t IMAGES_LAYERS_OLD < <(get_image_layers "${FINAL_DOCKER_TAG}") OLD_BASE_LAST_LAYER=$(get_image_label netbox.last-base-image-layer "${FINAL_DOCKER_TAG}")
NETBOX_GIT_REF_OLD=$(get_image_label netbox.git-ref "${FINAL_DOCKER_TAG}") NETBOX_GIT_REF_OLD=$(get_image_label netbox.git-ref "${FINAL_DOCKER_TAG}")
GIT_REF_OLD=$(get_image_label org.opencontainers.image.revision "${FINAL_DOCKER_TAG}") GIT_REF_OLD=$(get_image_label org.opencontainers.image.revision "${FINAL_DOCKER_TAG}")
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${BASE_LAST_LAYER}\$"; then if [ "${BASE_LAST_LAYER}" != "${OLD_BASE_LAST_LAYER}" ]; then
SHOULD_BUILD="true" SHOULD_BUILD="true"
BUILD_REASON="${BUILD_REASON} ubuntu" BUILD_REASON="${BUILD_REASON} ubuntu"
fi fi
@ -388,6 +388,7 @@ fi
if [ -n "${BUILD_REASON}" ]; then if [ -n "${BUILD_REASON}" ]; then
BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<<"$BUILD_REASON") BUILD_REASON=$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<<"$BUILD_REASON")
DOCKER_BUILD_ARGS+=(--label "netbox.build-reason=${BUILD_REASON}") DOCKER_BUILD_ARGS+=(--label "netbox.build-reason=${BUILD_REASON}")
DOCKER_BUILD_ARGS+=(--label "netbox.last-base-image-layer=${BASE_LAST_LAYER}")
fi fi
# --build-arg # --build-arg