Skip to content

Commit

Permalink
Add labels to container image and refresh build-image.sh
Browse files Browse the repository at this point in the history
On-behalf-of: SAP <[email protected]>
Signed-off-by: Marvin Beckers <[email protected]>
  • Loading branch information
embik committed Jan 17, 2025
1 parent 45f790c commit 7332a73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
LABEL org.opencontainers.image.source=https://github.com/kcp-dev/kcp-operator
LABEL org.opencontainers.image.description="A Kubernetes operator to set up and manage kcp instances"
LABEL org.opencontainers.image.licenses=Apache-2.0

WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
Expand Down
31 changes: 21 additions & 10 deletions hack/ci/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -euo pipefail

# make git available
if ! [ -x "$(command -v git)" ]; then
echo "Installing git ..."
echo "Installing git"
dnf install -y git
fi

Expand All @@ -27,7 +27,7 @@ if [ -n "${DOCKER_REGISTRY_MIRROR_ADDR:-}" ]; then
# remove "http://" or "https://" prefix
mirror="$(echo "$DOCKER_REGISTRY_MIRROR_ADDR" | awk -F// '{print $NF}')"

echo "Configuring registry mirror for docker.io ..."
echo "Configuring registry mirror for docker.io"

cat <<EOF > /etc/containers/registries.conf.d/mirror.conf
[[registry]]
Expand Down Expand Up @@ -65,13 +65,13 @@ if [ -z "$version" ]; then
fi

image="$repository:$version"
echo "Building container image $image ..."
echo "Building container image $image"

# build image for all architectures
for arch in $architectures; do
fullTag="$image-$arch"

echo "Building $version-$arch ..."
echo "Building $version-$arch"
buildah build-using-dockerfile \
--file Dockerfile \
--tag "$fullTag" \
Expand All @@ -83,8 +83,19 @@ for arch in $architectures; do
.
done

echo "Creating manifest $image ..."
buildah manifest create "$image"
function create_manifest() {
local name="$1"

# deleting the previous manifest makes it possible to re-run this script locally
if buildah manifest exists "$name"; then
buildah manifest rm "$name"
fi

buildah manifest create "$name"
}

echo "Creating manifest $image"
create_manifest "$image"
for arch in $architectures; do
buildah manifest add "$image" "$image-$arch"
done
Expand All @@ -96,19 +107,19 @@ done
if [ -n "$branchName" ]; then
branchImage="$repository:$branchName"

echo "Creating manifest $branchImage ..."
buildah manifest create "$branchImage"
echo "Creating manifest $branchImage"
create_manifest "$branchImage"
for arch in $architectures; do
buildah manifest add "$branchImage" "$image-$arch"
done
fi

# push manifest, except in presubmits
if [ -z "${DRY_RUN:-}" ]; then
echo "Logging into GHCR ..."
echo "Logging into GHCR"
buildah login --username "$KCP_GHCR_USERNAME" --password "$KCP_GHCR_PASSWORD" ghcr.io

echo "Pushing manifest and images ..."
echo "Pushing manifest and images"
buildah manifest push --all "$image" "docker://$image"

if [ -n "${branchImage:-}" ]; then
Expand Down

0 comments on commit 7332a73

Please sign in to comment.