From 22f0d5cbd6114210ba7835468facbdee60609aa2 Mon Sep 17 00:00:00 2001 From: YAEGASHI Takeshi Date: Fri, 21 Jun 2019 01:29:04 +0900 Subject: [PATCH 1/2] Workaround for segmentation faults in hugo_extended registry image - Run muslstack on hugo executable to extend thread stack size to 8MB - Introduce multi-stage builds to reduce image size further - Use alpine:image for the final image muslstack utility: https://github.com/yaegashi/muslstack muslstack test cases using Hugo extended version: https://github.com/yaegashi/muslstack/tree/master/tests/hugo --- Dockerfile | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07b6062..de4a3ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,30 @@ -FROM alpine:latest - +FROM golang:1.12-alpine ARG HUGO=hugo ARG HUGO_VERSION=0.55.6 -ARG HUGO_APK="ca-certificates openssl git" ARG HUGO_SHA=39d3119cdb9ba5d6f1f1b43693e707937ce851791a2ea8d28003f49927c428f4 -ARG HUGO_EXTENDED_APK="libc6-compat libstdc++" ARG HUGO_EXTENDED_SHA=8962b8cdc0ca220da97293cea0bb1b31718cb4d99d0766be6865cb976b1c1805 - -# Install HUGO RUN set -eux && \ case ${HUGO} in \ *_extended) \ - HUGO_APK="${HUGO_APK} ${HUGO_EXTENDED_APK}" \ HUGO_SHA="${HUGO_EXTENDED_SHA}" ;; \ esac && \ - apk add --update --no-cache ${HUGO_APK} && \ - wget -O ${HUGO_VERSION}.tar.gz https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/${HUGO}_${HUGO_VERSION}_Linux-64bit.tar.gz && \ - echo "${HUGO_SHA} ${HUGO_VERSION}.tar.gz" | sha256sum -c && \ - tar xf ${HUGO_VERSION}.tar.gz && mv hugo* /usr/bin/hugo && \ - rm -rf ${HUGO_VERSION}.tar.gz && \ - rm -rf /var/cache/apk/* && \ - hugo version + apk add --update --no-cache ca-certificates openssl git && \ + wget -O ${HUGO_VERSION}.tar.gz https://github.com/spf13/hugo/releases/download/v${HUGO_VERSION}/${HUGO}_${HUGO_VERSION}_Linux-64bit.tar.gz && \ + echo "${HUGO_SHA} ${HUGO_VERSION}.tar.gz" | sha256sum -c && \ + tar xf ${HUGO_VERSION}.tar.gz && mv hugo* /usr/bin/hugo +RUN go get github.com/yaegashi/muslstack +RUN muslstack -s 0x800000 /usr/bin/hugo +FROM alpine:edge +ARG HUGO=hugo +COPY --from=0 /usr/bin/hugo /usr/bin +RUN set -eux && \ + case ${HUGO} in \ + *_extended) \ + apk add --update --no-cache libc6-compat libstdc++ && \ + rm -rf /var/cache/apk/* ;; \ + esac && \ + hugo version EXPOSE 1313 - +WORKDIR /src CMD ["/usr/bin/hugo"] From 9e27fcdcb46d357eeb76f72de46877c8e1fc6f7a Mon Sep 17 00:00:00 2001 From: YAEGASHI Takeshi Date: Thu, 27 Jun 2019 03:07:10 +0900 Subject: [PATCH 2/2] Add some comments in Dockerfile --- Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Dockerfile b/Dockerfile index de4a3ea..cfa59b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,12 @@ +# Dockerfile for Hugo (HUGO=hugo) / Hugo Extended (HUGO=hugo_extended) +# HUGO_VERSION / HUGO_SHA / HUGO_EXTENDED_SHA is automatically updated +# by update.py when new release is available on the upstream. +# Utilize multi-stage builds to make images optimized in size. + +# First stage - download prebuilt hugo binary from the GitHub release. +# Use golang image to run https://github.com/yaegashi/muslstack +# on hugo executable to extend its default thread stack size to 8MB +# to work around segmentation fault issues. FROM golang:1.12-alpine ARG HUGO=hugo ARG HUGO_VERSION=0.55.6 @@ -15,6 +24,8 @@ RUN set -eux && \ RUN go get github.com/yaegashi/muslstack RUN muslstack -s 0x800000 /usr/bin/hugo +# Second stage - build the final image with minimal apk dependencies. +# alpine:edge is required for muslstack to work as of June 2019. FROM alpine:edge ARG HUGO=hugo COPY --from=0 /usr/bin/hugo /usr/bin