Skip to content

Commit 8f4a00c

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

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

.github/workflows/build.yml

Lines changed: 39 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,39 @@ 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+
name: Login to GHCR
124+
uses: docker/login-action@3
125+
with:
126+
username: ${{ secrets.DOCKER_USER }}
127+
password: ${{ secrets.DOCKER_TOKEN }}
128+
-
129+
name: Build website image
130+
uses: docker/bake-action@v5
131+
with:
132+
files: |
133+
docker-bake.hcl
134+
${{ steps.meta.outputs.bake-file }}
135+
targets: image
136+
set: |
137+
*.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }}
138+
*.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max
139+
push: ${{ github.event_name != 'pull_request' }}

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ARG ALPINE_VERSION=3.20
77
ARG GO_VERSION=1.23
88
# HTML_TEST_VERSION sets the wjdp/htmltest version for HTML testing
99
ARG HTMLTEST_VERSION=0.17.0
10+
ARG NGINX_VERSION=1.27
1011

1112
# base is the base stage with build dependencies
1213
FROM golang:${GO_VERSION}-alpine AS base
@@ -39,9 +40,9 @@ FROM build-base AS dev
3940
# build creates production builds with Hugo
4041
FROM build-base AS build
4142
# HUGO_ENV sets the hugo.Environment (production, development, preview)
42-
ARG HUGO_ENV
43+
ARG HUGO_ENV="development"
4344
# DOCS_URL sets the base URL for the site
44-
ARG DOCS_URL
45+
ARG DOCS_URL="https://docs.docker.com"
4546
RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL
4647

4748
# lint lints markdown files
@@ -146,3 +147,7 @@ EOT
146147
FROM scratch AS release
147148
COPY --from=build /out /
148149
COPY --from=pagefind /pagefind /pagefind
150+
151+
# image creates a Docker image for the documentation site
152+
FROM nginx:${NGINX_VERSION}-alpine AS image
153+
COPY --from=release / /usr/share/nginx/html

docker-bake.hcl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
variable "HUGO_ENV" {
2-
default = "development"
2+
default = null
33
}
44

55
variable "DOCS_URL" {
6-
default = "https://docs.docker.com"
6+
default = null
77
}
88

99
variable "DOCS_SITE_DIR" {
@@ -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)