add setup-kaniko-auth.sh

This commit is contained in:
Haitao Pan 2024-03-05 23:42:15 +08:00
parent 5833c1a1f2
commit 054533f574
2 changed files with 28 additions and 1 deletions

View File

@ -13,7 +13,9 @@ FROM alpine:latest AS prod
WORKDIR /src/
RUN apk --no-cache add ca-certificates git && mkdir -pv /kaniko/
COPY --from=builder /src/go/bin/executor /kaniko/
COPY setup-kaniko-auth.sh /kaniko/setup-kaniko-auth.sh
RUN apk --no-cache add ca-certificates git && \
chmod +x /kaniko/setup-kaniko-auth.sh
ENTRYPOINT ["/bin/sh"]

View File

@ -0,0 +1,25 @@
#!/bin/bash
REGISTRY_ADDR=$1
REGISTRY_REPO_USER=$2
REGISTRY_REPO_PASSWORD=$3
DEBUG=${4:-false}
check_non_empty() {
if [ -z "$1" ]; then
echo "Error: $2 must be provided."
exit 1
fi
}
check_non_empty "$REGISTRY_ADDR" "Registry address"
check_non_empty "$REGISTRY_REPO_USER" "Registry username"
check_non_empty "$REGISTRY_REPO_PASSWORD" "Registry password"
mkdir -p /kaniko/.docker
AUTH=$(echo -n "${REGISTRY_REPO_USER}:${REGISTRY_REPO_PASSWORD}" | base64)
echo "{\"auths\":{\"https://${REGISTRY_ADDR}/v1/\":{\"auth\":\"${AUTH}\"}}}" > /kaniko/.docker/config.json
if [ "$DEBUG" = "true" ]; then
cat /kaniko/.docker/config.json
fi