You've already forked hugo-docker
mirror of
https://github.com/jakejarvis/hugo-docker.git
synced 2025-07-01 22:46:41 -04:00
Compare commits
66 Commits
Author | SHA1 | Date | |
---|---|---|---|
10103bce3b
|
|||
fcb292357c
|
|||
61fa24ed38
|
|||
250387c4f1
|
|||
6e5386c78a
|
|||
86af318435
|
|||
5bbac6174f
|
|||
9fc7783e5a
|
|||
4f26d81802
|
|||
de42257aa2
|
|||
e10c7362c7
|
|||
5bd125e947
|
|||
92aeed4a00
|
|||
23cd994860
|
|||
5bbdb9ba12
|
|||
b69006cb54
|
|||
f0b59209e5
|
|||
061289816b | |||
e59900daaa
|
|||
92748c6c0f | |||
18a14635c0
|
|||
3cb403f6fa
|
|||
70c9d418ec
|
|||
4ec3e8be98
|
|||
f1513cf6c7
|
|||
e608453299
|
|||
7a43febe15
|
|||
4898a96b66
|
|||
73e0bf7815
|
|||
d6ca9055b4
|
|||
bca0721d67
|
|||
33bd893ed3
|
|||
d9338044c5
|
|||
cb26219a40
|
|||
f6580ec25c
|
|||
6bc21e062a
|
|||
04930ae9ae
|
|||
eb82474eb8
|
|||
90b15c893d
|
|||
b31b18ac2d
|
|||
4df70ef38c
|
|||
f75b85512b
|
|||
f97154879d
|
|||
4f1d3a9c48
|
|||
22ba6e27d0
|
|||
3123853163
|
|||
5d7840092e
|
|||
7d20947610 | |||
a6b5427dca
|
|||
941079893a
|
|||
8a2fe24434
|
|||
bdf6d208b4
|
|||
de4ef2242f
|
|||
a7e4ccee25
|
|||
77fc7a219c
|
|||
b9d9a45c6a | |||
912a1f4176
|
|||
b807ac60eb
|
|||
2cf9bd62af
|
|||
30f54331e8
|
|||
791ec15da8
|
|||
deaf886150
|
|||
248ff169bd
|
|||
9be7813071
|
|||
783939f439 | |||
54f06a59e8
|
82
.github/workflows/build.yml
vendored
Normal file
82
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
name: Build and Push
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Prepare tags
|
||||||
|
id: tag
|
||||||
|
env:
|
||||||
|
HUB_IMAGE: jakejarvis/hugo-extended
|
||||||
|
GHCR_IMAGE: ghcr.io/jakejarvis/hugo-extended
|
||||||
|
run: |
|
||||||
|
TAGS="${HUB_IMAGE}:latest,${GHCR_IMAGE}:latest"
|
||||||
|
|
||||||
|
# If triggered by a new tag, add a version tag to the image
|
||||||
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
TAGS="$TAGS,${HUB_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set output parameters
|
||||||
|
echo ::set-output name=tags::${TAGS}
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@master
|
||||||
|
with:
|
||||||
|
platforms: all
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@master
|
||||||
|
|
||||||
|
- name: Cache Docker layers
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache
|
||||||
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: jakejarvis
|
||||||
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GHCR_PAT }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
builder: ${{ steps.buildx.outputs.name }}
|
||||||
|
context: ./
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.tag.outputs.tags }}
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache
|
||||||
|
|
||||||
|
- name: Image digest
|
||||||
|
run: echo ${{ steps.build.outputs.digest }}
|
52
.github/workflows/publish.yml
vendored
52
.github/workflows/publish.yml
vendored
@ -1,52 +0,0 @@
|
|||||||
name: Publish to GitHub Container Registry
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
# Publish `v*` tags as releases.
|
|
||||||
tags:
|
|
||||||
- v*
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE_NAME: hugo-extended
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Build image
|
|
||||||
run: docker build . --file Dockerfile
|
|
||||||
|
|
||||||
# Push image to GitHub Container Registry
|
|
||||||
push:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.event_name == 'push'
|
|
||||||
needs: build
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Build image
|
|
||||||
run: docker build . --file Dockerfile --tag $IMAGE_NAME
|
|
||||||
- name: Login to GitHub Container Registry
|
|
||||||
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
|
||||||
- name: Push image to GitHub
|
|
||||||
run: |
|
|
||||||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
|
|
||||||
|
|
||||||
# Change all uppercase to lowercase
|
|
||||||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
|
|
||||||
|
|
||||||
# Strip git ref prefix from version
|
|
||||||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
|
||||||
|
|
||||||
# Strip "v" prefix from tag name
|
|
||||||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
|
||||||
|
|
||||||
echo IMAGE_ID=$IMAGE_ID
|
|
||||||
echo VERSION=$VERSION
|
|
||||||
|
|
||||||
# Push image with both version tag and `latest` tag
|
|
||||||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
|
|
||||||
docker tag $IMAGE_NAME $IMAGE_ID:latest
|
|
||||||
docker push $IMAGE_ID:$VERSION
|
|
||||||
docker push $IMAGE_ID:latest
|
|
152
Dockerfile
152
Dockerfile
@ -1,11 +1,61 @@
|
|||||||
# Hugo doesn't require Go to run, *except* if you're using Hugo Modules. It's
|
|
||||||
# much easier to install Node on the Go base image than vice-versa.
|
|
||||||
FROM golang:1.15-alpine
|
|
||||||
|
|
||||||
# the following version can be overridden at image build time with --build-arg
|
# the following version can be overridden at image build time with --build-arg
|
||||||
ARG HUGO_VERSION=0.80.0
|
ARG HUGO_VERSION=0.102.1
|
||||||
# remove/comment the following line completely to build with vanilla Hugo:
|
# remove/comment the following line completely to compile vanilla Hugo:
|
||||||
ARG HUGO_EXTENDED=1
|
ARG HUGO_BUILD_TAGS=extended
|
||||||
|
|
||||||
|
# Hugo >= v0.81.0 requires Go 1.16+ to build
|
||||||
|
ARG GO_VERSION=1.18
|
||||||
|
ARG ALPINE_VERSION=3.16
|
||||||
|
|
||||||
|
# ---
|
||||||
|
|
||||||
|
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build
|
||||||
|
|
||||||
|
# renew global args from above
|
||||||
|
# https://docs.docker.com/engine/reference/builder/#scope
|
||||||
|
ARG HUGO_VERSION
|
||||||
|
ARG HUGO_BUILD_TAGS
|
||||||
|
|
||||||
|
ARG CGO=1
|
||||||
|
ENV CGO_ENABLED=${CGO}
|
||||||
|
ENV GOOS=linux
|
||||||
|
ENV GO111MODULE=on
|
||||||
|
|
||||||
|
WORKDIR /go/src/github.com/gohugoio/hugo
|
||||||
|
|
||||||
|
# gcc/g++ are required to build SASS libraries for extended version
|
||||||
|
RUN apk add --update --no-cache \
|
||||||
|
gcc \
|
||||||
|
g++ \
|
||||||
|
musl-dev \
|
||||||
|
git
|
||||||
|
|
||||||
|
# clone source from Git repo:
|
||||||
|
RUN git clone \
|
||||||
|
--branch "v${HUGO_VERSION}" \
|
||||||
|
--single-branch \
|
||||||
|
--depth 1 \
|
||||||
|
https://github.com/gohugoio/hugo.git ./
|
||||||
|
|
||||||
|
# https://github.com/gohugoio/hugo/commit/241481931f5f5f2803cd4be519936b26d8648dfd
|
||||||
|
RUN go build -v -ldflags "-X github.com/gohugoio/hugo/common/hugo.vendorInfo=docker" -tags "$HUGO_BUILD_TAGS" && \
|
||||||
|
mv ./hugo /go/bin/hugo
|
||||||
|
|
||||||
|
# fix potential stack size problems on Alpine
|
||||||
|
# https://github.com/microsoft/vscode-dev-containers/blob/fb63f7e016877e13535d4116b458d8f28012e87f/containers/hugo/.devcontainer/Dockerfile#L19
|
||||||
|
RUN go install github.com/yaegashi/muslstack@latest && \
|
||||||
|
muslstack -s 0x800000 /go/bin/hugo
|
||||||
|
|
||||||
|
# ---
|
||||||
|
|
||||||
|
FROM alpine:${ALPINE_VERSION}
|
||||||
|
|
||||||
|
# renew global args from above & pin any dependency versions
|
||||||
|
ARG HUGO_VERSION
|
||||||
|
# https://github.com/jgm/pandoc/releases
|
||||||
|
ARG PANDOC_VERSION=2.18
|
||||||
|
# https://github.com/sass/dart-sass-embedded/releases
|
||||||
|
ARG DART_SASS_VERSION=1.54.0
|
||||||
|
|
||||||
LABEL version="${HUGO_VERSION}"
|
LABEL version="${HUGO_VERSION}"
|
||||||
LABEL repository="https://github.com/jakejarvis/hugo-docker"
|
LABEL repository="https://github.com/jakejarvis/hugo-docker"
|
||||||
@ -13,54 +63,84 @@ LABEL homepage="https://jarv.is/"
|
|||||||
LABEL maintainer="Jake Jarvis <jake@jarv.is>"
|
LABEL maintainer="Jake Jarvis <jake@jarv.is>"
|
||||||
|
|
||||||
# https://docs.github.com/en/free-pro-team@latest/packages/managing-container-images-with-github-container-registry/connecting-a-repository-to-a-container-image#connecting-a-repository-to-a-container-image-on-the-command-line
|
# https://docs.github.com/en/free-pro-team@latest/packages/managing-container-images-with-github-container-registry/connecting-a-repository-to-a-container-image#connecting-a-repository-to-a-container-image-on-the-command-line
|
||||||
LABEL org.opencontainers.image.source https://github.com/jakejarvis/hugo-docker
|
LABEL org.opencontainers.image.source="https://github.com/jakejarvis/hugo-docker"
|
||||||
|
|
||||||
# only install libc6-compat & libstdc++ if we're building extended Hugo
|
# bring over patched binary from build stage
|
||||||
# https://gitlab.com/yaegashi/hugo/commit/22f0d5cbd6114210ba7835468facbdee60609aa2
|
COPY --from=build /go/bin/hugo /usr/bin/hugo
|
||||||
RUN apk update && \
|
|
||||||
apk add --no-cache \
|
# this step is intentionally a bit of a mess to minimize the number of layers in the final image
|
||||||
|
RUN set -euo pipefail && \
|
||||||
|
if [ "$(uname -m)" = "x86_64" ]; then \
|
||||||
|
ARCH="amd64"; \
|
||||||
|
elif [ "$(uname -m)" = "aarch64" ]; then \
|
||||||
|
ARCH="arm64"; \
|
||||||
|
else \
|
||||||
|
echo "Unknown build architecture, quitting." && exit 2; \
|
||||||
|
fi && \
|
||||||
|
# alpine packages
|
||||||
|
# libc6-compat & libstdc++ are required for extended SASS libraries
|
||||||
|
# ca-certificates are required to fetch outside resources (like Twitter oEmbeds)
|
||||||
|
apk add --update --no-cache \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
tzdata \
|
||||||
git \
|
git \
|
||||||
nodejs \
|
nodejs \
|
||||||
npm \
|
npm \
|
||||||
yarn \
|
go \
|
||||||
python3 \
|
python3 \
|
||||||
py3-pip \
|
py3-pip \
|
||||||
ruby \
|
ruby \
|
||||||
${HUGO_EXTENDED:+libc6-compat libstdc++} && \
|
libc6-compat \
|
||||||
update-ca-certificates
|
libstdc++ && \
|
||||||
|
update-ca-certificates && \
|
||||||
# download Hugo and miscellaneous optional dependencies
|
# npm packages
|
||||||
RUN npm install --global postcss postcss-cli autoprefixer @babel/core @babel/cli && \
|
npm install --global --production \
|
||||||
pip3 install --upgrade Pygments==2.* && \
|
yarn \
|
||||||
|
postcss \
|
||||||
|
postcss-cli \
|
||||||
|
autoprefixer \
|
||||||
|
@babel/core \
|
||||||
|
@babel/cli && \
|
||||||
|
npm cache clean --force && \
|
||||||
|
# ruby gems
|
||||||
gem install asciidoctor && \
|
gem install asciidoctor && \
|
||||||
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_EXTENDED:+extended_}${HUGO_VERSION}_Linux-64bit.tar.gz && \
|
# python packages
|
||||||
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_checksums.txt && \
|
python3 -m pip install --no-cache-dir --upgrade Pygments==2.* docutils && \
|
||||||
grep hugo_${HUGO_EXTENDED:+extended_}${HUGO_VERSION}_Linux-64bit.tar.gz hugo_${HUGO_VERSION}_checksums.txt | sha256sum -c && \
|
# manually fetch pandoc binary
|
||||||
tar xf hugo_${HUGO_EXTENDED:+extended_}${HUGO_VERSION}_Linux-64bit.tar.gz && \
|
wget -O pandoc.tar.gz https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-${ARCH}.tar.gz && \
|
||||||
mv ./hugo /usr/local/bin/ && \
|
tar xf pandoc.tar.gz && \
|
||||||
chmod +x /usr/local/bin/hugo && \
|
mv ./pandoc-${PANDOC_VERSION}/bin/pandoc /usr/bin/ && \
|
||||||
rm -rf hugo_* LICENSE README.md
|
chmod +x /usr/bin/pandoc && \
|
||||||
|
rm -rf pandoc.tar.gz pandoc-${PANDOC_VERSION} && \
|
||||||
# fix potential stack size problems on Alpine
|
# manually fetch Dart SASS binary (on x64 only)
|
||||||
# https://github.com/microsoft/vscode-dev-containers/blob/fb63f7e016877e13535d4116b458d8f28012e87f/containers/hugo/.devcontainer/Dockerfile#L19
|
if [ "$ARCH" = "amd64" ]; then \
|
||||||
RUN go get github.com/yaegashi/muslstack && \
|
wget -O sass-embedded.tar.gz https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz && \
|
||||||
muslstack -s 0x800000 /usr/local/bin/hugo
|
tar xf sass-embedded.tar.gz && \
|
||||||
|
mv ./sass_embedded/dart-sass-embedded /usr/bin/ && \
|
||||||
# verify everything's OK, exit otherwise
|
chmod +x /usr/bin/dart-sass-embedded && \
|
||||||
RUN hugo version && \
|
rm -rf sass-embedded.tar.gz sass_embedded; \
|
||||||
|
fi && \
|
||||||
|
# clean up some junk
|
||||||
|
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* && \
|
||||||
|
# make super duper sure that everything went OK, exit otherwise
|
||||||
hugo env && \
|
hugo env && \
|
||||||
|
go version && \
|
||||||
|
node --version && \
|
||||||
|
npm --version && \
|
||||||
|
yarn --version && \
|
||||||
postcss --version && \
|
postcss --version && \
|
||||||
autoprefixer --version && \
|
autoprefixer --version && \
|
||||||
babel --version && \
|
babel --version && \
|
||||||
pygmentize -V && \
|
pygmentize -V && \
|
||||||
asciidoctor --version
|
asciidoctor --version && \
|
||||||
|
pandoc --version && \
|
||||||
|
rst2html.py --version
|
||||||
|
|
||||||
# add site source as volume
|
# add site source as volume
|
||||||
VOLUME /src
|
VOLUME /src
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# expose live-refresh server
|
# expose live-refresh server on default port
|
||||||
EXPOSE 1313
|
EXPOSE 1313
|
||||||
|
|
||||||
ENTRYPOINT ["hugo"]
|
ENTRYPOINT ["hugo"]
|
||||||
|
17
README.md
17
README.md
@ -1,8 +1,8 @@
|
|||||||
# ✏️ [Hugo Extended](https://github.com/gohugoio/hugo) via Docker
|
# ✏️ [Hugo Extended](https://github.com/gohugoio/hugo) via Docker
|
||||||
|
|
||||||
[](https://hub.docker.com/r/jakejarvis/hugo-extended)
|
[](https://github.com/jakejarvis/hugo-docker/actions/workflows/build.yml)
|
||||||
|
|
||||||
A base image to ease local development of Hugo sites, including [Hugo Extended](https://gohugo.io/troubleshooting/faq/#i-get-tocss-this-feature-is-not-available-in-your-current-hugo-version) (with SASS/SCSS support) and optional third-party tools ([listed below](#third-party-software)).
|
A base image to ease local development of Hugo sites, including [Hugo Extended](https://gohugo.io/troubleshooting/faq/#i-get-tocss-this-feature-is-not-available-in-your-current-hugo-version) (with SASS/SCSS support) and optional third-party tools ([listed below](#third-party-software)). Now with [multi-architecture images](https://docs.docker.com/docker-for-mac/multi-arch/) for native AMD64 and ARM64 support!
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -35,15 +35,18 @@ When using Docker to run a live server (i.e. `hugo server`), you must pass `--bi
|
|||||||
|
|
||||||
## Third-party software
|
## Third-party software
|
||||||
|
|
||||||
Just in case, the final container includes a few small third-party tools that are required by certain optional Hugo features:
|
Just in case, the final Alpine Linux container includes a few small third-party tools that are required by certain optional Hugo features:
|
||||||
|
|
||||||
- [PostCSS (CLI)](https://github.com/postcss/postcss-cli)
|
- [PostCSS](https://github.com/postcss/postcss-cli)
|
||||||
- [Autoprefixer](https://github.com/postcss/autoprefixer)
|
- [Autoprefixer](https://github.com/postcss/autoprefixer)
|
||||||
- [Babel (CLI)](https://babeljs.io/)
|
- [Babel](https://babeljs.io/)
|
||||||
- [Pygments](https://pygments.org/)
|
- [Pygments](https://pygments.org/)
|
||||||
- [Asciidoctor](https://asciidoctor.org/)
|
- [Asciidoctor](https://asciidoctor.org/)
|
||||||
|
- [Pandoc](https://pandoc.org/)
|
||||||
|
- [Docutils](https://docutils.sourceforge.io/) / [RST](https://docutils.sourceforge.io/rst.html)
|
||||||
|
- [Embedded Dart Sass](https://github.com/sass/dart-sass-embedded) (amd64 only)
|
||||||
|
|
||||||
Node (with NPM and Yarn) and Go (for [Hugo Modules](https://gohugo.io/hugo-modules/) support) are also pre-installed.
|
Node (with NPM and Yarn), Go (for [Hugo Modules](https://gohugo.io/hugo-modules/) support), and Python are also pre-installed.
|
||||||
|
|
||||||
## Licenses
|
## Licenses
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user