chore(docker): build with go-task
build with go-task Signed-off-by: kovacs <mritd@linux.com>
This commit is contained in:
parent
0f6bef9006
commit
f3433168df
2 changed files with 336 additions and 63 deletions
64
Dockerfile
64
Dockerfile
|
@ -1,49 +1,59 @@
|
|||
# the frontend builder
|
||||
# cloudreve need node.js 16* to build frontend,
|
||||
# separate build step and custom image tag will resolve this
|
||||
FROM node:16-alpine as cloudreve_frontend_builder
|
||||
# !!! Doesn't require any cleanup, as multi-stage builds are removed after completion
|
||||
FROM node:16-alpine as frontend_builder
|
||||
|
||||
RUN apk update \
|
||||
&& apk add --no-cache wget curl git yarn zip bash \
|
||||
&& git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve_frontend
|
||||
RUN set -e \
|
||||
&& apk update \
|
||||
&& apk add bash wget curl git zip \
|
||||
&& sh -c "$(curl -sSL https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
|
||||
|
||||
# build frontend assets using build script, make sure all the steps just follow the regular release
|
||||
WORKDIR /cloudreve_frontend
|
||||
ENV GENERATE_SOURCEMAP false
|
||||
RUN chmod +x ./build.sh && ./build.sh -a
|
||||
# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve
|
||||
|
||||
COPY . /cloudreve
|
||||
|
||||
WORKDIR /cloudreve
|
||||
|
||||
RUN task build-frontend
|
||||
|
||||
|
||||
# the backend builder
|
||||
# cloudreve backend needs golang 1.18* to build
|
||||
FROM golang:1.18-alpine as cloudreve_backend_builder
|
||||
# !!! Doesn't require any cleanup, as multi-stage builds are removed after completion
|
||||
FROM golang:1.18-alpine as backend_builder
|
||||
|
||||
# install dependencies and build tools
|
||||
RUN apk update \
|
||||
# install dependencies and build tools
|
||||
&& apk add --no-cache wget curl git build-base gcc abuild binutils binutils-doc gcc-doc zip bash \
|
||||
&& git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve_backend
|
||||
RUN set -e \
|
||||
&& apk update \
|
||||
&& apk add bash wget curl git build-base \
|
||||
&& sh -c "$(curl -sSL https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
|
||||
|
||||
WORKDIR /cloudreve_backend
|
||||
COPY --from=cloudreve_frontend_builder /cloudreve_frontend/assets.zip ./
|
||||
RUN chmod +x ./build.sh && ./build.sh -c
|
||||
# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve
|
||||
|
||||
COPY . /cloudreve
|
||||
|
||||
WORKDIR /cloudreve
|
||||
|
||||
COPY --from=frontend_builder /cloudreve/assets.zip ./
|
||||
|
||||
RUN task build-backend "TASK=docker"
|
||||
|
||||
|
||||
# TODO: merge the frontend build and backend build into a single one image
|
||||
# the final published image
|
||||
# the final builder
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /cloudreve
|
||||
COPY --from=cloudreve_backend_builder /cloudreve_backend/cloudreve ./cloudreve
|
||||
|
||||
RUN apk update \
|
||||
&& apk add --no-cache tzdata \
|
||||
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||
&& chmod +x ./cloudreve \
|
||||
&& mkdir -p /data/aria2 \
|
||||
&& chmod -R 766 /data/aria2
|
||||
COPY --from=backend_builder /cloudreve/release/cloudreve-docker ./cloudreve
|
||||
|
||||
# !!! For i18n users, do not set timezone
|
||||
RUN set -e \
|
||||
&& apk update \
|
||||
&& apk add bash ca-certificates tzdata \
|
||||
&& rm -f /var/cache/apk/*
|
||||
|
||||
EXPOSE 5212
|
||||
|
||||
VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"]
|
||||
|
||||
ENTRYPOINT ["./cloudreve"]
|
||||
|
|
335
Taskfile.yaml
335
Taskfile.yaml
|
@ -8,14 +8,21 @@ vars:
|
|||
CGO_ENABLED: 1
|
||||
|
||||
tasks:
|
||||
clean:
|
||||
desc: Clean Build Dir
|
||||
clean-frontend:
|
||||
desc: Clean Frontend Build Files
|
||||
cmds:
|
||||
- rm -rf assets/build assets/node_modules assets.zip release
|
||||
- rm -rf assets/build assets/node_modules assets.zip
|
||||
status:
|
||||
- test ! -d assets/build
|
||||
- test ! -d assets/node_modules
|
||||
- test ! -f assets.zip
|
||||
- test ! -d release
|
||||
|
||||
clean-backend:
|
||||
desc: Clean Backend Build Files
|
||||
cmds:
|
||||
- rm -f release/cloudreve-{{.TASK}}{{.BINEXT}}
|
||||
status:
|
||||
- test ! -d release/cloudreve-{{.TASK}}{{.BINEXT}}
|
||||
|
||||
mkdir:
|
||||
desc: Create Build Dir
|
||||
|
@ -31,81 +38,337 @@ tasks:
|
|||
GENERATE_SOURCEMAP: false
|
||||
dir: assets
|
||||
cmds:
|
||||
- task: clean-frontend
|
||||
- yarn install
|
||||
- yarn build
|
||||
- zip -r - build > ../assets.zip
|
||||
- cd .. && zip -r - assets/build > assets.zip
|
||||
status:
|
||||
- test -d node_modules
|
||||
- test -d build
|
||||
|
||||
build-backend:
|
||||
desc: Cloudreve Backend Build Template(Do not execute this Task directly)
|
||||
label: build-{{.PLATFORM}}
|
||||
label: build-{{.TASK}}
|
||||
cmds:
|
||||
- task: mkdir
|
||||
- task: build-frontend
|
||||
- task: clean-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: "{{.BINEXT}}"
|
||||
}
|
||||
- |
|
||||
GOOS={{.GOOS}} GOARCH={{.GOARCH}} GOARM={{.GOARM}} GOMIPS={{.GOMIPS}} CC={{.CC}} \
|
||||
go build -trimpath -o release/cloudreve-{{.PLATFORM}}{{.OSEXT}} -ldflags \
|
||||
GOOS={{.GOOS}} GOARCH={{.GOARCH}} GOARM={{.GOARM}} GOMIPS={{.GOMIPS}} CGO_ENABLED={{.CGO_ENABLED}} CC={{.CC}} \
|
||||
go build -trimpath -o release/cloudreve-{{.TASK}}{{.BINEXT}} -ldflags \
|
||||
"-w -s -X github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion={{.VERSION}} \
|
||||
-X github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit={{.COMMIT_SHA}}"
|
||||
|
||||
linux-amd64-gcc:
|
||||
desc: Build Cloudreve Backend(linux/amd64/gcc)
|
||||
|
||||
linux-amd64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
PLATFORM: linux-amd64-gcc,
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: amd64
|
||||
}
|
||||
linux-amd64-v2:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: amd64,
|
||||
CC: gcc
|
||||
GOAMD64: v2
|
||||
}
|
||||
linux-arm-gnueabihf-gcc:
|
||||
desc: Build Cloudreve Backend(linux/arm/arm-linux-gnueabihf-gcc)
|
||||
linux-amd64-v3:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
PLATFORM: linux-arm-gnueabihf-gcc,
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v3
|
||||
}
|
||||
linux-amd64-v4:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v4
|
||||
}
|
||||
linux-armv5:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: arm,
|
||||
CC: arm-linux-gnueabihf-gcc
|
||||
GOARM: 5
|
||||
}
|
||||
linux-arm64-gnu-gcc:
|
||||
desc: Build Cloudreve Backend(linux/arm64/aarch64-linux-gnu-gcc)
|
||||
linux-armv6:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
PLATFORM: linux-arm64-gnu-gcc,
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: arm64,
|
||||
CC: aarch64-linux-gnu-gcc
|
||||
GOARCH: arm,
|
||||
GOARM: 6
|
||||
}
|
||||
windows-amd64-mingw32-gcc:
|
||||
desc: Build Cloudreve Backend(windows/amd64/x86_64-w64-mingw32-gcc)
|
||||
linux-armv7:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
PLATFORM: windows-amd64-mingw32-gcc,
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: arm,
|
||||
GOARM: 7
|
||||
}
|
||||
linux-armv8:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: arm64
|
||||
}
|
||||
linux-mips-hardfloat:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: mips,
|
||||
GOMIPS: hardfloat
|
||||
}
|
||||
linux-mipsle-softfloat:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: mipsle,
|
||||
GOMIPS: softfloat
|
||||
}
|
||||
linux-mipsle-hardfloat:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: mipsle,
|
||||
GOMIPS: hardfloat
|
||||
}
|
||||
linux-mips64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: mips64
|
||||
}
|
||||
linux-mips64le:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: linux,
|
||||
GOARCH: mips64le
|
||||
}
|
||||
darwin-amd64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: darwin,
|
||||
GOARCH: amd64
|
||||
}
|
||||
darwin-amd64-v2:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: darwin,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v2
|
||||
}
|
||||
darwin-amd64-v3:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: darwin,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v3
|
||||
}
|
||||
darwin-amd64-v4:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: darwin,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v4
|
||||
}
|
||||
darwin-arm64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: darwin,
|
||||
GOARCH: arm64
|
||||
}
|
||||
freebsd-386:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: 386
|
||||
}
|
||||
freebsd-amd64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: amd64
|
||||
}
|
||||
freebsd-amd64-v2:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v2
|
||||
}
|
||||
freebsd-amd64-v3:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v3
|
||||
}
|
||||
freebsd-amd64-v4:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v4
|
||||
}
|
||||
freebsd-arm:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: arm
|
||||
}
|
||||
freebsd-arm64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
GOOS: freebsd,
|
||||
GOARCH: arm64
|
||||
}
|
||||
windows-386:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: 386
|
||||
}
|
||||
windows-amd64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: amd64
|
||||
}
|
||||
windows-amd64-v2:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: amd64,
|
||||
CC: x86_64-w64-mingw32-gcc,
|
||||
OSEXT: .exe
|
||||
GOAMD64: v2
|
||||
}
|
||||
windows-amd64-v3:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v3
|
||||
}
|
||||
windows-amd64-v4:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: amd64,
|
||||
GOAMD64: v4
|
||||
}
|
||||
windows-arm64:
|
||||
cmds:
|
||||
- task: build-backend
|
||||
vars: {
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: ".exe",
|
||||
GOOS: windows,
|
||||
GOARCH: arm64
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
cmds:
|
||||
- task: clean
|
||||
- task: build-frontend
|
||||
- task: build-backend
|
||||
vars: {
|
||||
PLATFORM: "{{OS}}-{{ARCH}}",
|
||||
OSEXT: "{{exeExt}}"
|
||||
TASK: "{{.TASK}}",
|
||||
BINEXT: "{{exeExt}}"
|
||||
}
|
||||
|
||||
release:
|
||||
cmds:
|
||||
- task: clean
|
||||
- task: linux-amd64-gcc
|
||||
- task: linux-arm-gnueabihf-gcc
|
||||
- task: linux-arm64-gnu-gcc
|
||||
- task: windows-amd64-mingw32-gcc
|
||||
- task: build-frontend
|
||||
- task: linux-amd64
|
||||
- task: linux-amd64-v2
|
||||
- task: linux-amd64-v3
|
||||
- task: linux-amd64-v4
|
||||
- task: linux-armv5
|
||||
- task: linux-armv6
|
||||
- task: linux-armv7
|
||||
- task: linux-armv8
|
||||
- task: linux-mips-hardfloat
|
||||
- task: linux-mipsle-softfloat
|
||||
- task: linux-mipsle-hardfloat
|
||||
- task: linux-mips64
|
||||
- task: linux-mips64le
|
||||
- task: darwin-amd64
|
||||
- task: darwin-amd64-v2
|
||||
- task: darwin-amd64-v3
|
||||
- task: darwin-amd64-v4
|
||||
- task: darwin-arm64
|
||||
- task: windows-386
|
||||
- task: windows-amd64
|
||||
- task: windows-amd64-v2
|
||||
- task: windows-amd64-v3
|
||||
- task: windows-amd64-v4
|
||||
- task: windows-arm64
|
||||
|
|
Loading…
Add table
Reference in a new issue