-
Notifications
You must be signed in to change notification settings - Fork 26
67 lines (61 loc) · 1.92 KB
/
_shared-docker-clone.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Reusable docker clone workflow
on:
workflow_call:
inputs:
source_repository:
description: 'Source Docker Hub Repository'
default: ''
required: false
type: string
target_repository:
description: 'Target Docker Hub Repository'
default: ''
required: false
type: string
tags:
description: 'Docker Image Tags (JSON)'
default: ''
required: false
type: string
secrets:
DOCKERHUB_USERNAME:
description: 'Docker Hub Username'
required: false
DOCKERHUB_TOKEN:
description: 'Docker Hub Token'
required: false
# shared build jobs
jobs:
clone_docker_images:
name: Clone docker images to ${{ inputs.target_repository }}
if: ${{ inputs.tags }}
runs-on: ubuntu-latest
strategy:
matrix:
tag: ${{ fromJSON(inputs.tags) }}
steps:
# prepare docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get tag names
id: tags
run: |
tagstr="${{ matrix.tag }}"
tagparts=(${tagstr//:/ })
echo "source_tag=${tagparts[0]}" >> $GITHUB_OUTPUT
if [ -z "${tagparts[1]}" ]; then
echo "target_tag=${tagparts[0]}" >> $GITHUB_OUTPUT
else
echo "target_tag=${tagparts[1]}" >> $GITHUB_OUTPUT
fi
# build multiarch image
- name: "Copy docker image: ${{ steps.tags.outputs.target_tag }}"
run: |
docker buildx imagetools create -t ${{ inputs.target_repository }}:${{ steps.tags.outputs.target_tag }} \
${{ inputs.source_repository }}:${{ steps.tags.outputs.source_tag }}-amd64 \
${{ inputs.source_repository }}:${{ steps.tags.outputs.source_tag }}-arm64