From e7b1ef7fda28f01acbaf3df10c47308e9bf61ed0 Mon Sep 17 00:00:00 2001 From: Mauren Berti Date: Fri, 18 Feb 2022 17:55:57 -0500 Subject: [PATCH 1/2] Create Dockerfile for arm64 architecture. --- Dockerfile.arm64 | 37 +++++++++++++++++++++++++++++++++++++ Makefile | 7 +++++++ README.md | 2 ++ 3 files changed, 46 insertions(+) create mode 100644 Dockerfile.arm64 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000000..49543bf091 --- /dev/null +++ b/Dockerfile.arm64 @@ -0,0 +1,37 @@ +# This is a modified version of the original Dockerfile in this repository, +# edited to install Hugo Extended from a tarball in a way that works with arm64 +# architectures. + +FROM golang:1.16-alpine + +RUN apk add --no-cache \ + curl \ + gcc \ + g++ \ + git \ + musl-dev \ + openssh-client \ + rsync \ + build-base \ + libc6-compat \ + npm && \ + npm install -D autoprefixer postcss-cli + +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 && \ + cp /go/bin/hugo /usr/local/bin/hugo && \ + mkdir -p /usr/local/src && \ + cd /usr/local/src && \ + addgroup -Sg 1000 hugo && \ + adduser -Sg hugo -u 1000 -h /src hugo + +WORKDIR /src + +USER hugo:hugo + +EXPOSE 1313 diff --git a/Makefile b/Makefile index 57fca6e2d1..63ae35c778 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,13 @@ container-image: ## Build a container image for the preview of the website --tag $(CONTAINER_IMAGE) \ --build-arg HUGO_VERSION=$(HUGO_VERSION) +container-image-arm64: ## Build a container image for the preview of the website that works with arm64 + $(CONTAINER_ENGINE) build . \ + --file Dockerfile.arm64 \ + --network=host \ + --tag $(CONTAINER_IMAGE) \ + --build-arg HUGO_VERSION=$(HUGO_VERSION) + container-build: module-check $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development" diff --git a/README.md b/README.md index 87dd03e7eb..48650c569b 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ make container-serve If you see errors, it probably means that the hugo container did not have enough computing resources available. To solve it, increase the amount of allowed CPU and memory usage for Docker on your machine ([MacOSX](https://docs.docker.com/docker-for-mac/#resources) and [Windows](https://docs.docker.com/docker-for-windows/#resources)). +If you use a computer with arm64 architecture instead of amd64, use the target `make container-image-arm64` instead to build the container image. + Open up your browser to to view the website. As you make changes to the source files, Hugo updates the website and forces a browser refresh. ## Running the website locally using Hugo From 7a8d695f11bde52818b97949231544dac3445831 Mon Sep 17 00:00:00 2001 From: Mauren Berti Date: Wed, 9 Mar 2022 08:05:56 -0500 Subject: [PATCH 2/2] Convert to multi-stage Dockerfile. - Remove architecture-specific Dockerfile and Makefile target. - Convert Dockerfile to a multi-stage build, keeping only what is needed to run. --- Dockerfile | 31 ++++++++++++++++++++++--------- Dockerfile.arm64 | 37 ------------------------------------- Makefile | 7 ------- README.md | 2 -- 4 files changed, 22 insertions(+), 55 deletions(-) delete mode 100644 Dockerfile.arm64 diff --git a/Dockerfile b/Dockerfile index 93c73d218c..9e9a6d65b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,29 +4,42 @@ # change is that the Hugo version is now an overridable argument rather than a fixed # environment variable. -FROM golang:1.15-alpine +FROM golang:1.16-alpine LABEL maintainer="Luc Perkins " RUN apk add --no-cache \ curl \ - git \ - openssh-client \ - rsync \ + gcc \ + g++ \ + musl-dev \ build-base \ - libc6-compat \ - npm && \ - npm install -D autoprefixer postcss-cli + 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 golang:1.16-alpine + +RUN apk add --no-cache \ + git \ + openssh-client \ + rsync \ + npm && \ + npm install -D autoprefixer postcss-cli + RUN mkdir -p /usr/local/src && \ cd /usr/local/src && \ - curl -L https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz | tar -xz && \ - mv hugo /usr/local/bin/hugo && \ addgroup -Sg 1000 hugo && \ adduser -Sg hugo -u 1000 -h /src hugo +COPY --from=0 /go/bin/hugo /usr/local/bin/hugo + WORKDIR /src USER hugo:hugo diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 deleted file mode 100644 index 49543bf091..0000000000 --- a/Dockerfile.arm64 +++ /dev/null @@ -1,37 +0,0 @@ -# This is a modified version of the original Dockerfile in this repository, -# edited to install Hugo Extended from a tarball in a way that works with arm64 -# architectures. - -FROM golang:1.16-alpine - -RUN apk add --no-cache \ - curl \ - gcc \ - g++ \ - git \ - musl-dev \ - openssh-client \ - rsync \ - build-base \ - libc6-compat \ - npm && \ - npm install -D autoprefixer postcss-cli - -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 && \ - cp /go/bin/hugo /usr/local/bin/hugo && \ - mkdir -p /usr/local/src && \ - cd /usr/local/src && \ - addgroup -Sg 1000 hugo && \ - adduser -Sg hugo -u 1000 -h /src hugo - -WORKDIR /src - -USER hugo:hugo - -EXPOSE 1313 diff --git a/Makefile b/Makefile index 63ae35c778..57fca6e2d1 100644 --- a/Makefile +++ b/Makefile @@ -71,13 +71,6 @@ container-image: ## Build a container image for the preview of the website --tag $(CONTAINER_IMAGE) \ --build-arg HUGO_VERSION=$(HUGO_VERSION) -container-image-arm64: ## Build a container image for the preview of the website that works with arm64 - $(CONTAINER_ENGINE) build . \ - --file Dockerfile.arm64 \ - --network=host \ - --tag $(CONTAINER_IMAGE) \ - --build-arg HUGO_VERSION=$(HUGO_VERSION) - container-build: module-check $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development" diff --git a/README.md b/README.md index 48650c569b..87dd03e7eb 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,6 @@ make container-serve If you see errors, it probably means that the hugo container did not have enough computing resources available. To solve it, increase the amount of allowed CPU and memory usage for Docker on your machine ([MacOSX](https://docs.docker.com/docker-for-mac/#resources) and [Windows](https://docs.docker.com/docker-for-windows/#resources)). -If you use a computer with arm64 architecture instead of amd64, use the target `make container-image-arm64` instead to build the container image. - Open up your browser to to view the website. As you make changes to the source files, Hugo updates the website and forces a browser refresh. ## Running the website locally using Hugo