blob: 63e62bd0bda7ba503839b99bafe11caad36488e1 [file] [log] [blame]
Eric Ballb31722a2026-06-09 18:07:26 -07001---
2# SPDX-FileCopyrightText: 2026 The Linux Foundation
3# SPDX-License-Identifier: Apache-2.0
4
5name: Docker Publish
6description: "Build and push Docker images tagged with branch name and git tags"
7
8inputs:
9 docker-registry:
10 description: "Docker registry URL"
11 required: false
12 default: "docker.io"
13 docker-repository:
14 description: "Docker repository prefix"
15 required: true
16 image-name:
17 description: "Name of the Docker image"
18 required: true
19 branch-tag:
20 description: "Branch name to use as a Docker image tag"
21 required: true
22 extra-environment-vars:
23 description: "Extra environment variables for make commands"
24 required: false
25 default: ""
26 docker-username:
27 description: "Docker registry username"
28 required: true
29 docker-password:
30 description: "Docker registry password"
31 required: true
32
33runs:
34 using: "composite"
35 steps:
36 - name: Log in to Docker registry
37 uses: docker/login-action@v3
38 with:
39 registry: ${{ inputs.docker-registry }}
40 username: ${{ inputs.docker-username }}
41 password: ${{ inputs.docker-password }}
42
43 - name: Get git tags on HEAD
44 id: git-tags
45 shell: bash
46 run: |
47 set -eu -o pipefail
48 TAGS=$(git tag --points-at HEAD || true)
49 echo "tags<<EOF" >> "$GITHUB_OUTPUT"
50 echo "$TAGS" >> "$GITHUB_OUTPUT"
51 echo "EOF" >> "$GITHUB_OUTPUT"
52
53 - name: Build Docker image with branch tag
54 shell: bash
55 run: |
56 set -eu -o pipefail
57 DOCKER_REGISTRY="${{ inputs.docker-registry }}"
58 DOCKER_REPOSITORY="${{ inputs.docker-repository }}"
59 IMAGE_NAME="${{ inputs.image-name }}"
60 BRANCH_NAME="${{ inputs.branch-tag }}"
61
62 echo "Building image with branch tag: ${BRANCH_NAME}"
63 ${{ inputs.extra-environment-vars }} \
64 DOCKER_TAG="${BRANCH_NAME}" \
65 DOCKER_REGISTRY="${DOCKER_REGISTRY}" \
66 DOCKER_REPOSITORY="${DOCKER_REPOSITORY}" \
67 IMAGE_NAME="${IMAGE_NAME}" \
68 make docker-build
69
70 - name: Build Docker images for git tags
71 shell: bash
72 run: |
73 set -eu -o pipefail
74 DOCKER_REGISTRY="${{ inputs.docker-registry }}"
75 DOCKER_REPOSITORY="${{ inputs.docker-repository }}"
76 IMAGE_NAME="${{ inputs.image-name }}"
77
78 TAGS='${{ steps.git-tags.outputs.tags }}'
79 if [ -z "$TAGS" ]; then
80 echo "No git tags on HEAD, skipping tag builds"
81 exit 0
82 fi
83
84 while IFS= read -r tag; do
85 [ -z "$tag" ] && continue
86 # Strip leading 'v' from golang-style version tags
87 DOCKER_TAG="${tag#v}"
88 echo "Building image with tag: ${DOCKER_TAG}"
89 ${{ inputs.extra-environment-vars }} \
90 DOCKER_TAG="${DOCKER_TAG}" \
91 DOCKER_REGISTRY="${DOCKER_REGISTRY}" \
92 DOCKER_REPOSITORY="${DOCKER_REPOSITORY}" \
93 IMAGE_NAME="${IMAGE_NAME}" \
94 make docker-build
95 done <<< "$TAGS"
96
97 - name: Push Docker image with branch tag
98 shell: bash
99 run: |
100 set -eu -o pipefail
101 DOCKER_REGISTRY="${{ inputs.docker-registry }}"
102 DOCKER_REPOSITORY="${{ inputs.docker-repository }}"
103 IMAGE_NAME="${{ inputs.image-name }}"
104 BRANCH_NAME="${{ inputs.branch-tag }}"
105
106 echo "Pushing image with branch tag: ${BRANCH_NAME}"
107 ${{ inputs.extra-environment-vars }} \
108 DOCKER_TAG="${BRANCH_NAME}" \
109 DOCKER_REGISTRY="${DOCKER_REGISTRY}" \
110 DOCKER_REPOSITORY="${DOCKER_REPOSITORY}" \
111 IMAGE_NAME="${IMAGE_NAME}" \
112 make docker-push
113
114 - name: Push Docker images for git tags
115 shell: bash
116 run: |
117 set -eu -o pipefail
118 DOCKER_REGISTRY="${{ inputs.docker-registry }}"
119 DOCKER_REPOSITORY="${{ inputs.docker-repository }}"
120 IMAGE_NAME="${{ inputs.image-name }}"
121
122 TAGS='${{ steps.git-tags.outputs.tags }}'
123 if [ -z "$TAGS" ]; then
124 echo "No git tags on HEAD, skipping tag pushes"
125 exit 0
126 fi
127
128 while IFS= read -r tag; do
129 [ -z "$tag" ] && continue
130 # Strip leading 'v' from golang-style version tags
131 DOCKER_TAG="${tag#v}"
132 echo "Pushing image with tag: ${DOCKER_TAG}"
133 ${{ inputs.extra-environment-vars }} \
134 DOCKER_TAG="${DOCKER_TAG}" \
135 DOCKER_REGISTRY="${DOCKER_REGISTRY}" \
136 DOCKER_REPOSITORY="${DOCKER_REPOSITORY}" \
137 IMAGE_NAME="${IMAGE_NAME}" \
138 make docker-push
139 done <<< "$TAGS"
140
141 - name: Log out of Docker registry
142 if: always()
143 shell: bash
144 run: docker logout "${{ inputs.docker-registry }}"