#!/usr/bin/env bash INPUT_IMAGE_NAME=$imageName INPUT_IMAGE_PREFIX=$imagePrefix INPUT_PUSH_IMAGE=$push INPUT_PULL_CACHE=$pullCache INPUT_DOCKERFILE_PATH=$path INPUT_PLATFORM=$platform INPUT_EXPORT_TAR=$exportTarPath set -e # shellcheck disable=SC2155 export LOWERCASE_INPUT_IMAGE_PREFIX="$(echo "$INPUT_IMAGE_PREFIX" | tr '[:upper:]' '[:lower:]')" IMAGE_NAME="$(echo "$LOWERCASE_INPUT_IMAGE_PREFIX" | sed 's/^https\?:\/\///')$INPUT_IMAGE_NAME" if [ -n "$DOCKER_CONFIG_BASE64" ]; then echo "Retrieving docker config" mkdir "$HOME/.docker/" echo "$DOCKER_CONFIG_BASE64" | base64 -d > "$HOME/.docker/config.json" fi; echo "Full image name: $IMAGE_NAME" if [ -z "$INPUT_IMAGE_NAME" ]; then echo "No image name given." exit 1 fi; DOCKER_BUILD_OPTIONS=("--progress" "plain" "-t" "$IMAGE_NAME") if [ -n "$INPUT_PLATFORM" ]; then DOCKER_BUILD_OPTIONS+=("--platform" "$INPUT_PLATFORM" "--pull") fi if [ "$INPUT_PUSH_IMAGE" = "true" ]; then DOCKER_BUILD_OPTIONS+=("--output=type=image,name=${IMAGE_NAME},push=true,compression=zstd,compression-level=8,force-compression=true,oci-mediatypes=true") fi if [ "$INPUT_PULL_CACHE" = "true" ]; then IMAGE_CACHE_NAME="${IMAGE_NAME%%:*}:build-cache" DOCKER_BUILD_OPTIONS+=("--cache-from" "type=registry,ref=${IMAGE_CACHE_NAME}") DOCKER_BUILD_OPTIONS+=("--cache-to" "type=registry,image-manifest=true,oci-mediatypes=true,ref=${IMAGE_CACHE_NAME},mode=max") echo "Using docker image cache ${IMAGE_CACHE_NAME}" fi if [ -n "$INPUT_EXPORT_TAR" ]; then DOCKER_BUILD_OPTIONS+=("--output" "type=docker,dest=$INPUT_EXPORT_TAR") fi DOCKER_BUILD_OPTIONS+=("--rm") DOCKER_BUILD_OPTIONS+=("${INPUT_DOCKERFILE_PATH}") # shellcheck disable=SC2145 echo "Running docker buildx with options: ${DOCKER_BUILD_OPTIONS[@]}" echo "Building and pushing !" docker buildx build "${DOCKER_BUILD_OPTIONS[@]}" echo "Cleaning up docker" docker system prune --all --force --filter label!=ACT_IMAGE=true echo "imageName=${IMAGE_NAME}" >> "$GITEA_OUTPUT" exit 0