1
+ name : Build and Publish Docker Image
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ tag :
7
+ description : ' Release tag (e.g. v0.0.1)'
8
+ required : true
9
+ workflow_run :
10
+ workflows : ["Release Binary"]
11
+ types :
12
+ - completed
13
+
14
+ jobs :
15
+ build-and-push :
16
+ runs-on : ubuntu-latest
17
+ permissions :
18
+ contents : read
19
+ packages : write
20
+
21
+ strategy :
22
+ matrix :
23
+ platform : [linux/amd64, linux/arm64]
24
+
25
+ steps :
26
+ - name : Set release tag
27
+ run : |
28
+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
29
+ echo "RELEASE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
30
+ elif [[ "${{ github.event_name }}" == "workflow_run" ]]; then
31
+ echo "RELEASE_TAG=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
32
+ else
33
+ echo "RELEASE_TAG=unknown" >> $GITHUB_ENV
34
+ fi
35
+
36
+ - name : Validate RELEASE_TAG
37
+ run : |
38
+ if [[ -z "$RELEASE_TAG" || "$RELEASE_TAG" == "unknown" ]]; then
39
+ echo "Missing or invalid RELEASE_TAG"
40
+ exit 1
41
+ fi
42
+
43
+ - name : Checkout
44
+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
45
+
46
+ - name : Set up QEMU
47
+ uses : docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
48
+
49
+ - name : Set up Docker Buildx
50
+ uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
51
+
52
+ - name : Login to DockerHub
53
+ uses : docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
54
+ with :
55
+ username : ${{ secrets.DOCKERHUB_USERNAME }}
56
+ password : ${{ secrets.DOCKERHUB_TOKEN }}
57
+
58
+ - name : Transform platform for artifact name
59
+ run : |
60
+ OS="${{ matrix.platform%%/* }}"
61
+ ARCH="${{ matrix.platform##*/ }}"
62
+ # Capitalize OS first letter
63
+ OS="$(tr '[:lower:]' '[:upper:]' <<< ${OS:0:1})${OS:1}"
64
+ # Map arch amd64 → x86_64
65
+ if [ "$ARCH" = "amd64" ]; then ARCH="x86_64"; fi
66
+ SAFE_PLATFORM="${OS}_${ARCH}"
67
+ echo "SAFE_PLATFORM=$SAFE_PLATFORM" >> $GITHUB_ENV
68
+
69
+ - name : Download release artifact
70
+ run : |
71
+ TAG="${RELEASE_TAG}"
72
+ ARCHIVE="mcpd_${SAFE_PLATFORM}.tar.gz"
73
+ curl -L -o $ARCHIVE "https://github.com/${GITHUB_REPOSITORY}/releases/download/$TAG/$ARCHIVE"
74
+ tar -xf $ARCHIVE -C .
75
+
76
+ - name : Build & push Docker image
77
+ uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
78
+ with :
79
+ context : .
80
+ platforms : ${{ matrix.platform }}
81
+ push : true
82
+ tags : |
83
+ mzdotai/mcpd:${{ env.RELEASE_TAG }}-${{ env.SAFE_PLATFORM }}
84
+ mzdotai/mcpd:latest
85
+ build-args : |
86
+ MCPD_VERSION=${{ env.RELEASE_TAG }}
87
+ file : ./Dockerfile
0 commit comments