From c5d6855aefd37cf15b75c81d8ff62bca76762f95 Mon Sep 17 00:00:00 2001 From: vvisionnn Date: Tue, 1 Mar 2022 13:49:42 +0000 Subject: [PATCH] Feat: add official Dockerfile --- Dockerfile | 82 +++++++++++++++------------------------------- Dockerfile-contrib | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 Dockerfile-contrib diff --git a/Dockerfile b/Dockerfile index 9f924569..6d2a3555 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,72 +1,44 @@ -# build frontend -FROM node:lts-buster AS fe-builder +FROM golang:alpine as cloudreve_builder -COPY ./assets /assets +WORKDIR /cloudreve_builder -WORKDIR /assets -# If encountered problems like JavaScript heap out of memory, please uncomment the following options -ENV NODE_OPTIONS --max_old_space_size=4096 +# install dependencies and build tools +RUN apk update && apk add --no-cache wget curl git yarn build-base gcc abuild binutils binutils-doc gcc-doc -# yarn repo connection is unstable, adjust the network timeout to 10 min. -RUN set -ex \ - && yarn install --network-timeout 600000 \ +# build frontend +RUN git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git +RUN cd ./Cloudreve/assets \ + && yarn install --network-timeout 1000000 \ && yarn run build # build backend -FROM golang:1.15.1-alpine3.12 AS be-builder - -ENV GO111MODULE on - -COPY . /go/src/github.com/cloudreve/Cloudreve/v3 -COPY --from=fe-builder /assets/build/ /go/src/github.com/cloudreve/Cloudreve/v3/assets/build/ - -WORKDIR /go/src/github.com/cloudreve/Cloudreve/v3 - -RUN set -ex \ - && apk upgrade \ - && apk add gcc libc-dev git \ - && export COMMIT_SHA=$(git rev-parse --short HEAD) \ - && export VERSION=$(git describe --tags) \ - && (cd && go get github.com/rakyll/statik) \ +RUN cd ./Cloudreve \ + && go get github.com/rakyll/statik \ && statik -src=assets/build/ -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico -f \ - && go install -ldflags "-X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=${VERSION}' \ - -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=${COMMIT_SHA}'\ - -w -s" - -# build final image -FROM alpine:3.12 AS dist + && tag_name=$(git describe --tags --abbrev=0) \ + && git checkout ${tag_name} \ + && export COMMIT_SHA=$(git rev-parse --short HEAD) \ + && go build -a -o cloudreve -ldflags " -X 'github.com/HFO4/cloudreve/pkg/conf.BackendVersion=$tag_name' -X 'github.com/HFO4/cloudreve/pkg/conf.LastCommit=$COMMIT_SHA'" -LABEL maintainer="mritd " -# we use the Asia/Shanghai timezone by default, you can be modified -# by `docker build --build-arg=TZ=Other_Timezone ...` -ARG TZ="Asia/Shanghai" +# build final image +FROM alpine:latest -ENV TZ ${TZ} +WORKDIR /cloudreve -COPY --from=be-builder /go/bin/Cloudreve /cloudreve/cloudreve -COPY docker-bootstrap.sh /cloudreve/bootstrap.sh +RUN apk update && apk add --no-cache tzdata -RUN apk upgrade \ - && apk add bash tzdata aria2 \ - && ln -s /cloudreve/cloudreve /usr/bin/cloudreve \ - && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ - && echo ${TZ} > /etc/timezone \ - && rm -rf /var/cache/apk/* \ - && mkdir /etc/cloudreve \ - && ln -s /etc/cloudreve/cloureve.db /cloudreve/cloudreve.db \ - && ln -s /etc/cloudreve/conf.ini /cloudreve/conf.ini +# we using the `Asia/Shanghai` timezone by default, you can do modification at your will +RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone -# cloudreve use tcp 5212 port by default -EXPOSE 5212/tcp +COPY --from=cloudreve_builder /cloudreve_builder/Cloudreve/cloudreve ./ -# cloudreve stores all files(including executable file) in the `/cloudreve` -# directory by default; users should mount the configfile to the `/etc/cloudreve` -# directory by themselves for persistence considerations, and the data storage -# directory recommends using `/data` directory. -VOLUME /etc/cloudreve +# prepare permissions and aria2 dir +RUN chmod +x ./cloudreve && mkdir -p /data/aria2 && chmod -R 766 /data/aria2 -VOLUME /data +EXPOSE 5212 +VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"] -ENTRYPOINT ["sh", "/cloudreve/bootstrap.sh"] +ENTRYPOINT ["./cloudreve"] \ No newline at end of file diff --git a/Dockerfile-contrib b/Dockerfile-contrib new file mode 100644 index 00000000..9f924569 --- /dev/null +++ b/Dockerfile-contrib @@ -0,0 +1,72 @@ +# build frontend +FROM node:lts-buster AS fe-builder + +COPY ./assets /assets + +WORKDIR /assets + +# If encountered problems like JavaScript heap out of memory, please uncomment the following options +ENV NODE_OPTIONS --max_old_space_size=4096 + +# yarn repo connection is unstable, adjust the network timeout to 10 min. +RUN set -ex \ + && yarn install --network-timeout 600000 \ + && yarn run build + +# build backend +FROM golang:1.15.1-alpine3.12 AS be-builder + +ENV GO111MODULE on + +COPY . /go/src/github.com/cloudreve/Cloudreve/v3 +COPY --from=fe-builder /assets/build/ /go/src/github.com/cloudreve/Cloudreve/v3/assets/build/ + +WORKDIR /go/src/github.com/cloudreve/Cloudreve/v3 + +RUN set -ex \ + && apk upgrade \ + && apk add gcc libc-dev git \ + && export COMMIT_SHA=$(git rev-parse --short HEAD) \ + && export VERSION=$(git describe --tags) \ + && (cd && go get github.com/rakyll/statik) \ + && statik -src=assets/build/ -include=*.html,*.js,*.json,*.css,*.png,*.svg,*.ico -f \ + && go install -ldflags "-X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=${VERSION}' \ + -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=${COMMIT_SHA}'\ + -w -s" + +# build final image +FROM alpine:3.12 AS dist + +LABEL maintainer="mritd " + +# we use the Asia/Shanghai timezone by default, you can be modified +# by `docker build --build-arg=TZ=Other_Timezone ...` +ARG TZ="Asia/Shanghai" + +ENV TZ ${TZ} + +COPY --from=be-builder /go/bin/Cloudreve /cloudreve/cloudreve +COPY docker-bootstrap.sh /cloudreve/bootstrap.sh + +RUN apk upgrade \ + && apk add bash tzdata aria2 \ + && ln -s /cloudreve/cloudreve /usr/bin/cloudreve \ + && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ + && echo ${TZ} > /etc/timezone \ + && rm -rf /var/cache/apk/* \ + && mkdir /etc/cloudreve \ + && ln -s /etc/cloudreve/cloureve.db /cloudreve/cloudreve.db \ + && ln -s /etc/cloudreve/conf.ini /cloudreve/conf.ini + +# cloudreve use tcp 5212 port by default +EXPOSE 5212/tcp + +# cloudreve stores all files(including executable file) in the `/cloudreve` +# directory by default; users should mount the configfile to the `/etc/cloudreve` +# directory by themselves for persistence considerations, and the data storage +# directory recommends using `/data` directory. +VOLUME /etc/cloudreve + +VOLUME /data + +ENTRYPOINT ["sh", "/cloudreve/bootstrap.sh"]