From 8a4c371b4c044a89b7a381d2efeb77bb9810f5d9 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 18 Dec 2020 10:39:19 +0100 Subject: [PATCH] Use buildx imagetools create --- .github/workflows/ci.yml | 7 +++++++ action.yml | 42 +++++++++------------------------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d54f1fb..4c837ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,12 @@ on: jobs: dockerhub-mirror: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + dry-run: + - false + - true services: registry: image: registry:2 @@ -46,3 +52,4 @@ jobs: dockerhub-repo: crazymax/diun dest-registry: localhost:5000 dest-repo: name/app + dry-run: ${{ matrix.dry-run }} diff --git a/action.yml b/action.yml index 613275d..cdbca77 100644 --- a/action.yml +++ b/action.yml @@ -40,33 +40,11 @@ runs: DOCKER_DEST_REGISTRY=${{ inputs.dest-registry }} DOCKER_DEST_REPO=${{ inputs.dest-repo }} - PUSH_FLAG="" + DRYRUN_FLAG="--dry-run" if [ "${{ inputs.dry-run }}" = "false" ]; then - PUSH_FLAG="--push" + DRYRUN_FLAG="" fi - function get_platforms() { - local images=${1} - platforms="" - for image in $images; do - _jq() { - echo "${image}" | base64 --decode | jq -r "${1}" - } - os=$(_jq '.os') - arch=$(_jq '.architecture') - variant=$(_jq '.variant') - platform="$os/$arch" - if [ -n "$variant" ] && [ "$variant" != "null" ]; then - platform="$platform/$variant" - fi - if [ -n "$platforms" ]; then - platforms="$platforms," - fi - platforms="$platforms$platform" - done - echo "$platforms" - } - TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${DOCKERHUB_USERNAME}'", "password": "'${DOCKERHUB_PASSWORD}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token) if [ -z "${TOKEN}" -o "${TOKEN}" == "null" ]; then echo >&2 "error: cannot retrieve token" @@ -79,15 +57,13 @@ runs: echo "${TAG}" | base64 --decode | jq -r ${1} } TAG_NAME=$(_jq '.name') - TAG_IMAGES=$(echo "$(_jq '.images')" | jq -r '.[] | @base64') - TAG_PLATFORMS=$(get_platforms "${TAG_IMAGES}") - echo "::group::Copying ${DOCKERHUB_REPO}:${TAG_NAME} to ${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}" - echo "FROM --platform=\${TARGETPLATFORM:-linux/amd64} ${DOCKERHUB_REPO}:${TAG_NAME}" > Dockerfile.tmp - docker buildx build \ - ${PUSH_FLAG} \ - --platform "${TAG_PLATFORMS}" \ - --tag "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" \ - --file ./Dockerfile.tmp . + echo "::group::Copying ${DOCKERHUB_REPO}:${TAG_NAME} to ${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" + set -x + docker buildx imagetools create ${DRYRUN_FLAG} --tag "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" "${DOCKERHUB_REPO}:${TAG_NAME}" + set +x + if [ "${{ inputs.dry-run }}" = "false" ]; then + docker buildx imagetools inspect "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" + fi echo "::endgroup" done shell: bash