Skip to content

Commit

Permalink
Upgrade to latest Go version + some Docker improvements (note)
Browse files Browse the repository at this point in the history
* Add tzdata (needed by Hugo)
* add ldflags
* Adjust cache logic to speed up CGO rebuilds

Closes #12920
See #12885
  • Loading branch information
bep committed Oct 9, 2024
1 parent a3a0001 commit 2505dd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
defaults: &defaults
resource_class: large
docker:
- image: bepsays/ci-hugoreleaser:1.22300.20000
- image: bepsays/ci-hugoreleaser:1.22300.20200
environment: &buildenv
GOMODCACHE: /root/project/gomodcache
version: 2
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
environment:
<<: [*buildenv]
docker:
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22300.20000
- image: bepsays/ci-hugoreleaser-linux-arm64:1.22300.20200
steps:
- *restore-cache
- &attach-workspace
Expand Down
33 changes: 17 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@

FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.5.0 AS xx

FROM --platform=$BUILDPLATFORM golang:1.22.6-alpine AS build
FROM --platform=$BUILDPLATFORM golang:1.23.2-alpine AS build

# Set up cross-compilation helpers
COPY --from=xx / /
RUN apk add clang lld

# Optionally set HUGO_BUILD_TAGS to "extended" or "nodeploy" when building like so:
# docker build --build-arg HUGO_BUILD_TAGS=extended .
ARG HUGO_BUILD_TAGS="none"
# Optionally set HUGO_BUILD_TAGS to "none" or "nodeploy" when building like so:
# docker build --build-arg HUGO_BUILD_TAGS=nodeploy .
# We build the extended version by default.
# We could probably set up a multi-stage build to build both versions,
# but that would be more complex and it only shaves off about 1% of the image size.
ARG HUGO_BUILD_TAGS="extended"

ARG CGO=1
ENV CGO_ENABLED=${CGO}
ENV GOOS=linux
ENV GO111MODULE=on
ENV GOPROXY=https://proxy.golang.org
ENV GOCACHE=/root/.cache/go-build
ENV GOMODCACHE=/go/pkg/mod

WORKDIR /go/src/github.com/gohugoio/hugo

RUN --mount=src=go.mod,target=go.mod \
--mount=src=go.sum,target=go.sum \
--mount=type=cache,target=/go/pkg/mod \
go mod download

ARG TARGETPLATFORM
# gcc/g++ are required to build SASS libraries for extended version
# gcc/g++ are required to build libsass and libwebp libraries for the extended version.
RUN xx-apk add --no-scripts --no-cache gcc g++ musl-dev git
RUN --mount=target=. \
--mount=type=cache,target=/go/pkg/mod <<EOT
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build <<EOT
set -ex
xx-go build -tags "$HUGO_BUILD_TAGS" -o /usr/bin/hugo
xx-go build -tags "$HUGO_BUILD_TAGS" -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.vendorInfo=docker" -o /usr/bin/hugo
xx-verify /usr/bin/hugo
EOT

# ---

FROM alpine:3.18

COPY --from=build /usr/bin/hugo /usr/bin/hugo

# libc6-compat & libstdc++ are required for extended SASS libraries
# ca-certificates are required to fetch outside resources (like Twitter oEmbeds)
# tzdata (Timezone data) and git is required by Hugo.
RUN apk update && \
apk add --no-cache ca-certificates libc6-compat libstdc++ git
apk add --no-cache ca-certificates libc6-compat libstdc++ git tzdata

VOLUME /site
WORKDIR /site
Expand All @@ -55,3 +55,4 @@ EXPOSE 1313

ENTRYPOINT ["hugo"]
CMD ["--help"]

0 comments on commit 2505dd7

Please sign in to comment.