Skip to content

Commit 8a4c371

Browse files
committed
Use buildx imagetools create
1 parent 8544455 commit 8a4c371

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ on:
1414
jobs:
1515
dockerhub-mirror:
1616
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
dry-run:
21+
- false
22+
- true
1723
services:
1824
registry:
1925
image: registry:2
@@ -46,3 +52,4 @@ jobs:
4652
dockerhub-repo: crazymax/diun
4753
dest-registry: localhost:5000
4854
dest-repo: name/app
55+
dry-run: ${{ matrix.dry-run }}

action.yml

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,11 @@ runs:
4040
DOCKER_DEST_REGISTRY=${{ inputs.dest-registry }}
4141
DOCKER_DEST_REPO=${{ inputs.dest-repo }}
4242
43-
PUSH_FLAG=""
43+
DRYRUN_FLAG="--dry-run"
4444
if [ "${{ inputs.dry-run }}" = "false" ]; then
45-
PUSH_FLAG="--push"
45+
DRYRUN_FLAG=""
4646
fi
4747
48-
function get_platforms() {
49-
local images=${1}
50-
platforms=""
51-
for image in $images; do
52-
_jq() {
53-
echo "${image}" | base64 --decode | jq -r "${1}"
54-
}
55-
os=$(_jq '.os')
56-
arch=$(_jq '.architecture')
57-
variant=$(_jq '.variant')
58-
platform="$os/$arch"
59-
if [ -n "$variant" ] && [ "$variant" != "null" ]; then
60-
platform="$platform/$variant"
61-
fi
62-
if [ -n "$platforms" ]; then
63-
platforms="$platforms,"
64-
fi
65-
platforms="$platforms$platform"
66-
done
67-
echo "$platforms"
68-
}
69-
7048
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)
7149
if [ -z "${TOKEN}" -o "${TOKEN}" == "null" ]; then
7250
echo >&2 "error: cannot retrieve token"
@@ -79,15 +57,13 @@ runs:
7957
echo "${TAG}" | base64 --decode | jq -r ${1}
8058
}
8159
TAG_NAME=$(_jq '.name')
82-
TAG_IMAGES=$(echo "$(_jq '.images')" | jq -r '.[] | @base64')
83-
TAG_PLATFORMS=$(get_platforms "${TAG_IMAGES}")
84-
echo "::group::Copying ${DOCKERHUB_REPO}:${TAG_NAME} to ${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}"
85-
echo "FROM --platform=\${TARGETPLATFORM:-linux/amd64} ${DOCKERHUB_REPO}:${TAG_NAME}" > Dockerfile.tmp
86-
docker buildx build \
87-
${PUSH_FLAG} \
88-
--platform "${TAG_PLATFORMS}" \
89-
--tag "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" \
90-
--file ./Dockerfile.tmp .
60+
echo "::group::Copying ${DOCKERHUB_REPO}:${TAG_NAME} to ${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}"
61+
set -x
62+
docker buildx imagetools create ${DRYRUN_FLAG} --tag "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}" "${DOCKERHUB_REPO}:${TAG_NAME}"
63+
set +x
64+
if [ "${{ inputs.dry-run }}" = "false" ]; then
65+
docker buildx imagetools inspect "${DOCKER_DEST_REGISTRY}/${DOCKER_DEST_REPO}:${TAG_NAME}"
66+
fi
9167
echo "::endgroup"
9268
done
9369
shell: bash

0 commit comments

Comments
 (0)