From c185a04ec108f6cf957dfccb7251a5df92613b38 Mon Sep 17 00:00:00 2001 From: redxef Date: Mon, 29 Aug 2022 18:28:23 +0200 Subject: [PATCH] WIP/POC: Initial commit. --- Dockerfile | 4 +++ ci/pipeline.yml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ src/check | 11 ++++++++ src/common | 11 ++++++++ src/in | 11 ++++++++ src/out | 11 ++++++++ 6 files changed, 115 insertions(+) create mode 100644 Dockerfile create mode 100644 ci/pipeline.yml create mode 100755 src/check create mode 100755 src/common create mode 100755 src/in create mode 100755 src/out diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..65bd377 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM gcr.io/go-containerregistry/crane as crane +FROM alpine +COPY --from=crane /ko-app/crane /usr/local/bin/crane +RUN apk add --no-cache jq diff --git a/ci/pipeline.yml b/ci/pipeline.yml new file mode 100644 index 0000000..80437fb --- /dev/null +++ b/ci/pipeline.yml @@ -0,0 +1,67 @@ +--- +resources: +- name: source + type: git + source: + uri: https://gitea.redxef.at/redxef/concourse-oci-resource + branch: master + fetch_tags: true +- name: upstream-image + type: registry-image + source: + repository: alpine + +jobs: +- name: build-push + plan: + - get: source + trigger: true + - get: upstream-image + trigger: true + - task: compute-docker-tags + config: + platform: linux + image_resource: + type: registry-image + source: + repository: alpine/git + inputs: + - name: source + path: . + outputs: + - name: docker-tags + run: + path: sh + args: + - -c + - | + #!/usr/bin/env sh + git rev-parse --short HEAD > docker-tags/tags.txt + git show-ref --tags | \ + sed -n "/$(git rev-parse HEAD)/ s|$(git rev-parse HEAD).refs/tags/||gp" \ + >> docker-tags/tags.txt + - task: build + privileged: true + config: + platform: linux + image_resource: + type: registry-image + source: + repository: redxef/concourse-buildkit + tag: v0.2.1 + inputs: + - name: source + path: . + - name: docker-tags + params: + username: ((docker.username)) + password: ((docker.password)) + repository: docker.io/redxef/concourse-oci-resource + tag: latest + additional_tags: docker-tags/tags.txt + push: true + platform: aarch64,arm,ppc64le,s390x,x86_64 + context: . + manual: false + run: + path: build diff --git a/src/check b/src/check new file mode 100755 index 0000000..64d13c3 --- /dev/null +++ b/src/check @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -eu + +. ./common + +jq -r tostring << EOF +[ + $(crane digest "$REPOSITORY:$TAG") +] +EOF diff --git a/src/common b/src/common new file mode 100755 index 0000000..c0c174a --- /dev/null +++ b/src/common @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +INPUT_FILE="$(mktemp -t)" +cat > "$INPUT_FILE" <&0 +export INPUT_FILE + +REPOSITORY="$(jq -r .source.repository < "$INPUT_FILE")" +TAG="$(jq -r .source.tag < "$INPUT_FILE")" + +export REPOSITORY +export TAG diff --git a/src/in b/src/in new file mode 100755 index 0000000..4b91c11 --- /dev/null +++ b/src/in @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -eu + +. ./common + +oci_dir="$(mktemp -d)" +crane pull --format=oci "$REPOSITORY:@$(jq -r .version "$INPUT_FILE")" "$oci_dir" +pushd "$oci_dir" && tar cf "$1/image.tar" && popd + +echo "$(jq -r .version < "$INPUT_FILE")" diff --git a/src/out b/src/out new file mode 100755 index 0000000..0c2b773 --- /dev/null +++ b/src/out @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -eu + +. ./common + +IMAGE_REFS_FILE="$(mktemp -t)" +oci_dir="$(mktemp -d)" +pushd "$oci_dir" && tar xf "$1/$(jq -r .params.image < "$INPUT_FILE")" && popd +crane push "$1" "$REPOSITORY:$TAG" --image-refs="$IMAGE_REFS_FILE" +sed 's/^[^@]*@//' < "$IMAGE_REFS_FILE"