From 7cb4bda424f4d5bcd7f1c87426159da4c95d88ca Mon Sep 17 00:00:00 2001 From: redxef Date: Wed, 9 Mar 2022 16:02:03 +0100 Subject: [PATCH] Add more configurations. --- ci/pipeline.yml | 28 +++++++++++++++++++++++ entrypoint.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/ci/pipeline.yml b/ci/pipeline.yml index adf11c2..d157999 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -17,6 +17,26 @@ jobs: trigger: true - get: upstream-image trigger: true + - task: compute-docker-tags: + config: + platform: linux + image_resource: + type: registry-image + source: + repository: alpine + inputs: + - name: source + path: . + outputs: + - name: docker-tags + run: + path: sh + args: + - -c + - | + #!/usr/bin/env sh + apk add --no-cache git + git rev-parse --short HEAD > docker-tags/tags.txt - task: build privileged: true config: @@ -28,9 +48,17 @@ jobs: inputs: - name: source path: . + - name: docker-tags params: username: ((docker.username)) password: ((docker.password)) + repository: docker.io/redxef/concourse-buildkit + tag: latest + additional_tags: docker-tags/tags.txt + push: true + platform: aarch64,arm,ppc64le,s390x,x86_64 + context: . + manual: false run: path: entrypoint.sh args: diff --git a/entrypoint.sh b/entrypoint.sh index 45e2ebc..7ffec1d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,6 +8,11 @@ DOCKER_LOGIN_FILE_TMPL='{ } }' +fail() { + echo "Error:" "$@" 1>&2 + exit 1 +} + docker_login() { # TODO: detect registry url mkdir -p "$HOME/.docker" @@ -18,7 +23,60 @@ docker_login() { } if [ -n "$username" ]; then + if [ -z "$password" ]; then + fail "need to also give password when logging in" + fi docker_login fi -buildctl-daemonless.sh "$@" +plain() { + buildctl-daemonless.sh "$@" +} + +build() { + if [ -z "$repository" ]; then + fail "missing argument: repository" + fi + if [ -z "$tag" ]; then + tag=latest + fi + if [ -z "$push" ]; then + push=false + fi + if [ -z "$context" ]; then + context=. + fi + if [ -z "$platform" ]; then + platform="" + else + platform="--opt platform=$platform" + fi + + final_tag="$repository:$tag" + if [ -z "$additional_tags" ]; then + while read -r line; do + if [ -z "$line" ]; then + continue + fi + final_tag="$final_tag,$repository:$line" + done < "$additional_tags" + fi + + buildctl-daemonless.sh \ + build \ + --frontend dockerfile.v0 \ + --local context="$context" \ + --local dockerfile="$context" \ + $platform \ + --output type=image,\""$final_tag"\",push="$push" +} + +if [ -z "$manual" ]; then + manual=false +fi + +if "$manual"; then + plain "$@" +else + build +fi