Skip to content

Commit c0b3801

Browse files
authored
Merge pull request #5636 from karlkfi/karl-site-pin-version
Update site/Dockerfile to use pinned hugo version
2 parents f068142 + 2c68a4d commit c0b3801

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.github
22
docs
33
examples
4-
site
54
travis
65
*.md

site/Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ RUN apk add --no-cache \
1313
build-base \
1414
libc6-compat
1515

16-
ARG HUGO_VERSION
17-
18-
RUN mkdir $HOME/src && \
19-
cd $HOME/src && \
20-
curl -L https://github.com/gohugoio/hugo/archive/refs/tags/v${HUGO_VERSION}.tar.gz | tar -xz && \
21-
cd "hugo-${HUGO_VERSION}" && \
22-
go install --tags extended
16+
RUN mkdir -p /go/src/sigs.k8s.io/kustomize/hack
17+
WORKDIR /go/src/sigs.k8s.io/kustomize/hack
18+
COPY hack/go.mod ./
19+
COPY hack/go.sum ./
20+
RUN go install --tags extended github.com/gohugoio/hugo
2321

2422
FROM docker.io/library/golang:1.21-alpine
2523

@@ -32,8 +30,8 @@ RUN apk add --no-cache \
3230

3331
RUN mkdir -p /usr/local/node_packages
3432
WORKDIR /usr/local/node_packages
35-
COPY package.json ./
36-
COPY package-lock.json ./
33+
COPY site/package.json ./
34+
COPY site/package-lock.json ./
3735
RUN npm install -D autoprefixer postcss-cli
3836
ENV PATH="/usr/local/node_packages/node_modules/.bin:${PATH}"
3937

site/Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ build-preview: module-check ## Build site with drafts and future posts enabled
4343
serve: module-check ## Boot the development server.
4444
hugo server --buildFuture --environment development
4545

46+
## Update the hugo version in ../hack/go.mod to match HUGO_VERSION in netlify.toml
47+
.PHONY: tools
48+
tools: netlify.toml
49+
@echo "Hugo: v$(HUGO_VERSION)"
50+
@set -euo pipefail && cd ../hack && \
51+
sed -e "/github.com\/gohugoio\/hugo/ s/v[0-9]\+\.[0-9]\+\.[0-9]\+/v$(HUGO_VERSION)/" go.mod > go.mod.next && \
52+
mv go.mod.next go.mod && \
53+
echo "Updated ../hack/go.mod"
54+
cd ../hack && go mod tidy
55+
4656
## Build a container image for the preview of the website
4757
.PHONY: container-image
48-
container-image: netlify.toml Dockerfile hugo.toml
49-
$(CONTAINER_ENGINE) build . \
58+
container-image: tools Dockerfile hugo.toml
59+
cd .. && $(CONTAINER_ENGINE) build . \
60+
--file site/Dockerfile \
5061
--network=host \
51-
--tag $(CONTAINER_IMAGE) \
52-
--build-arg HUGO_VERSION=$(HUGO_VERSION)
62+
--tag $(CONTAINER_IMAGE)
5363

5464
# no build lock to allow for read-only mounts
5565
## Boot the development server using container.

site/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ If you see errors, it probably means that the hugo container did not have enough
6060

6161
Open up your browser to <http://localhost:1313> to view the website. As you make changes to the source files, Hugo updates the website and forces a browser refresh.
6262

63+
If you need to update the `HUGO_VERSION`, edit it in the [`netlify.toml`](netlify.toml#L7) file and then run `make tools` to update the pinned version of Hugo in [hack/go.mod](/hack/go.mod#L9).
64+
6365
## Running the website locally using Hugo
6466

6567
Make sure to install the Hugo extended version specified by the `HUGO_VERSION` environment variable in the [`netlify.toml`](netlify.toml#L7) file.

site/netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ command = "git submodule update --init --recursive --depth 1 && hugo"
44
publish = "publishedSite/"
55

66
[build.environment]
7-
HUGO_VERSION = "0.120.3"
7+
HUGO_VERSION = "0.120.4"
88
NODE_ENV = "development"
99
NETLIFY_BUILD_DEBUG = "true"
1010

0 commit comments

Comments
 (0)