Skip to content

Commit 53f4ce4

Browse files
committed
Publish Hugo base image under Apache-owned GHCR namespace
1 parent 4330293 commit 53f4ce4

4 files changed

Lines changed: 80 additions & 9 deletions

File tree

.github/workflows/build-docker-image.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
# GitHub Container Registry
1212
REGISTRY: ghcr.io
1313
IMAGE_NAME: ${{ github.repository }}
14+
HUGO_BASE_IMAGE: ghcr.io/${{ github.repository }}/hugo:v0.123.7-ext-multiplatform
1415

1516
jobs:
1617
build-and-push:
@@ -46,10 +47,14 @@ jobs:
4647
with:
4748
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4849

50+
- name: Ensure Hugo base image
51+
run: |
52+
docker pull ${{ env.HUGO_BASE_IMAGE }} || docker build -t ${{ env.HUGO_BASE_IMAGE }} -f Dockerfile.multiplatform .
53+
4954
- name: Build Hugo site
5055
run: |
51-
# Build the site using the multi-platform Hugo image
52-
docker run --rm -v $(pwd):/src hvishwanath/hugo:v0.123.7-ext-multiplatform \
56+
# Build the site using the Apache-owned multi-platform Hugo image
57+
docker run --rm -v $(pwd):/src ${{ env.HUGO_BASE_IMAGE }} \
5358
--minify \
5459
--destination output
5560
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and Publish Hugo Base Image
2+
3+
on:
4+
push:
5+
branches: [ markdown ]
6+
paths:
7+
- Dockerfile.multiplatform
8+
- scripts/entrypoint.sh
9+
- .github/workflows/build-hugo-base-image.yml
10+
pull_request:
11+
types: [ opened, synchronize, reopened ]
12+
branches: [ markdown ]
13+
paths:
14+
- Dockerfile.multiplatform
15+
- scripts/entrypoint.sh
16+
- .github/workflows/build-hugo-base-image.yml
17+
workflow_dispatch:
18+
19+
env:
20+
REGISTRY: ghcr.io
21+
IMAGE_NAME: ${{ github.repository }}/hugo
22+
HUGO_VERSION: 0.123.7
23+
24+
jobs:
25+
build-and-publish:
26+
runs-on: ubuntu-latest
27+
permissions:
28+
contents: read
29+
packages: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Log in to Container Registry
39+
if: github.event_name != 'pull_request'
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Build and optionally push Hugo base image
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: .
50+
file: ./Dockerfile.multiplatform
51+
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
52+
push: ${{ github.event_name != 'pull_request' }}
53+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ env.HUGO_VERSION }}-ext-multiplatform
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
56+
57+
- name: Create build summary
58+
run: |
59+
echo "## Hugo Base Image" >> $GITHUB_STEP_SUMMARY
60+
echo "- **Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ env.HUGO_VERSION }}-ext-multiplatform" >> $GITHUB_STEP_SUMMARY
61+
echo "- **Push Enabled**: ${{ github.event_name != 'pull_request' }}" >> $GITHUB_STEP_SUMMARY

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Hugo configuration
22
OUTPUT_DIR := output
3-
HUGO_BASE_IMAGE := hvishwanath/hugo:v0.123.7-ext-multiplatform
3+
HUGO_VERSION := 0.123.7
4+
HUGO_BASE_IMAGE := ghcr.io/apache/kafka-site/hugo:v$(HUGO_VERSION)-ext-multiplatform
45
DOCKER_IMAGE := $(HUGO_BASE_IMAGE)
56
#PROD_IMAGE := hvishwanath/kafka-site-md:1.2.0
67
PROD_IMAGE := us-west1-docker.pkg.dev/play-394201/kafka-site-md/kafka-site-md:1.6.0
78

8-
.PHONY: build serve clean docker-image hugo-base-multi-platform prod-image prod-run buildx-setup ghcr-prod-image
9+
.PHONY: build serve clean docker-image ensure-hugo-image hugo-base-multi-platform prod-image prod-run buildx-setup ghcr-prod-image
910

1011
# Setup buildx for multi-arch builds
1112
buildx-setup:
@@ -26,16 +27,19 @@ hugo-base-multi-platform: buildx-setup
2627
--push \
2728
.
2829

30+
# Pull the published Apache-owned Hugo image, or build it locally if it is not
31+
# available yet (useful for first-time bootstrapping and PR validation).
32+
ensure-hugo-image:
33+
docker pull $(DOCKER_IMAGE) || docker build -t $(DOCKER_IMAGE) -f Dockerfile.multiplatform .
34+
2935
# Build the static site using Docker
30-
build:
31-
docker pull $(DOCKER_IMAGE)
36+
build: ensure-hugo-image
3237
docker run --rm -v $(PWD):/src $(DOCKER_IMAGE) \
3338
--minify \
3439
--destination $(OUTPUT_DIR)
3540

3641
# Serve the site locally using Docker (development)
37-
serve:
38-
docker pull $(DOCKER_IMAGE)
42+
serve: ensure-hugo-image
3943
docker run --rm -it -v $(PWD):/src -p 1313:1313 $(DOCKER_IMAGE) \
4044
server \
4145
--bind 0.0.0.0 \

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ author: "Author Name (@github_handle)"
309309
make serve
310310
```
311311
This will:
312-
- Build the Hugo Docker image
312+
- Pull the published Apache-owned Hugo build image if available
313+
- Or build the Hugo build image locally from `Dockerfile.multiplatform`
313314
- Start a development server on http://localhost:1313
314315
- Watch for changes and automatically rebuild
315316
- Enable drafts and future posts

0 commit comments

Comments
 (0)