chore(build): add go-task support (#1608)

* chore(build): add go-task support

add go-task support

Signed-off-by: kovacs <mritd@linux.com>

* chore(docker): build with go-task

build with go-task

Signed-off-by: kovacs <mritd@linux.com>

* chore(task): support cross compile

support cross compile

Signed-off-by: kovacs <mritd@linux.com>

* chore(task): remove GCC build

remove GCC build

Signed-off-by: kovacs <mritd@linux.com>

* docs(task): update README

update README

Signed-off-by: kovacs <mritd@linux.com>

---------

Signed-off-by: kovacs <mritd@linux.com>
This commit is contained in:
mritd
2023-02-08 13:57:21 +08:00
committed by GitHub
parent 9c58278e08
commit abe90e4c88
4 changed files with 559 additions and 85 deletions

View File

@@ -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
# Maybe copying the current directory is more accurate?
# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve
# 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
COPY . /cloudreve
WORKDIR /cloudreve
RUN task clean-frontend 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
# Maybe copying the current directory is more accurate?
# && git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git /cloudreve
WORKDIR /cloudreve_backend
COPY --from=cloudreve_frontend_builder /cloudreve_frontend/assets.zip ./
RUN chmod +x ./build.sh && ./build.sh -c
COPY . /cloudreve
WORKDIR /cloudreve
COPY --from=frontend_builder /cloudreve/assets.zip ./
RUN task clean-backend build-backend "PLATFORM=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"]