Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectively build base container for fasttrack/2.0 #11777

Open
wants to merge 9 commits into
base: fasttrack/2.0
Choose a base branch
from
Open
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions .pipelines/containerSourceData/scripts/BuildBaseContainers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ set -e
# -r "" \
# -q "false"

while getopts ":a:c:k:l:o:p:r:q:" OPTIONS; do
while getopts ":a:c:k:l:o:p:r:q:s:t:u:v:" OPTIONS; do
case ${OPTIONS} in
a ) ACR=$OPTARG;;
c ) CONTAINER_TARBALLS_DIR=$OPTARG;;
Expand All @@ -59,6 +59,10 @@ while getopts ":a:c:k:l:o:p:r:q:" OPTIONS; do
p ) PUBLISHING_LEVEL=$OPTARG;;
r ) REPO_PREFIX=$OPTARG;;
q ) PUBLISH_TO_ACR=$OPTARG;;
s ) DISTROLESS_BASE_BUILD=$OPTARG;;
t ) DISTROLESS_DEBUG_BUILD=$OPTARG;;
u ) DISTROLESS_MINIMAL_BUILD=$OPTARG;;
v ) BASE_BUILD=$OPTARG;;

\? )
echo "Error - Invalid Option: -$OPTARG" 1>&2
Expand Down Expand Up @@ -88,6 +92,10 @@ function print_inputs {
echo "PUBLISHING_LEVEL -> $PUBLISHING_LEVEL"
echo "PUBLISH_TO_ACR -> $PUBLISH_TO_ACR"
echo "OUTPUT_DIR -> $OUTPUT_DIR"
echo "DISTROLESS_BASE_BUILD -> $DISTROLESS_BASE_BUILD"
echo "DISTROLESS_DEBUG_BUILD -> $DISTROLESS_DEBUG_BUILD"
echo "DISTROLESS_MINIMAL_BUILD -> $DISTROLESS_MINIMAL_BUILD"
echo "BASE_BUILD -> $BASE_BUILD"
}

