From 248cb76ac6f4d4caec0d57fc7cfaefdffabe98b5 Mon Sep 17 00:00:00 2001 From: redxef Date: Wed, 9 Mar 2022 14:19:24 +0100 Subject: [PATCH] Add docker login. --- Dockerfile | 1 + entrypoint.sh | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4a35063..a143724 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ FROM moby/buildkit +COPY entrypoint.sh /usr/local/bin/entrypoint.sh ENTRYPOINT [ "entrypoint.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh index 5180792..45e2ebc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,24 @@ #!/usr/bin/env sh -buildctl-deamonless.sh +DOCKER_LOGIN_FILE_TMPL='{ + "auths": { + "{{REGISTRY_URL}}": { + "auth": "{{BASE64_UNAME_PW}}" + } + } +}' -"$@" +docker_login() { + # TODO: detect registry url + mkdir -p "$HOME/.docker" + echo "$DOCKER_LOGIN_FILE_TMPL" | \ + sed -e "s|{{BASE64_UNAME_PW}}|$(printf '%s:%s' "$username" "$password" | base64)|g" \ + -e "s|{{REGISTRY_URL}}|https://index.docker.io/v1/|g" \ + > "$HOME/.docker/config.json" +} + +if [ -n "$username" ]; then + docker_login +fi + +buildctl-daemonless.sh "$@"