Skip to content

Commit b3faef2

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

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-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
@@ -98,3 +101,41 @@ jobs:
98101
set: |
99102
*.cache-from=type=gha,scope=releaser
100103
*.cache-to=type=gha,scope=releaser,mode=max
104+
105+
image:
106+
runs-on: ubuntu-24.04
107+
steps:
108+
-
109+
name: Checkout
110+
uses: actions/checkout@v4
111+
with:
112+
fetch-depth: 0
113+
-
114+
name: Set up Docker Buildx
115+
uses: docker/setup-buildx-action@v3
116+
-
117+
name: Docker meta
118+
id: meta
119+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
120+
with:
121+
images: ${{ env.IMAGE_NAME }}
122+
-
123+
if: ${{ github.event_name != 'pull_request' }}
124+
name: Login to Docker Hub
125+
uses: docker/login-action@v3
126+
with:
127+
username: ${{ vars.DOCKER_USER }}
128+
password: ${{ secrets.DOCKER_TOKEN }}
129+
-
130+
name: Build website image
131+
uses: docker/bake-action@v5
132+
with:
133+
files: |
134+
docker-bake.hcl
135+
${{ steps.meta.outputs.bake-file-tags }}
136+
${{ steps.meta.outputs.bake-file-annotations }}
137+
targets: image
138+
set: |
139+
*.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }}
140+
*.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max
141+
push: ${{ github.event_name != 'pull_request' }}

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ARG GO_VERSION=1.23
99
ARG HTMLTEST_VERSION=0.17.0
1010
# HUGO_VERSION sets the version of Hugo to build the site with
1111
ARG HUGO_VERSION=0.136.2
12+
# NGINX_VERSION sets the version of Nginx to use in the runtime image
13+
ARG NGINX_VERSION=1.27
1214

1315
# build-base is the base stage used for building the site
1416
FROM ghcr.io/gohugoio/hugo:v${HUGO_VERSION} AS build-base
@@ -131,3 +133,7 @@ EOT
131133
FROM scratch AS release
132134
COPY --from=build /out /
133135
COPY --from=pagefind /pagefind /pagefind
136+
137+
# image creates a Docker image for the documentation site
138+
FROM nginx:${NGINX_VERSION}-alpine AS image
139+
COPY --from=release / /usr/share/nginx/html

docker-bake.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ target "release" {
3131
provenance = false
3232
}
3333

34+
target "image" {
35+
args = {
36+
HUGO_ENV = HUGO_ENV
37+
DOCS_URL = "/"
38+
}
39+
target = "image"
40+
attest = [
41+
"type=provenance,mode=max",
42+
"type=sbom",
43+
]
44+
output = ["type=docker"]
45+
}
46+
3447
group "validate" {
3548
targets = ["lint", "test", "unused-media", "test-go-redirects", "dockerfile-lint", "path-warnings"]
3649
}

0 commit comments

Comments
 (0)