Skip to content

Commit aaf6eb4

Browse files
committed
Build and publish Docker image to GHCR after each upstream sync
Triggers on clean auto-merges to master and on merge of conflict- resolution PRs (detected by sync/upstream-v* branch name). Also available as a manual dispatch for on-demand rebuilds. Images are published to ghcr.io/decode-development/metabase-teal tagged with both the upstream version and latest.
1 parent 6eba0de commit aaf6eb4

2 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Build and Publish Docker Image
2+
3+
# Triggers:
4+
# 1. Push to master whose commit message starts with "chore: sync upstream v..."
5+
# (i.e. a clean auto-merge from teal-sync-upstream-release.yml)
6+
# 2. A pull_request from a sync/upstream-v* branch is merged to master
7+
# (i.e. a conflict resolution PR from teal-sync-upstream-release.yml)
8+
# 3. Manual dispatch — useful for rebuilding any version on demand.
9+
10+
on:
11+
push:
12+
branches:
13+
- master
14+
pull_request:
15+
types: [closed]
16+
workflow_dispatch:
17+
inputs:
18+
version:
19+
description: "Upstream version tag to label the image (e.g. v0.53.2). Defaults to the current latest upstream release."
20+
required: false
21+
22+
jobs:
23+
# ── Resolve whether this run should produce a build, and which version tag ──
24+
25+
resolve:
26+
name: Resolve version
27+
runs-on: ubuntu-latest
28+
outputs:
29+
should_build: ${{ steps.resolve.outputs.should_build }}
30+
version: ${{ steps.resolve.outputs.version }}
31+
steps:
32+
- name: Determine version and build gate
33+
id: resolve
34+
env:
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
EVENT="${{ github.event_name }}"
38+
39+
if [[ "$EVENT" == "workflow_dispatch" ]]; then
40+
VERSION="${{ inputs.version }}"
41+
if [[ -z "$VERSION" ]]; then
42+
VERSION=$(gh api repos/metabase/metabase/releases/latest --jq '.tag_name')
43+
fi
44+
echo "should_build=true" >> "$GITHUB_OUTPUT"
45+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
46+
echo "Manual dispatch — building $VERSION"
47+
48+
elif [[ "$EVENT" == "push" ]]; then
49+
COMMIT_MSG="${{ github.event.head_commit.message }}"
50+
if [[ "$COMMIT_MSG" =~ ^chore:\ sync\ upstream\ (v[0-9]+\.[0-9x.]+) ]]; then
51+
VERSION="${BASH_REMATCH[1]}"
52+
echo "should_build=true" >> "$GITHUB_OUTPUT"
53+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
54+
echo "Sync commit detected — building $VERSION"
55+
else
56+
echo "should_build=false" >> "$GITHUB_OUTPUT"
57+
echo "Not a sync commit — skipping."
58+
fi
59+
60+
elif [[ "$EVENT" == "pull_request" ]]; then
61+
MERGED="${{ github.event.pull_request.merged }}"
62+
BRANCH="${{ github.event.pull_request.head.ref }}"
63+
64+
if [[ "$MERGED" == "true" ]] && [[ "$BRANCH" =~ ^sync/upstream-v ]]; then
65+
VERSION=$(echo "$BRANCH" | grep -oP 'v[0-9]+\.[0-9x.]+' || true)
66+
if [[ -z "$VERSION" ]]; then
67+
VERSION=$(gh api repos/metabase/metabase/releases/latest --jq '.tag_name')
68+
fi
69+
echo "should_build=true" >> "$GITHUB_OUTPUT"
70+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
71+
echo "Upstream-sync PR merged — building $VERSION"
72+
else
73+
echo "should_build=false" >> "$GITHUB_OUTPUT"
74+
echo "PR is not a merged upstream-sync — skipping."
75+
fi
76+
fi
77+
78+
# ── Build the Docker image and push to GHCR ──
79+
80+
build-and-push:
81+
name: Build and push to GHCR
82+
needs: resolve
83+
if: needs.resolve.outputs.should_build == 'true'
84+
runs-on: ubuntu-latest
85+
timeout-minutes: 90
86+
permissions:
87+
contents: read
88+
packages: write
89+
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v4
93+
94+
# Docker image names must be lowercase; github.repository preserves case.
95+
- name: Normalise image name
96+
id: image
97+
run: |
98+
echo "name=ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" \
99+
>> "$GITHUB_OUTPUT"
100+
101+
- name: Set up Docker Buildx
102+
uses: docker/setup-buildx-action@v3
103+
104+
- name: Log in to GHCR
105+
uses: docker/login-action@v3
106+
with:
107+
registry: ghcr.io
108+
username: ${{ github.actor }}
109+
password: ${{ secrets.GITHUB_TOKEN }}
110+
111+
- name: Build and push
112+
uses: docker/build-push-action@v6
113+
with:
114+
context: .
115+
push: true
116+
build-args: |
117+
MB_EDITION=oss
118+
VERSION=${{ needs.resolve.outputs.version }}
119+
tags: |
120+
${{ steps.image.outputs.name }}:${{ needs.resolve.outputs.version }}
121+
${{ steps.image.outputs.name }}:latest
122+
# Layer cache stored in GitHub Actions cache — speeds up subsequent builds
123+
# significantly since the apt/JDK/Clojure install layers rarely change.
124+
cache-from: type=gha
125+
cache-to: type=gha,mode=max
126+
127+
- name: Summary
128+
run: |
129+
IMAGE="${{ steps.image.outputs.name }}"
130+
VERSION="${{ needs.resolve.outputs.version }}"
131+
{
132+
echo "### 🐳 Docker image published"
133+
echo ""
134+
echo "| Tag | Image |"
135+
echo "|-----|-------|"
136+
echo "| \`$VERSION\` | \`$IMAGE:$VERSION\` |"
137+
echo "| \`latest\` | \`$IMAGE:latest\` |"
138+
echo ""
139+
echo "\`\`\`bash"
140+
echo "docker pull $IMAGE:$VERSION"
141+
echo "\`\`\`"
142+
} >> "$GITHUB_STEP_SUMMARY"

README-TEAL.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,20 @@ Polls [metabase/metabase](https://github.com/metabase/metabase) for new releases
6666

6767
**Conflict resolution:** The three branding files above are the most likely to conflict. In each case, keep the Teal values — the upstream values for those specific keys will always be wrong for this fork.
6868

69+
### Docker Publishing — `teal-docker-publish.yml`
70+
71+
Builds the Metabase OSS image from the root `Dockerfile` and publishes it to the GitHub Container Registry (GHCR) after each successful upstream sync.
72+
73+
```bash
74+
docker pull ghcr.io/decode-development/metabase-teal:latest
75+
docker pull ghcr.io/decode-development/metabase-teal:v0.53.2 # specific version
76+
```
77+
78+
**Triggers:**
79+
- Push to `master` with a sync commit message (clean auto-merge)
80+
- Merge of a `sync/upstream-v*` PR into master (conflict resolution)
81+
- Manual dispatch — accepts an optional version tag, defaults to the current latest upstream release
82+
83+
> **Note:** The build compiles the full frontend and backend from source and takes approximately 60–90 minutes on a standard GitHub-hosted runner. Layer caching (`type=gha`) reduces this significantly on subsequent builds.
84+
6985

0 commit comments

Comments
 (0)