refactor: build docker image using build.sh (#1562)

pull/1571/head
vvisionnn 2 years ago committed by GitHub
parent 053e4352b4
commit 5f4f6bd91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,44 +1,47 @@
FROM golang:1.18-alpine as cloudreve_builder # 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
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
# install dependencies and build tools # build frontend assets using build script, make sure all the steps just follow the regular release
RUN apk update && apk add --no-cache wget curl git yarn build-base gcc abuild binutils binutils-doc gcc-doc zip WORKDIR /cloudreve_frontend
ENV GENERATE_SOURCEMAP false
RUN chmod +x ./build.sh && ./build.sh -a
WORKDIR /cloudreve_builder
RUN git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git
# build frontend # the backend builder
WORKDIR /cloudreve_builder/Cloudreve/assets # cloudreve backend needs golang 1.18* to build
ENV GENERATE_SOURCEMAP false FROM golang:1.18-alpine as cloudreve_backend_builder
# Disable new OpenSSL to prevent 0308010C:digital envelope routines::unsupported
ENV NODE_OPTIONS --openssl-legacy-provider
RUN yarn install --network-timeout 1000000 # install dependencies and build tools
RUN yarn run build 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
# build backend WORKDIR /cloudreve_backend
WORKDIR /cloudreve_builder/Cloudreve COPY --from=cloudreve_frontend_builder /cloudreve_frontend/assets.zip ./
RUN zip -r - assets/build >assets.zip RUN chmod +x ./build.sh && ./build.sh -c
RUN tag_name=$(git describe --tags) \
&& 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'"
# build final image # TODO: merge the frontend build and backend build into a single one image
# the final published image
FROM alpine:latest FROM alpine:latest
WORKDIR /cloudreve WORKDIR /cloudreve
COPY --from=cloudreve_backend_builder /cloudreve_backend/cloudreve ./cloudreve
RUN apk update && apk add --no-cache tzdata
RUN apk update \
# we using the `Asia/Shanghai` timezone by default, you can do modification at your will && apk add --no-cache tzdata \
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone && echo "Asia/Shanghai" > /etc/timezone \
&& chmod +x ./cloudreve \
COPY --from=cloudreve_builder /cloudreve_builder/Cloudreve/cloudreve ./ && mkdir -p /data/aria2 \
&& chmod -R 766 /data/aria2
# prepare permissions and aria2 dir
RUN chmod +x ./cloudreve && mkdir -p /data/aria2 && chmod -R 766 /data/aria2
EXPOSE 5212 EXPOSE 5212
VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"] VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"]

@ -32,11 +32,15 @@ buildAssets() {
yarn run build yarn run build
cd build cd build
cd $REPO cd $REPO
# please keep in mind that if this final output binary `assets.zip` name changed, please go and update the `Dockerfile` as well
zip -r - assets/build >assets.zip zip -r - assets/build >assets.zip
} }
buildBinary() { buildBinary() {
cd $REPO cd $REPO
# same as assets, if this final output binary `cloudreve` name changed, please go and update the `Dockerfile`
go build -a -o cloudreve -ldflags " -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'" go build -a -o cloudreve -ldflags " -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$VERSION' -X 'github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$COMMIT_SHA'"
} }

Loading…
Cancel
Save