Repository: vespa-engine/vespa
File: .buildkite/build-container.sh (Shell)

Code before:
        VESPA_BASE_IMAGE="el8"
        SYSTEM_TEST_BASE_IMAGE="almalinux:8"
        ;;
    alma9)
        VESPA_BASE_IMAGE="el9"
        SYSTEM_TEST_BASE_IMAGE="almalinux:9"
        ;;
    *)
        echo "Unknown build os: ${VESPA_BUILDOS_LABEL}" 1>&2
        exit 1
        ;;
esac

echo "--- Setting up docker-image repository"
if [[ ! -d "${WORKDIR}/docker-image" ]]; then
    echo "Cloning docker-image repository..."
    git clone --quiet --depth 1 https://github.com/vespa-engine/docker-image "$WORKDIR/docker-image"
else
    echo "Using existing docker-image repository"
fi

echo "Preparing RPMs for container build..."
rm -rf "${WORKDIR}/docker-image/rpms"
cp -a "${WORKDIR}/artifacts/$ARCH/rpms" "${WORKDIR}/docker-image/"

cd "${WORKDIR}/docker-image"
SOURCE_GITREF=$(git rev-parse HEAD)

echo "--- Building Vespa preview container"
GHCR_PREVIEW_TAG=ghcr.io/vespa-engine/vespa-preview-${ARCH}:${VESPA_VERSION}${VESPA_CONTAINER_IMAGE_VERSION_TAG_SUFFIX}
echo "Building container with tag: ${GHCR_PREVIEW_TAG}"
docker build --progress plain \
             --build-arg SOURCE_GITREF="$SOURCE_GITREF" \
             --build-arg VESPA_VERSION="$VESPA_VERSION" \
             --build-arg VESPA_BASE_IMAGE="$VESPA_BASE_IMAGE" \
             --tag vespaengine/vespa \
             --tag "${GHCR_PREVIEW_TAG}" \
             --file Dockerfile .

declare -r GITREF="${GITREF_SYSTEM_TEST:-HEAD}"

echo "--- Setting up system-test repository"
cd "$WORKDIR"
if [[ ! -d $WORKDIR/system-test ]]; then
    echo "Cloning system-test repository..."
    git clone --quiet --filter="blob:none" https://github.com/vespa-engine/system-test
else
    echo "Using existing system-test repository"
fi

echo "Preparing system-test environment (checking out ${GITREF})..."

Review comment (suggestion):
All other scripts in this PR add a `: "${LOCAL_RPM_REPO:?...}"` validation guard at the top, but this script is missing it. Since the script uses `set -o nounset`, a missing variable would produce an unhelpful "unbound variable" error at the `cp` line instead of a clear message. Consider adding it for consistency:

```bash
: "${LOCAL_RPM_REPO:?Environment variable LOCAL_RPM_REPO must be set (path to local RPM repo)}"
```

Code after:
        VESPA_BASE_IMAGE="el8"
        SYSTEM_TEST_BASE_IMAGE="almalinux:8"
        ;;
    alma9)
        VESPA_BASE_IMAGE="el9"
        SYSTEM_TEST_BASE_IMAGE="almalinux:9"
        ;;
    *)
        echo "Unknown build os: ${VESPA_BUILDOS_LABEL}" 1>&2
        exit 1
        ;;
esac

echo "--- Setting up docker-image repository"
if [[ ! -d "${WORKDIR}/docker-image" ]]; then
    echo "Cloning docker-image repository..."
    git clone --quiet --depth 1 https://github.com/vespa-engine/docker-image "$WORKDIR/docker-image"
else
    echo "Using existing docker-image repository"
fi

echo "Preparing RPMs for container build..."
# Ensure clean state for rpms directory
rm -rf "${WORKDIR}/docker-image/rpms" && mkdir -p "${WORKDIR}/docker-image/rpms"
# Note: Appending "./" ensures that the directory's contents are copied, rather than the directory itself.
cp -a "${LOCAL_RPM_REPO}/." "${WORKDIR}/docker-image/rpms/"

cd "${WORKDIR}/docker-image"
SOURCE_GITREF=$(git rev-parse HEAD)

echo "--- Building Vespa preview container"
GHCR_PREVIEW_TAG=ghcr.io/vespa-engine/vespa-preview-${ARCH}:${VESPA_VERSION}${VESPA_CONTAINER_IMAGE_VERSION_TAG_SUFFIX}
echo "Building container with tag: ${GHCR_PREVIEW_TAG}"
docker build --progress plain \
             --build-arg SOURCE_GITREF="$SOURCE_GITREF" \
             --build-arg VESPA_VERSION="$VESPA_VERSION" \
             --build-arg VESPA_BASE_IMAGE="$VESPA_BASE_IMAGE" \
             --tag vespaengine/vespa \
             --tag "${GHCR_PREVIEW_TAG}" \
             --file Dockerfile .

declare -r GITREF="${GITREF_SYSTEM_TEST:-HEAD}"

echo "--- Setting up system-test repository"
cd "$WORKDIR"
if [[ ! -d $WORKDIR/system-test ]]; then
    echo "Cloning system-test repository..."
    git clone --quiet --filter="blob:none" https://github.com/vespa-engine/system-test
else
    echo "Using existing system-test repository"
fi