Après Comment j’ai viré mon WordPress pour GoHugo, voici comment y apporter quelques optimisations, au niveau Docker et du contenu généré.
Build
L’image Docker
L’image est construite en deux parties : la première partie sert à compiler minify, qui sera par la suite copiée dans l’image définitive.
FROM golang:1.10-alpine as builder
ARG MINIFY_REPO="github.com/tdewolff/minify"
ARG MINIFY_PACKAGE="cmd/minify"
ARG MINIFY_VERSION="2.3.5"
RUN apk add --no-cache --update \
git \
gcc \
libc-dev \
&& cd /go ; go get -v ${MINIFY_REPO}/${MINIFY_PACKAGE} \
&& cd /go/src/${MINIFY_REPO}/${MINIFY_PACKAGE} ; git checkout tags/v${MINIFY_VERSION} -b v${MINIFY_VERSION} \
&& cd /go ; go get -v -d ${MINIFY_REPO}/${MINIFY_PACKAGE} \
&& cd /go ; CGO_ENABLED=0 go build -ldflags "-X main.Version=${MINIFY_VERSION}" -a -o /go/bin/minify -installsuffix cgo ${MINIFY_REPO}/${MINIFY_PACKAGE} \
&& /go/bin/minify --version
FROM alpine:3.7
COPY --from=builder /go/bin/minify /usr/local/bin/
ARG HUGO_VERSION="0.41"
RUN set -x && \
apk add --no-cache --update \
curl \
ca-certificates \
&& curl -L https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz | \
tar -xz hugo -C /usr/local/bin/
Variable
- HUGO_VERSION : version d’Hugo désirée à définir au build (https://github.com/gohugoio/hugo/releases)
- MINIFY_VERSION : version de Minify désirée à définir au build (https://github.com/tdewolff/minify)
La CI
Les tags sont utilisés pour construire des versions spécifiques.
La branche master construit l’image latest.
image: docker:latest
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
build-master:
stage: build
script:
- docker build --pull
--build-arg HUGO_VERSION="${HUGO_VERSION}"
--build-arg MINIFY_VERSION="${MINIFY_VERSION}"
-t "$CI_REGISTRY_IMAGE" .
- docker push "${CI_REGISTRY_IMAGE}"
only:
- master
build:
stage: build
script:
- docker build --pull
--build-arg HUGO_VERSION="${CI_COMMIT_TAG}"
--build-arg MINIFY_VERSION="${MINIFY_VERSION}"
-t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
only:
- master
only:
- tags
Déploiement Hugo
image: ${CI_REGISTRY}/github/hugo-build:latest
variables:
GIT_SUBMODULE_STRATEGY: recursive
pages:
script:
- /usr/local/bin/hugo
- /usr/local/bin/minify -r -o public/ public/
artifacts:
paths:
- public
only:
- master
test:
script:
- hugo
except:
- master
Catégories : Linux