Skip to content

Commit

Permalink
release: build docs as container image
Browse files Browse the repository at this point in the history
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
  • Loading branch information
dvdksn committed Oct 1, 2024
1 parent 473a90f commit 32731dd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IMAGE_NAME: "docs/docker-docs"

on:
push:
# needs push event on default branch otherwise cache is evicted when pull request is merged
Expand Down Expand Up @@ -98,3 +101,39 @@ jobs:
set: |
*.cache-from=type=gha,scope=releaser
*.cache-to=type=gha,scope=releaser,mode=max
image:
runs-on: ubuntu-24.04
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ env.IMAGE_NAME }}
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build website image
uses: docker/bake-action@v5
with:
files: |
docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image
set: |
*.cache-from=type=gha,scope=deploy-${{ env.BRANCH_NAME }}
*.cache-to=type=gha,scope=deploy-${{ env.BRANCH_NAME }},mode=max
push: ${{ github.event_name != 'pull_request' }}
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ARG ALPINE_VERSION=3.20
ARG GO_VERSION=1.23
# HTML_TEST_VERSION sets the wjdp/htmltest version for HTML testing
ARG HTMLTEST_VERSION=0.17.0
ARG NGINX_VERSION=1.27

# base is the base stage with build dependencies
FROM golang:${GO_VERSION}-alpine AS base
Expand Down Expand Up @@ -39,9 +40,9 @@ FROM build-base AS dev
# build creates production builds with Hugo
FROM build-base AS build
# HUGO_ENV sets the hugo.Environment (production, development, preview)
ARG HUGO_ENV
ARG HUGO_ENV="development"
# DOCS_URL sets the base URL for the site
ARG DOCS_URL
ARG DOCS_URL="https://docs.docker.com"
RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL

# lint lints markdown files
Expand Down Expand Up @@ -146,3 +147,7 @@ EOT
FROM scratch AS release
COPY --from=build /out /
COPY --from=pagefind /pagefind /pagefind

# image creates a Docker image for the documentation site
FROM nginx:${NGINX_VERSION}-alpine AS image
COPY --from=release / /usr/share/nginx/html
17 changes: 15 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
variable "HUGO_ENV" {
default = "development"
default = null
}

variable "DOCS_URL" {
default = "https://docs.docker.com"
default = null
}

variable "DOCS_SITE_DIR" {
Expand Down Expand Up @@ -31,6 +31,19 @@ target "release" {
provenance = false
}

target "image" {
args = {
HUGO_ENV = HUGO_ENV
DOCS_URL = "/"
}
target = "image"
attest = [
"type=provenance,mode=max",
"type=sbom",
]
output = ["type=docker"]
}

group "validate" {
targets = ["lint", "test", "unused-media", "test-go-redirects", "dockerfile-lint", "path-warnings"]
}
Expand Down

0 comments on commit 32731dd

Please sign in to comment.