Skip to content

Commit 9e99281

Browse files
committed
release: build docs as container image
Signed-off-by: David Karlsson <[email protected]>
1 parent cc9ab90 commit 9e99281

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
55
cancel-in-progress: true
66

7+
env:
8+
IMAGE_NAME: "docs/docker-docs"
9+
710
on:
811
push:
912
# needs push event on default branch otherwise cache is evicted when pull request is merged
@@ -113,3 +116,41 @@ jobs:
113116
*.cache-to=type=gha,scope=validate-${{ matrix.target }},mode=max
114117
*.cache-from=type=gha,scope=validate-${{ matrix.target }}
115118
*.cache-from=type=gha,scope=build
119+
120+
image:
121+
runs-on: ubuntu-24.04
122+
steps:
123+
-
124+
name: Checkout
125+
uses: actions/checkout@v4
126+
with:
127+
fetch-depth: 0
128+
-
129+
name: Set up Docker Buildx
130+
uses: docker/setup-buildx-action@v3
131+
-
132+
name: Docker meta
133+
id: meta
134+
uses: docker/metadata-action@v5
135+
with:
136+
images: ${{ env.IMAGE_NAME }}
137+
-
138+
if: ${{ github.event_name != 'pull_request' }}
139+
name: Login to Docker Hub
140+
uses: docker/login-action@v3
141+
with:
142+
username: ${{ vars.DOCKER_USER }}
143+
password: ${{ secrets.DOCKER_TOKEN }}
144+
-
145+
name: Build website image
146+
uses: docker/bake-action@v5
147+
with:
148+
files: |
149+
docker-bake.hcl
150+
${{ steps.meta.outputs.bake-file-tags }}
151+
${{ steps.meta.outputs.bake-file-annotations }}
152+
targets: image
153+
set: |
154+
*.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }}
155+
*.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max
156+
push: ${{ github.event_name != 'pull_request' }}

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ARG HTMLTEST_VERSION=0.17.0
77
ARG HUGO_VERSION=0.141.0
88
ARG NODE_VERSION=22
99
ARG PAGEFIND_VERSION=1.3.0
10+
ARG NGINX_VERSION=1.27
1011

1112
# base defines the generic base stage
1213
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
@@ -149,3 +150,7 @@ EOT
149150
FROM scratch AS release
150151
COPY --from=build /project/public /
151152
COPY --from=pagefind /pagefind /pagefind
153+
154+
# image creates a Docker image for the documentation site
155+
FROM nginx:${NGINX_VERSION}-alpine AS image
156+
COPY --from=release / /usr/share/nginx/html

docker-bake.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ target "release" {
3535
provenance = false
3636
}
3737

38+
target "image" {
39+
args = {
40+
HUGO_ENV = HUGO_ENV
41+
DOCS_URL = "/"
42+
}
43+
target = "image"
44+
attest = [
45+
"type=provenance,mode=max",
46+
"type=sbom",
47+
]
48+
output = ["type=docker"]
49+
}
50+
3851
group "validate" {
3952
targets = ["lint", "test", "unused-media", "test-go-redirects", "dockerfile-lint", "path-warnings"]
4053
}

0 commit comments

Comments
 (0)