function validate_inputs {
Expand All @@ -106,10 +114,16 @@ function validate_inputs {
DISTROLESS_BASE_TARBALL=$(find "$CONTAINER_TARBALLS_DIR" -name "distroless-base-[0-9.]*.tar.gz")
DISTROLESS_DEBUG_TARBALL=$(find "$CONTAINER_TARBALLS_DIR" -name "distroless-debug-[0-9.]*.tar.gz")
DISTROLESS_MINIMAL_TARBALL=$(find "$CONTAINER_TARBALLS_DIR" -name "distroless-minimal-[0-9.]*.tar.gz")
if [[ (! -f $BASE_TARBALL) || \
(! -f $DISTROLESS_BASE_TARBALL) || \
(! -f $DISTROLESS_DEBUG_TARBALL) || \
(! -f $DISTROLESS_MINIMAL_TARBALL) ]]; then
#give default values
BASE_BUILD=${BASE_BUILD:-true}
DISTROLESS_BASE_BUILD=${DISTROLESS_BASE_BUILD:-true}
DISTROLESS_DEBUG_BUILD=${DISTROLESS_DEBUG_BUILD:-true}
DISTROLESS_MINIMAL_BUILD=${DISTROLESS_MINIMAL_BUILD:-true}

if [[ ($BASE_BUILD =~ [Tt]rue && ! -f $BASE_TARBALL) || \
($DISTROLESS_BASE_BUILD =~ [Tt]rue && ! -f $DISTROLESS_BASE_TARBALL) || \
($DISTROLESS_DEBUG_BUILD =~ [Tt]rue && ! -f $DISTROLESS_DEBUG_TARBALL) || \
($DISTROLESS_MINIMAL_BUILD =~ [Tt]rue && ! -f $DISTROLESS_MINIMAL_TARBALL) ]]; then
echo "Error - Missing some tarball(s) in $CONTAINER_TARBALLS_DIR"
exit 1
fi
Expand Down Expand Up @@ -203,6 +217,10 @@ function initialization {
echo "DISTROLESS_DEBUG_IMAGE_NAME -> $DISTROLESS_DEBUG_IMAGE_NAME"
echo "DISTROLESS_DEBUG_NONROOT_IMAGE_NAME -> $DISTROLESS_DEBUG_NONROOT_IMAGE_NAME"
echo "MARINARA_IMAGE_NAME -> $MARINARA_IMAGE_NAME"
echo "DISTROLESS_BASE_BUILD -> $DISTROLESS_BASE_BUILD"
echo "DISTROLESS_DEBUG_BUILD -> $DISTROLESS_DEBUG_BUILD"
echo "DISTROLESS_MINIMAL_BUILD -> $DISTROLESS_MINIMAL_BUILD"
echo "BASE_BUILD -> $BASE_BUILD"

ROOT_FOLDER="$(git rev-parse --show-toplevel)"
EULA_FILE_PATH="$ROOT_FOLDER/.pipelines/container_artifacts/data"
Expand All @@ -219,6 +237,12 @@ function docker_build {
local image_full_name=$2
local image_tarball=$3
local dockerfile=$4
local should_build=$5

if [[ $should_build =~ [Ff]alse ]]; then
echo "+++ Skip building image- Fasttrack: $image_full_name"
return
fi

echo "+++ Importing container image: $image_full_name"
local temp_image=${image_full_name}_temp
Expand Down Expand Up @@ -256,6 +280,13 @@ function docker_build_custom {
local image_full_name=$2
local final_image_to_use=$3
local dockerfile=$4
local should_build=$5

if [[ $should_build != true ]]; then
PawelWMS marked this conversation as resolved.
Show resolved Hide resolved
PawelWMS marked this conversation as resolved.
Show resolved Hide resolved
echo "+++ Skip building image- Fasttrack: $image_full_name"
return
fi


# $WORK_DIR has $RPMS_DIR directory and $LOCAL_REPO_FILE file.
pushd "$WORK_DIR" > /dev/null
Expand Down Expand Up @@ -345,15 +376,15 @@ function save_container_image {
function build_images {
echo "+++ Build images"

docker_build $BASE "$BASE_IMAGE_NAME" "$BASE_TARBALL" "Dockerfile-Base-Template"
docker_build $DISTROLESS "$DISTROLESS_BASE_IMAGE_NAME" "$DISTROLESS_BASE_TARBALL" "Dockerfile-Distroless-Template"
docker_build $DISTROLESS "$DISTROLESS_MINIMAL_IMAGE_NAME" "$DISTROLESS_MINIMAL_TARBALL" "Dockerfile-Distroless-Template"
docker_build $DISTROLESS "$DISTROLESS_DEBUG_IMAGE_NAME" "$DISTROLESS_DEBUG_TARBALL" "Dockerfile-Distroless-Template"
docker_build $BASE "$BASE_IMAGE_NAME" "$BASE_TARBALL" "Dockerfile-Base-Template" $BASE_BUILD
docker_build $DISTROLESS "$DISTROLESS_BASE_IMAGE_NAME" "$DISTROLESS_BASE_TARBALL" "Dockerfile-Distroless-Template" $DISTROLESS_BASE_BUILD
docker_build $DISTROLESS "$DISTROLESS_MINIMAL_IMAGE_NAME" "$DISTROLESS_MINIMAL_TARBALL" "Dockerfile-Distroless-Template" $DISTROLESS_MINIMAL_BUILD
docker_build $DISTROLESS "$DISTROLESS_DEBUG_IMAGE_NAME" "$DISTROLESS_DEBUG_TARBALL" "Dockerfile-Distroless-Template" $DISTROLESS_DEBUG_BUILD

docker_build_custom $BASE "$BASE_NONROOT_IMAGE_NAME" "" "Dockerfile-Base-Nonroot-Template"
docker_build_custom $DISTROLESS "$DISTROLESS_BASE_NONROOT_IMAGE_NAME" "$DISTROLESS_BASE_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template"
docker_build_custom $DISTROLESS "$DISTROLESS_MINIMAL_NONROOT_IMAGE_NAME" "$DISTROLESS_MINIMAL_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template"
docker_build_custom $DISTROLESS "$DISTROLESS_DEBUG_NONROOT_IMAGE_NAME" "$DISTROLESS_DEBUG_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template"
docker_build_custom $BASE "$BASE_NONROOT_IMAGE_NAME" "" "Dockerfile-Base-Nonroot-Template" $BASE_BUILD
docker_build_custom $DISTROLESS "$DISTROLESS_BASE_NONROOT_IMAGE_NAME" "$DISTROLESS_BASE_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template" $DISTROLESS_BASE_BUILD
docker_build_custom $DISTROLESS "$DISTROLESS_MINIMAL_NONROOT_IMAGE_NAME" "$DISTROLESS_MINIMAL_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template" $DISTROLESS_MINIMAL_BUILD
docker_build_custom $DISTROLESS "$DISTROLESS_DEBUG_NONROOT_IMAGE_NAME" "$DISTROLESS_DEBUG_IMAGE_NAME" "Dockerfile-Distroless-Nonroot-Template" $DISTROLESS_DEBUG_BUILD

docker_build_marinara
}
Expand Down
Loading