-
Notifications
You must be signed in to change notification settings - Fork 34
128 lines (113 loc) · 4.15 KB
/
Copy pathbuild_docker_images.yml
File metadata and controls
128 lines (113 loc) · 4.15 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
name: Build Docker images
on:
workflow_call:
inputs:
image-tag:
description: 'The primary tag for the image (e.g., latest, dev)'
required: true
type: string
version-tag:
description: 'The version tag (e.g., 1.2.3, 1.2.3-rc1)'
required: true
type: string
use-cache:
description: 'Whether to use GHA build cache'
required: false
type: boolean
default: false
secrets:
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_PASSWORD:
required: false
DOCKERHUB_ORGANIZATION:
required: false
env:
IMAGE_NAME: saic-mqtt-gateway
DOCKERHUB_IMAGE_NAME: saic-python-mqtt-gateway
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7
steps:
- uses: actions/checkout@v6
- name: Set platform slug
id: platform
run: echo "slug=$(echo '${{ matrix.platform }}' | tr '/' '-')" >> "$GITHUB_OUTPUT"
- name: Set repository lowercase
id: repo
run: echo "lowercase=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
build-args: |
RELEASE_VERSION=${{ inputs.version-tag }}
platforms: ${{ matrix.platform }}
push: true
provenance: false
cache-from: ${{ inputs.use-cache && 'type=gha' || '' }}
cache-to: ${{ inputs.use-cache && 'type=gha,mode=max' || '' }}
tags: |
ghcr.io/${{ steps.repo.outputs.lowercase }}/${{ env.IMAGE_NAME }}:${{ inputs.image-tag }}-${{ steps.platform.outputs.slug }}
merge:
runs-on: ubuntu-latest
needs: build
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ORGANIZATION: ${{ secrets.DOCKERHUB_ORGANIZATION == null && secrets.DOCKERHUB_USERNAME || secrets.DOCKERHUB_ORGANIZATION }}
steps:
- name: Set repository lowercase
id: repo
run: echo "lowercase=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Login to Docker Hub
uses: docker/login-action@v4
if: env.DOCKERHUB_USERNAME != null
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Create GHCR multi-arch manifest
run: |
GHCR_BASE="ghcr.io/${{ steps.repo.outputs.lowercase }}/${{ env.IMAGE_NAME }}"
for tag in "${{ inputs.image-tag }}" "${{ inputs.version-tag }}"; do
docker buildx imagetools create -t "${GHCR_BASE}:${tag}" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-amd64" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-arm64" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-arm-v7"
done
- name: Create DockerHub multi-arch manifest
if: env.DOCKERHUB_ORGANIZATION != null
run: |
GHCR_BASE="ghcr.io/${{ steps.repo.outputs.lowercase }}/${{ env.IMAGE_NAME }}"
DH_BASE="${{ env.DOCKERHUB_ORGANIZATION }}/${{ env.DOCKERHUB_IMAGE_NAME }}"
for tag in "${{ inputs.image-tag }}" "${{ inputs.version-tag }}"; do
docker buildx imagetools create -t "${DH_BASE}:${tag}" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-amd64" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-arm64" \
"${GHCR_BASE}:${{ inputs.image-tag }}-linux-arm-v7"
done