Skip to content

Commit

Permalink
Get distro information from FROM image
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Sep 20, 2023
1 parent 2df6f70 commit 66d8ab3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion base-images/alpine/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 alpine:3
FROM alpine:3

# Install packages that we want to make available at both build and run time
RUN apk add --update --no-cache bash ca-certificates
Expand Down
25 changes: 13 additions & 12 deletions base-images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,30 @@ STACK_ID="${ID_PREFIX}.$(basename "${IMAGE_DIR}")"
BASE_IMAGE=${REPO_PREFIX}:${TAG}
RUN_IMAGE=${REPO_PREFIX}-run:${TAG}
BUILD_IMAGE=${REPO_PREFIX}-build:${TAG}

if [[ -d "${IMAGE_DIR}/base" ]]; then
docker build --platform=${PLATFORM} \
--build-arg "distro_name=${DISTRO_NAME}" \
--build-arg "distro_version=${DISTRO_VERSION}" \
--build-arg "stack_id=${STACK_ID}" \
-t "${BASE_IMAGE}" \
"${IMAGE_DIR}/base"
fi
FROM_IMAGE=$(head -n1 "${IMAGE_DIR}"/base/Dockerfile | cut -d' ' -f2)

# Get target distro information
if cmd /c ver; then
DISTRO_NAME=""
RAW_VERSION=$(docker run --rm "${BASE_IMAGE}" cmd /c ver)
RAW_VERSION=$(docker run --rm "${FROM_IMAGE}" cmd /c ver)
DISTRO_VERSION=$(echo "$RAW_VERSION" | head -n1 | sed 's/Microsoft Windows //' | sed 's/[][]//g' | cut -d' ' -f2)
echo "DISTRO_VERSION: ${DISTRO_VERSION}"
else
DISTRO_NAME=$(docker run --rm "${BASE_IMAGE}" cat /etc/os-release | grep '^ID=' | cut -d'=' -f2)
DISTRO_NAME=$(docker run --rm "${FROM_IMAGE}" cat /etc/os-release | grep '^ID=' | cut -d'=' -f2)
echo "DISTRO_NAME: ${DISTRO_NAME}"
DISTRO_VERSION=$(docker run --rm "${BASE_IMAGE}" cat /etc/os-release | grep '^VERSION_ID=' | cut -d'=' -f2)
DISTRO_VERSION=$(docker run --rm "${FROM_IMAGE}" cat /etc/os-release | grep '^VERSION_ID=' | cut -d'=' -f2)
echo "DISTRO_VERSION: ${DISTRO_VERSION}"
fi

if [[ -d "${IMAGE_DIR}/base" ]]; then
docker build --platform=${PLATFORM} \
--build-arg "distro_name=${DISTRO_NAME}" \
--build-arg "distro_version=${DISTRO_VERSION}" \
--build-arg "stack_id=${STACK_ID}" \
-t "${BASE_IMAGE}" \
"${IMAGE_DIR}/base"
fi

echo "BUILDING ${BUILD_IMAGE}..."
docker build --platform=${PLATFORM} \
--build-arg "base_image=${BASE_IMAGE}" \
Expand Down
2 changes: 1 addition & 1 deletion base-images/jammy/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 ubuntu:jammy
FROM ubuntu:jammy

# Install packages that we want to make available at both build and run time
RUN apt update && \
Expand Down

0 comments on commit 66d8ab3

Please sign in to comment.