This commit is contained in:
csgeek 2022-08-02 19:58:46 +08:00 committed by GitHub
commit d8365ea557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 28 deletions

View file

@ -1,10 +1,12 @@
FROM amd64/golang:1.14-alpine AS build
ARG GO_VERSION=1.17
RUN apk add --no-cache git build-base && \
git clone --branch v0.70.0 https://github.com/gohugoio/hugo.git && \
cd hugo/ && \
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo . && \
CGO_ENABLED=1 go build -tags extended -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo-extended
FROM amd64/golang:$GO_VERSION-alpine AS hugo_builder
ARG HUGO_VERSION=0.91.0
ADD docker/scripts/build_hugo.sh .
RUN sh build_hugo.sh $HUGO_VERSION
FROM plugins/base:linux-amd64
@ -16,10 +18,10 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
RUN apk --no-cache add git libc6-compat libstdc++
ENV PLUGIN_HUGO_ARCH=64bit
ENV PLUGIN_HUGO_SHIPPED_VERSION=0.70.0
ENV PLUGIN_HUGO_SHIPPED_VERSION=$HUGO_VERSION
COPY --from=build /tmp/hugo /bin/hugo
COPY --from=build /tmp/hugo-extended /bin/hugo-extended
COPY --from=hugo_builder /tmp/hugo /bin/hugo
COPY --from=hugo_builder /tmp/hugo-extended /bin/hugo-extended
ADD release/linux/amd64/drone-hugo /bin/
ENTRYPOINT ["/bin/drone-hugo"]

View file

@ -1,10 +1,12 @@
FROM arm32v6/golang:1.14-alpine AS build
ARG GO_VERSION=1.17
RUN apk add --no-cache git build-base && \
git clone --branch v0.70.0 https://github.com/gohugoio/hugo.git && \
cd hugo/ && \
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo . && \
CGO_ENABLED=1 go build -tags extended -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo-extended
FROM arm32v6/golang:$GO_VERSION-alpine AS hugo_builder
ARG HUGO_VERSION=0.91.0
ADD docker/scripts/build_hugo.sh .
RUN sh build_hugo.sh $HUGO_VERSION
FROM plugins/base:linux-arm
@ -16,10 +18,10 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
RUN apk --no-cache add git libc6-compat libstdc++
ENV PLUGIN_HUGO_ARCH=arm
ENV PLUGIN_HUGO_SHIPPED_VERSION=0.70.0
ENV PLUGIN_HUGO_SHIPPED_VERSION=$HUGO_VERSION
COPY --from=build /tmp/hugo /bin/hugo
COPY --from=build /tmp/hugo-extended /bin/hugo-extended
COPY --from=hugo_builder /tmp/hugo /bin/hugo
COPY --from=hugo_builder /tmp/hugo-extended /bin/hugo-extended
ADD release/linux/arm/drone-hugo /bin/
ENTRYPOINT ["/bin/drone-hugo"]

View file

@ -1,11 +1,12 @@
FROM arm64v8/golang:1.14-alpine AS build
ARG GO_VERSION=1.17
RUN apk add --no-cache git build-base && \
git clone --branch v0.70.0 https://github.com/gohugoio/hugo.git && \
cd hugo/ && \
CGO_ENABLED=0 go build -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo . && \
CGO_ENABLED=1 go build -tags extended -ldflags "-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=$(git rev-parse --short HEAD)" -o /tmp/hugo-extended
FROM arm32v6/golang:$GO_VERSION-alpine AS hugo_builder
ARG HUGO_VERSION=0.91.0
ADD docker/scripts/build_hugo.sh .
RUN sh build_hugo.sh $HUGO_VERSION
FROM plugins/base:linux-arm64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
@ -16,10 +17,10 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
RUN apk --no-cache add git libc6-compat libstdc++
ENV PLUGIN_HUGO_ARCH=arm64
ENV PLUGIN_HUGO_SHIPPED_VERSION=0.70.0
ENV PLUGIN_HUGO_SHIPPED_VERSION=$HUGO_VERSION
COPY --from=build /tmp/hugo /bin/hugo
COPY --from=build /tmp/hugo-extended /bin/hugo-extended
COPY --from=hugo_builder /tmp/hugo /bin/hugo
COPY --from=hugo_builder /tmp/hugo-extended /bin/hugo-extended
ADD release/linux/arm64/drone-hugo /bin/
ENTRYPOINT ["/bin/drone-hugo"]

22
docker/scripts/build_hugo.sh Executable file
View file

@ -0,0 +1,22 @@
#! /bin/sh
set -e
hugo_version=${HUGO_VERSION:-0.91.0}
echo "downloading build dependencies..."
apk add -U --no-cache git build-base
LDFLAGS="-s -w -X github.com/gohugoio/hugo/common/hugo.buildDate=\$(date +%Y-%m-%dT%H:%M:%SZ) -X github.com/gohugoio/hugo/common/hugo.commitHash=\$(git rev-parse --short HEAD)"
echo "downloading hugo version v$hugo_version..."
git clone --branch "v$hugo_version" https://github.com/gohugoio/hugo.git
echo "building hugo..."
cd hugo
CGO_ENABLED=0 go build -ldflags "\"$LDFLAGS\"" -o /tmp/hugo .
CGO_ENABLED=1 go build -tags extended -ldflags "\"$LDFLAGS\"" -o /tmp/hugo-extended
echo "done."

2
go.mod
View file

@ -1,5 +1,7 @@
module github.com/drone-plugins/drone-hugo
go 1.17
require (
github.com/pkg/errors v0.8.1
github.com/urfave/cli v1.20.0

View file

@ -5,7 +5,7 @@ local test_pipeline_name = 'testing';
local windows(os) = os == 'windows';
local golang_image(os, version) =
'golang:' + '1.14' + if windows(os) then '-windowsservercore-' + version else '';
'golang:' + '1.17' + if windows(os) then '-windowsservercore-' + version else '';
{
test(os='linux', arch='amd64', version='')::