Skip to content

Commit a1197db

Browse files
committed
release: build docs as container image
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 27094d5 commit a1197db

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
@@ -116,3 +119,41 @@ jobs:
116119
*.cache-to=type=gha,scope=validate-${{ matrix.target }},mode=max
117120
*.cache-from=type=gha,scope=validate-${{ matrix.target }}
118121
*.cache-from=type=gha,scope=build
122+
123+
image:
124+
runs-on: ubuntu-24.04
125+
steps:
126+
-
127+
name: Checkout
128+
uses: actions/checkout@v4
129+
with:
130+
fetch-depth: 0
131+
-
132+
name: Set up Docker Buildx
133+
uses: docker/setup-buildx-action@v3
134+
-
135+
name: Docker meta
136+
id: meta
137+
uses: docker/metadata-action@v5
138+
with:
139+
images: ${{ env.IMAGE_NAME }}
140+
-
141+
if: ${{ github.event_name != 'pull_request' }}
142+
name: Login to Docker Hub
143+
uses: docker/login-action@v3
144+
with:
145+
username: ${{ vars.DOCKER_USER }}
146+
password: ${{ secrets.DOCKER_TOKEN }}
147+
-
148+
name: Build website image
149+
uses: docker/bake-action@v5
150+
with:
151+
files: |
152+
docker-bake.hcl
153+
${{ steps.meta.outputs.bake-file-tags }}
154+
${{ steps.meta.outputs.bake-file-annotations }}
155+
targets: image
156+
set: |
157+
*.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }}
158+
*.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max
159+
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.139.0
88
ARG NODE_VERSION=22
99
ARG PAGEFIND_VERSION=1.1.1
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)