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.
This commit is contained in:
Mauren Berti
2022-03-09 08:05:56 -05:00
parent e7b1ef7fda
commit 7a8d695f11
4 changed files with 22 additions and 55 deletions
+22 -9
View File
@@ -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 <lperkins@linuxfoundation.org>"
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
-37
View File
@@ -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
-7
View File
@@ -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"
-2
View File
@@ -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 <http://localhost:1313> 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