forked from kubernetes-sigs/kustomize
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix running docs site with docker (kubernetes-sigs#5512)
* Update docs site local build Clean up makefile Ignore container-image.sentinel Fix hugo server errors Ignore files Add makefile credit * Indentation per feedback * Address PR feedback. Remove sentinel file * Remove change to .gitignore
- Loading branch information
Showing
6 changed files
with
264 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
FROM klakegg/hugo:ext-alpine | ||
# Credit to Julien Guyomard (https://github.com/jguyomard) | ||
# Credit to the Kubernetes Website team. | ||
# This Dockerfile is based on: | ||
# (https://github.com/kubernetes/website/blob/main/Dockerfile) | ||
|
||
RUN apk add git | ||
FROM docker.io/library/golang:1.20-alpine | ||
|
||
RUN apk add --no-cache \ | ||
curl \ | ||
gcc \ | ||
g++ \ | ||
musl-dev \ | ||
build-base \ | ||
libc6-compat | ||
|
||
ARG HUGO_VERSION | ||
|
||
RUN mkdir $HOME/src && \ | ||
cd $HOME/src && \ | ||
curl -L https://github.com/gohugoio/hugo/archive/refs/tags/v${HUGO_VERSION}.tar.gz | tar -xz && \ | ||
cd "hugo-${HUGO_VERSION}" && \ | ||
go install --tags extended | ||
|
||
FROM docker.io/library/golang:1.20-alpine | ||
|
||
RUN apk add --no-cache \ | ||
runuser \ | ||
git \ | ||
openssh-client \ | ||
rsync \ | ||
npm && \ | ||
npm install -D autoprefixer postcss-cli | ||
|
||
RUN mkdir -p /var/hugo && \ | ||
addgroup -Sg 1000 hugo && \ | ||
adduser -Sg hugo -u 1000 -h /var/hugo hugo && \ | ||
chown -R hugo: /var/hugo && \ | ||
runuser -u hugo -- git config --global --add safe.directory /src | ||
|
||
COPY --from=0 /go/bin/hugo /usr/local/bin/hugo | ||
|
||
WORKDIR /src | ||
|
||
USER hugo:hugo | ||
|
||
EXPOSE 1313 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Credit to the Kubernetes Website team. (https://github.com/kubernetes/website/blob/main/Makefile) | ||
HUGO_VERSION = $(shell grep ^HUGO_VERSION netlify.toml | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n") | ||
|
||
# The CONTAINER_ENGINE variable is used for specifying the container engine. By default 'docker' is used | ||
# but this can be overridden when calling make, e.g. | ||
# CONTAINER_ENGINE=podman make container-image | ||
CONTAINER_ENGINE ?= docker | ||
IMAGE_REGISTRY ?= registry.local:5000 | ||
IMAGE_VERSION=$(shell scripts/hash-files.sh Dockerfile Makefile | cut -c 1-12) | ||
CONTAINER_IMAGE = $(IMAGE_REGISTRY)/kustomize-website-hugo:v$(HUGO_VERSION)-$(IMAGE_VERSION) | ||
# Mount read-only to allow use with tools like Podman in SELinux mode | ||
# Container targets don't need to write into /src | ||
CONTAINER_RUN = "$(CONTAINER_ENGINE)" run --rm --interactive --tty --volume "$(abspath $(CURDIR)/..):/src:ro,Z" | ||
|
||
CCRED=\033[0;31m | ||
CCEND=\033[0m | ||
|
||
.PHONY: help | ||
help: ## Show this help. | ||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | ||
|
||
.PHONY: module-check | ||
module-check: ## Check if all of the required submodules are correctly initialized. | ||
@git submodule status --recursive | awk '/^[+-]/ {err = 1; printf "\033[31mWARNING\033[0m Submodule not initialized: \033[34m%s\033[0m\n",$$2} END { if (err != 0) print "You need to run \033[32mmake module-init\033[0m to initialize missing modules first"; exit err }' 1>&2 | ||
|
||
.PHONY: module-init | ||
module-init: ## Initialize required submodules. | ||
@echo "Initializing submodules..." 1>&2 | ||
@git submodule update --init --recursive --depth 1 | ||
|
||
.PHONY: all | ||
all: build ## Build site with production settings and put deliverables in ./public | ||
|
||
.PHONY: build | ||
build: module-check ## Build site with non-production settings and put deliverables in ./public | ||
hugo --cleanDestinationDir --minify --environment development | ||
|
||
.PHONY: build-preview | ||
build-preview: module-check ## Build site with drafts and future posts enabled | ||
hugo --cleanDestinationDir --buildDrafts --buildFuture --environment preview | ||
|
||
.PHONY: serve | ||
serve: module-check ## Boot the development server. | ||
hugo server --buildFuture --environment development | ||
|
||
## Build a container image for the preview of the website | ||
.PHONY: container-image | ||
container-image: netlify.toml Dockerfile hugo.toml | ||
$(CONTAINER_ENGINE) build . \ | ||
--network=host \ | ||
--tag $(CONTAINER_IMAGE) \ | ||
--build-arg HUGO_VERSION=$(HUGO_VERSION) | ||
|
||
# no build lock to allow for read-only mounts | ||
## Boot the development server using container. | ||
.PHONY: container-serve | ||
container-serve: module-check | ||
$(CONTAINER_RUN) \ | ||
--cap-drop=ALL \ | ||
--cap-add=AUDIT_WRITE \ | ||
--read-only \ | ||
--mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 \ | ||
-p 1313:1313 $(CONTAINER_IMAGE) \ | ||
hugo server \ | ||
--source site \ | ||
--buildFuture \ | ||
--environment development \ | ||
--bind 0.0.0.0 \ | ||
--destination /tmp/hugo \ | ||
--cleanDestinationDir \ | ||
--noBuildLock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
[build] | ||
base = "site/" | ||
command = "git submodule update --init --recursive --depth 1 && hugo" | ||
publish = "publishedSite/" | ||
base = "site/" | ||
command = "git submodule update --init --recursive --depth 1 && hugo" | ||
publish = "publishedSite/" | ||
|
||
[build.environment] | ||
HUGO_VERSION = "0.92.2" | ||
NODE_ENV = "development" | ||
NETLIFY_BUILD_DEBUG = "true" | ||
HUGO_VERSION = "0.120.3" | ||
NODE_ENV = "development" | ||
NETLIFY_BUILD_DEBUG = "true" | ||
|
||
[context.deploy-preview] | ||
command = "git submodule update --init --recursive --depth 1 && hugo --enableGitInfo --buildFuture -b $DEPLOY_PRIME_URL" | ||
command = "git submodule update --init --recursive --depth 1 && hugo --enableGitInfo --buildFuture -b $DEPLOY_PRIME_URL" | ||
|
||
[context.branch-deploy] | ||
ignore = "exit 0" # build PRs (deploy preview env) only, not all branches | ||
ignore = "exit 0" # build PRs (deploy preview env) only, not all branches | ||
|
||
[context.production] | ||
ignore = "exit 0" # never deploy production until we're ready to launch | ||
|
||
ignore = "exit 0" # never deploy production until we're ready to launch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
# this script emits as hash for the files listed in $@ | ||
if command -v shasum >/dev/null 2>&1; then | ||
cat "$@" | shasum -a 256 | cut -d' ' -f1 | ||
elif command -v sha256sum >/dev/null 2>&1; then | ||
cat "$@" | sha256sum | cut -d' ' -f1 | ||
else | ||
echo "missing shasum tool" 1>&2 | ||
exit 1 | ||
fi |