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 <[email protected]>
  • Loading branch information
dvdksn committed Oct 22, 2024
1 parent b1256d5 commit 5e7e394
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
40 changes: 40 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,40 @@ 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: ${{ vars.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-tags }}
${{ steps.meta.outputs.bake-file-annotations }}
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' }}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ARG GO_VERSION=1.23
ARG HTMLTEST_VERSION=0.17.0
# HUGO_VERSION sets the version of Hugo to build the site with
ARG HUGO_VERSION=0.136.2
# NGINX_VERSION sets the version of Nginx to use in the runtime image
ARG NGINX_VERSION=1.27

# build-base is the base stage used for building the site
FROM ghcr.io/gohugoio/hugo:v${HUGO_VERSION} AS build-base
Expand Down Expand Up @@ -131,3 +133,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
13 changes: 13 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
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 5e7e394

Please sign in to comment.