1+ name : DockerHub Push
2+
3+ description : Build and Push images (multiplatform) to Dockerhub.
4+
5+ inputs :
6+ docker_user :
7+ description : ' DockerHub username'
8+ required : true
9+ docker_token :
10+ description : ' DockerHub access token'
11+ required : true
12+
13+ repository :
14+ description : ' DockerHub repository name (username/repository)'
15+ required : true
16+ tag :
17+ description : ' Docker image tag'
18+ required : true
19+
20+ platforms :
21+ description : ' Comma-separated list of platforms'
22+ required : false
23+ default : ' linux/amd64,linux/arm64'
24+ build_args :
25+ description : ' JSON object with build arguments'
26+ required : false
27+ default : ' {}'
28+ artifact_name :
29+ description : ' Artifact name to download (if using artifacts)'
30+ required : false
31+ default : ' '
32+
33+ context_path :
34+ description : ' Docker build context path'
35+ required : false
36+ default : ' .'
37+ dockerfile_path :
38+ description : ' Path to Dockerfile relative to context'
39+ required : false
40+ default : ' Dockerfile'
41+
42+ runs :
43+ using : ' composite'
44+ steps :
45+ - name : Prepare context
46+ id : prepare-context
47+ shell : bash
48+ run : |
49+ if [ -n "${{ inputs.artifact_name }}" ]; then
50+ echo "using_artifact=true" >> $GITHUB_OUTPUT
51+ echo "context_path=./artifact/${{ inputs.context_path }}" >> $GITHUB_OUTPUT
52+ else
53+ echo "using_artifact=false" >> $GITHUB_OUTPUT
54+ echo "context_path=${{ inputs.context_path }}" >> $GITHUB_OUTPUT
55+ fi
56+
57+ - name : Checkout repository
58+ if : steps.prepare-context.outputs.using_artifact == 'false'
59+ uses : actions/checkout@v4
60+
61+ - name : Download artifact
62+ if : steps.prepare-context.outputs.using_artifact == 'true'
63+ uses : actions/download-artifact@v4
64+ with :
65+ name : ${{ inputs.artifact_name }}
66+ path : ./artifact
67+
68+ - name : Login to DockerHub
69+ uses : docker/login-action@v3
70+ with :
71+ username : ${{ inputs.docker_user }}
72+ password : ${{ inputs.docker_token }}
73+
74+ - name : Setup QEMU
75+ uses : docker/setup-qemu-action@v3
76+
77+ - name : Setup Docker Buildx
78+ uses : docker/setup-buildx-action@v3
79+ with :
80+ install : true
81+
82+ - name : Build and push
83+ shell : bash
84+ run : |
85+ BUILD_ARGS=""
86+ if [ "${{ inputs.build_args }}" != "{}" ]; then
87+ while IFS= read -r arg; do
88+ BUILD_ARGS="$BUILD_ARGS $arg"
89+ done < <(echo '${{ inputs.build_args }}' | jq -r 'to_entries | .[] | "--build-arg \(.key)=\(.value)"')
90+ fi
91+
92+ docker buildx build \
93+ --platform ${{ inputs.platforms }} \
94+ --file ${{ steps.prepare-context.outputs.context_path }}/${{ inputs.dockerfile_path }} \
95+ $BUILD_ARGS \
96+ -t ${{ inputs.repository }}:${{ inputs.tag }} \
97+ --push \
98+ ${{ steps.prepare-context.outputs.context_path }}
0 commit comments