# syntax=docker/dockerfile:1.6 ARG FRONTEND_MIRROR=https://gitclone.com/github.com/cloudreve/frontend.git ARG GO_PROXY=https://goproxy.cn,direct ARG NPM_REGISTRY=https://registry.npmmirror.com # ======================================== # Stage 1: Frontend build # ======================================== FROM node:20-alpine AS frontend-build ARG FRONTEND_MIRROR ARG NPM_REGISTRY WORKDIR /build RUN apk add --no-cache git zip tzdata RUN --mount=type=cache,target=/tmp/git-cache \ git clone --depth 1 ${FRONTEND_MIRROR} assets WORKDIR /build/assets RUN npm config set registry ${NPM_REGISTRY} && \ yarn config set registry ${NPM_REGISTRY} RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \ --mount=type=cache,target=/build/assets/node_modules \ yarn install --network-timeout 1000000 --frozen-lockfile || yarn install --network-timeout 1000000 RUN export NODE_OPTIONS="--max-old-space-size=8192" && yarn run build WORKDIR /build RUN mkdir -p application/statics && \ cd assets/build && zip -r - . > /build/application/statics/assets.zip # ======================================== # Stage 2: Backend build # ======================================== FROM golang:1.23-alpine AS backend-build ARG GO_PROXY WORKDIR /src RUN apk add --no-cache git tzdata gcc musl-dev ENV CGO_ENABLED=0 \ GOOS=linux \ GOARCH=amd64 \ GOPROXY=${GO_PROXY} COPY go.mod go.sum ./ RUN --mount=type=cache,target=/go/pkg/mod \ go mod download COPY . . COPY --from=frontend-build /build/application/statics/assets.zip ./application/statics/assets.zip RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ go build -trimpath -ldflags "-s -w -X 'github.com/cloudreve/Cloudreve/v4/pkg/conf.BackendVersion=byw-${BUILD_DATE:-dev}'" -o /cloudreve . # ======================================== # Stage 3: Runtime image # ======================================== FROM alpine:latest AS runtime WORKDIR /cloudreve RUN apk update && \ apk add --no-cache tzdata vips-tools ffmpeg libreoffice aria2 supervisor font-noto font-noto-cjk libheif libraw-tools && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone && \ mkdir -p ./data/temp/aria2 && \ chmod -R 766 ./data/temp/aria2 && \ rm -rf /var/cache/apk/* ENV CR_ENABLE_ARIA2=1 \ CR_SETTING_DEFAULT_thumb_ffmpeg_enabled=1 \ CR_SETTING_DEFAULT_thumb_vips_enabled=1 \ CR_SETTING_DEFAULT_thumb_libreoffice_enabled=1 \ CR_SETTING_DEFAULT_media_meta_ffprobe=1 \ CR_SETTING_DEFAULT_thumb_libraw_enabled=1 COPY .build/aria2.supervisor.conf .build/entrypoint.sh ./ COPY --from=backend-build /cloudreve ./cloudreve RUN chmod +x ./cloudreve && \ chmod +x ./entrypoint.sh EXPOSE 5212 443 6888 6888/udp VOLUME ["/cloudreve/data"] ENTRYPOINT ["sh", "./entrypoint.sh"]