Skip to content

Commit 8d4fe55

Browse files
committed
Docker release action
1 parent 142bb4f commit 8d4fe55

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

.github/workflows/release-docker.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ FROM ghcr.io/astral-sh/uv:0.7.20 AS uv-builder
1111
# ==============================================================================
1212
FROM node:current-alpine3.22
1313

14+
ARG MCPD_VERSION=unknown
15+
1416
# --- Metadata ---
1517
# The version label should be dynamically overridden in a CI/CD pipeline
1618
# (e.g., --label "org.opencontainers.image.version=${GIT_TAG}").
1719
LABEL org.opencontainers.image.authors="Mozilla AI <[email protected]>"
1820
LABEL org.opencontainers.image.description="A container for the mcpd application."
19-
LABEL org.opencontainers.image.version="1.0.0"
21+
LABEL org.opencontainers.image.version=$MCPD_VERSION
2022

2123
ARG MCPD_USER=mcpd
2224
ARG MCPD_HOME=/home/$MCPD_USER

internal/cmd/basecmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424

2525
// Version is used by other packages to retrieve the build version of mcpd.
2626
func Version() string {
27-
return fmt.Sprintf("mcpd %s (%s), built %s", version, commit, date)
27+
return fmt.Sprintf("mcpd v%s (%s), built %s", version, commit, date)
2828
}
2929

3030
// AppName returns the name of the mcpd application.

0 commit comments

Comments
 (0)