diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ff955936..6a82e96b7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index afe5cf132..394133aed 100755 --- a/Dockerfile +++ b/Dockerfile @@ -2,56 +2,94 @@ # Twitter: https://twitter.com/gohugoio # Website: https://gohugo.io/ -FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.5.0 AS xx +ARG GO_VERSION="1.23.2" +ARG ALPINE_VERSION=3.20 -FROM --platform=$BUILDPLATFORM golang:1.22.6-alpine AS build +FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.5.0 AS xx +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gobuild +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS gorun + + +FROM gobuild AS build + +RUN apk add clang lld # 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" +ARG TARGETPLATFORM +RUN xx-apk add musl-dev gcc g++ -ARG CGO=1 -ENV CGO_ENABLED=${CGO} -ENV GOOS=linux -ENV GO111MODULE=on +# 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. +ARG HUGO_BUILD_TAGS="extended" +ENV CGO_ENABLED=1 +ENV GOPROXY=https://proxy.golang.org +ENV GOCACHE=/root/.cache/go-build +ENV GOMODCACHE=/go/pkg/mod +ARG TARGETPLATFORM 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 -RUN xx-apk add --no-scripts --no-cache gcc g++ musl-dev git +# For --mount=type=cache the value of target is the default cache id, so +# for the go mod cache it would be good if we could share it with other Go images using the same setup, +# but the go build cache needs to be per platform. +# See this comment: https://github.com/moby/buildkit/issues/1706#issuecomment-702238282 RUN --mount=target=. \ - --mount=type=cache,target=/go/pkg/mod <