1
mirror of https://github.com/jakejarvis/hugo-docker.git synced 2025-07-01 23:56:42 -04:00

Compare commits

...

9 Commits

Author SHA1 Message Date
b807ac60eb Hugo v0.82.0 2021-03-21 17:10:28 -04:00
2cf9bd62af clone source from Git repo instead of downloading from GitHub release 2021-03-14 11:28:44 -04:00
30f54331e8 pin alpine to 3.13 2021-03-14 11:05:03 -04:00
791ec15da8 run CI on new tags 2021-03-08 06:46:43 -05:00
deaf886150 trim a layer off final stage 2021-03-07 15:34:45 -05:00
248ff169bd correct labeling of final image 2021-03-06 10:35:32 -05:00
9be7813071 update readme & random cleanup 2021-03-06 10:12:11 -05:00
783939f439 Switch to building from source for multi-platform images (#1)
...so we can support platforms that official releases don't exist for (namely Linux on ARM64). Just building x86_64 and ARM64 for now, so I can work on my M1 mac.
2021-03-06 09:09:17 -05:00
54f06a59e8 Hugo v0.81.0
also force AMD64 base image (ran into problems with Docker on Apple Silicon since there's no ARM Linux version of Hugo)
2021-02-20 22:57:25 -05:00
4 changed files with 161 additions and 88 deletions

80
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,80 @@
name: Build and Push
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
docker:
runs-on: ubuntu-latest
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 }}

View File

@ -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

View File

@ -1,11 +1,59 @@
# 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.82.0
# 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
FROM golang:1.16-alpine3.13 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 update && \
apk add --no-cache \
gcc \
g++ \
musl-dev \
git && \
go get github.com/magefile/mage
# clone source from Git repo:
RUN git clone \
--branch "v${HUGO_VERSION}" \
--single-branch \
--depth 1 \
https://github.com/gohugoio/hugo.git ./
# download source from GitHub release (old method):
# RUN wget https://github.com/gohugoio/hugo/archive/v${HUGO_VERSION}.tar.gz && \
# tar xf v${HUGO_VERSION}.tar.gz --strip-components=1 && \
# rm v${HUGO_VERSION}.tar.gz
RUN mage -v hugo && mage install
# fix potential stack size problems on Alpine
# https://github.com/microsoft/vscode-dev-containers/blob/fb63f7e016877e13535d4116b458d8f28012e87f/containers/hugo/.devcontainer/Dockerfile#L19
RUN go get github.com/yaegashi/muslstack && \
muslstack -s 0x800000 /go/bin/hugo
# ---
FROM alpine:3.13
# renew global args from above
ARG HUGO_VERSION
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,10 +61,13 @@ 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/local/bin/hugo
# libc6-compat & libstdc++ are required for extended SASS libraries
# ca-certificates are required to fetch outside resources (like Twitter oEmbeds)
RUN apk update && \ RUN apk update && \
apk add --no-cache \ apk add --no-cache \
ca-certificates \ ca-certificates \
@ -24,32 +75,26 @@ RUN apk update && \
nodejs \ nodejs \
npm \ npm \
yarn \ 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 install --global --production \
RUN npm install --global postcss postcss-cli autoprefixer @babel/core @babel/cli && \ postcss \
pip3 install --upgrade Pygments==2.* && \ postcss-cli \
autoprefixer \
@babel/core \
@babel/cli && \
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 && \ pip3 install --upgrade Pygments==2.*
wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_checksums.txt && \
grep hugo_${HUGO_EXTENDED:+extended_}${HUGO_VERSION}_Linux-64bit.tar.gz hugo_${HUGO_VERSION}_checksums.txt | sha256sum -c && \
tar xf hugo_${HUGO_EXTENDED:+extended_}${HUGO_VERSION}_Linux-64bit.tar.gz && \
mv ./hugo /usr/local/bin/ && \
chmod +x /usr/local/bin/hugo && \
rm -rf hugo_* LICENSE README.md
# fix potential stack size problems on Alpine
# https://github.com/microsoft/vscode-dev-containers/blob/fb63f7e016877e13535d4116b458d8f28012e87f/containers/hugo/.devcontainer/Dockerfile#L19
RUN go get github.com/yaegashi/muslstack && \
muslstack -s 0x800000 /usr/local/bin/hugo
# verify everything's OK, exit otherwise # verify everything's OK, exit otherwise
RUN hugo version && \ RUN hugo env && \
hugo env && \ go version && \
node --version && \
postcss --version && \ postcss --version && \
autoprefixer --version && \ autoprefixer --version && \
babel --version && \ babel --version && \
@ -60,7 +105,7 @@ RUN hugo version && \
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"]

View File

@ -1,8 +1,8 @@
# ✏️ [Hugo Extended](https://github.com/gohugoio/hugo) via Docker # ✏️ [Hugo Extended](https://github.com/gohugoio/hugo) via Docker
[![Build docs](https://img.shields.io/docker/cloud/build/jakejarvis/hugo-extended?label=Docker%20Hub&logo=docker&logoColor=%23fff)](https://hub.docker.com/r/jakejarvis/hugo-extended) [![Build](https://github.com/jakejarvis/hugo-docker/actions/workflows/build.yml/badge.svg?branch=master)](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 includes native support for both AMD64 and ARM64 platforms!
## Usage ## Usage
@ -35,11 +35,11 @@ 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/)