Loading Dockerfile +2 −1 Original line number Diff line number Diff line Loading @@ -22,9 +22,10 @@ RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o buildctl ./cmd/buildctl FROM alpine as buildctl ENV DOCKER_CONFIG=/etc/docker RUN mkdir -p $DOCKER_CONFIG RUN mkdir -p $DOCKER_CONFIG && apk add --no-cache jq COPY --from=go /src/buildctl /bin/ COPY entrypoint.buildctl.sh /bin/entrypoint COPY add-auth.sh /bin/add-auth ENTRYPOINT ["/bin/entrypoint"] Loading add-auth.sh 0 → 100755 +28 −0 Original line number Diff line number Diff line #!/bin/sh set -eu die() { echo "$USAGE"; echo "Fatal: $*"; exit 1; } USAGE="$0 REPOSITORY USERNAME REPOSITORY The image repository to authenticate against USERNAME The username to authenticate with The password to authenticate with will be read from STDIN " CONFIG=$DOCKER_CONFIG/config.json || die "DOCKER_CONFIG must be set in the environment" REPOSITORY=$1 || die "REPOSITORY is missing" USERNAME=$2 || die "USERNAME is missing" read -p "Enter password: " PASSWORD test -e "$CONFIG" || touch "$CONFIG" jq <"$CONFIG" >"$CONFIG.tmp" \ --slurp \ --arg repo "$REPOSITORY" \ --arg user "$USERNAME" \ --arg pass "$PASSWORD" \ '(if . == [] then {} else .[0] end) * {"auths": {($repo): {"username": ($user), "password": ($pass)}}}' mv "$CONFIG.tmp" "$CONFIG" entrypoint.buildctl.sh +2 −10 Original line number Diff line number Diff line Loading @@ -6,16 +6,8 @@ case ${1-help} in esac if [ -n "${CI_REGISTRY-}" ]; then tee >$DOCKER_CONFIG/config.json <<-END_JSON { "auths": { "$CI_REGISTRY": { "username": "$CI_REGISTRY_USER", "password": "$CI_REGISTRY_PASSWORD" } } } END_JSON echo "$CI_REGISTRY_PASSWORD" | /bin/add-auth "$CI_REGISTRY" "$CI_REGISTRY_USER" fi exec "$@" Loading
Dockerfile +2 −1 Original line number Diff line number Diff line Loading @@ -22,9 +22,10 @@ RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o buildctl ./cmd/buildctl FROM alpine as buildctl ENV DOCKER_CONFIG=/etc/docker RUN mkdir -p $DOCKER_CONFIG RUN mkdir -p $DOCKER_CONFIG && apk add --no-cache jq COPY --from=go /src/buildctl /bin/ COPY entrypoint.buildctl.sh /bin/entrypoint COPY add-auth.sh /bin/add-auth ENTRYPOINT ["/bin/entrypoint"] Loading
add-auth.sh 0 → 100755 +28 −0 Original line number Diff line number Diff line #!/bin/sh set -eu die() { echo "$USAGE"; echo "Fatal: $*"; exit 1; } USAGE="$0 REPOSITORY USERNAME REPOSITORY The image repository to authenticate against USERNAME The username to authenticate with The password to authenticate with will be read from STDIN " CONFIG=$DOCKER_CONFIG/config.json || die "DOCKER_CONFIG must be set in the environment" REPOSITORY=$1 || die "REPOSITORY is missing" USERNAME=$2 || die "USERNAME is missing" read -p "Enter password: " PASSWORD test -e "$CONFIG" || touch "$CONFIG" jq <"$CONFIG" >"$CONFIG.tmp" \ --slurp \ --arg repo "$REPOSITORY" \ --arg user "$USERNAME" \ --arg pass "$PASSWORD" \ '(if . == [] then {} else .[0] end) * {"auths": {($repo): {"username": ($user), "password": ($pass)}}}' mv "$CONFIG.tmp" "$CONFIG"
entrypoint.buildctl.sh +2 −10 Original line number Diff line number Diff line Loading @@ -6,16 +6,8 @@ case ${1-help} in esac if [ -n "${CI_REGISTRY-}" ]; then tee >$DOCKER_CONFIG/config.json <<-END_JSON { "auths": { "$CI_REGISTRY": { "username": "$CI_REGISTRY_USER", "password": "$CI_REGISTRY_PASSWORD" } } } END_JSON echo "$CI_REGISTRY_PASSWORD" | /bin/add-auth "$CI_REGISTRY" "$CI_REGISTRY_USER" fi exec "$@"