#!/bin/bash

set -eo pipefail

# shellcheck source=ci/docker_commands
source "ci/docker_commands"

# source order is important as some functions overlap in name
source "ci/_build_ci_image_common"

build() {
    echo "Building UBI FIPS base image: ${BUILD_IMAGE}"

    trap cleanup_docker_context_trap ERR SIGINT SIGTERM
    setup_docker_context

    _docker_buildx build \
           --platform linux/amd64,linux/ppc64le,linux/arm64  \
           --no-cache \
           --build-arg UBI_VERSION="${UBI_VERSION}" \
           --push \
           -t "${BUILD_IMAGE}" \
           -f "${BUILD_DOCKERFILE}" \
           "${GIT_ROOT}"

    trap - ERR SIGINT SIGTERM
    cleanup_docker_context
}

login
pull
build
logout
scan
