11name : Docker Build - ghcr
2- description : Build image using buildx
2+ description : Build image using buildx. Supports pushing to a registry or exporting to an output.
33inputs :
44 docker-file :
55 required : true
@@ -11,43 +11,55 @@ inputs:
1111 required : true
1212 description : Image tag
1313 github-token :
14- required : true
15- description : GitHub token for login
14+ required : false
15+ description : GitHub token for registry login. Required when push is true.
16+ default : ' '
1617 registry :
1718 required : true
18- description : Container registry (e.g., ghcr.io/llm-d)
19+ description : GHCR namespace (e.g., ghcr.io/llm-d)
1920 prerelease :
20- required : true
21+ required : false
2122 description : indicates whether or not this is a pre-release (not a release) build
23+ default : ' false'
24+ push :
25+ required : false
26+ description : Push the built image to the registry. Set to false to export via buildx-outputs instead.
27+ default : ' true'
28+ buildx-outputs :
29+ required : false
30+ description : Buildx outputs value when push is false, such as type=docker,dest=<path>/image.tar.
31+ default : ' '
32+ commit-sha :
33+ required : false
34+ description : Git commit SHA to embed via COMMIT_SHA build arg
35+ default : ' '
2236runs :
2337 using : " composite"
2438 steps :
2539 - name : Set up Docker Buildx
2640 uses : docker/setup-buildx-action@v4
2741
2842 - name : Login to GitHub Container Registry
29- run : echo "${{ inputs.github-token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
30- shell : bash
31-
32- - name : Print image info
33- run : |
34- echo "Image name: ${{ inputs.image-name }}"
35- echo "Tag: ${{ inputs.tag }}"
36- echo "Registry: ${{ inputs.registry }}"
37- shell : bash
43+ if : inputs.push == 'true'
44+ uses : docker/login-action@v4
45+ with :
46+ registry : ghcr.io
47+ username : ${{ github.actor }}
48+ password : ${{ inputs.github-token }}
3849
39- - name : Build image and push
40- run : |
41- if [[ ${{ inputs.prerelease }} == "true" ]]; then
42- LATEST_TAG=""
43- else
44- LATEST_TAG="-t ${{ inputs.registry }}/${{ inputs.image-name }}:latest"
45- fi
46- docker buildx build \
47- --platform linux/amd64,linux/arm64 \
48- --cache-from type=gha,scope=${{ inputs.image-name }} \
49- --cache-to type=gha,mode=max,scope=${{ inputs.image-name }} \
50- --build-arg LDFLAGS="-s -w" \
51- -t ${{ inputs.registry }}/${{ inputs.image-name }}:${{ inputs.tag }} \
52- ${LATEST_TAG} -f ${{ inputs.docker-file }} --push .
53- shell : bash
50+ - name : Build image
51+ uses : docker/build-push-action@v6
52+ with :
53+ file : ${{ inputs.docker-file }}
54+ push : ${{ inputs.push == 'true' }}
55+ outputs : ${{ inputs.buildx-outputs }}
56+ platforms : ${{ inputs.push != 'true' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
57+ tags : |
58+ ${{ inputs.registry }}/${{ inputs.image-name }}:${{ inputs.tag }}
59+ ${{ inputs.push == 'true' && inputs.prerelease != 'true' && format('{0}/{1}:latest', inputs.registry, inputs.image-name) || '' }}
60+ build-args : |
61+ LDFLAGS=-s -w
62+ COMMIT_SHA=${{ inputs.commit-sha || 'unknown' }}
63+ BUILD_REF=${{ inputs.tag || 'unknown' }}
64+ cache-from : type=gha,scope=${{ inputs.image-name }}
65+ cache-to : type=gha,mode=max,scope=${{ inputs.image-name }}
0 commit comments