Update Dockerfile

Use released binary file from github rather than build with static flag. this will make docker image's behavior as same as released binary file. and pack with static library flag will take up additional image space.
使用github上已经发布的二进制文件而不是使用静态链接库标志构建,这可以使docker映像的行为与release的二进制文件保持一致。并且,使用静态链接库标志,将占用额外的镜像空间。
pull/1280/head
姚春锋 3 years ago committed by GitHub
parent 5bd711afc6
commit 41232d11b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,40 +1,41 @@
FROM golang:1.17-alpine as cloudreve_builder FROM alpine:latest as builder
ARG TARGETARCH
ARG TARGETVARIANT
# install dependencies and build tools ARG ReleaseApi="https://api.github.com/repos/cloudreve/Cloudreve/releases/latest"
RUN apk update && apk add --no-cache wget curl git yarn build-base gcc abuild binutils binutils-doc gcc-doc zip
WORKDIR /cloudreve_builder WORKDIR /ProjectCloudreve
RUN git clone --recurse-submodules https://github.com/cloudreve/Cloudreve.git
# build frontend RUN apk add tar gzip curl sed grep
WORKDIR /cloudreve_builder/Cloudreve/assets
RUN yarn install --network-timeout 1000000
RUN yarn run build && find . -name "*.map" -type f -delete
# build backend RUN echo "${TARGETARCH}<======>${TARGETVARIANT}"
WORKDIR /cloudreve_builder/Cloudreve
RUN zip -r - assets/build >assets.zip
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'"
RUN if [ "0$(uname -m)" = "0x86_64" ]; then export Arch="amd64" ;fi \
&& if [ "0$(uname -m)" = "0arm64" ] || [ "0$(uname -m)" = "0aarch64" ]; then export Arch="arm64" ;fi \
&& if [ "0$(uname -m)" = "0arm" ] || [ "0$(uname -m)" = "0armv7l" ]; then export Arch="arm" ;fi \
&& if [ "0$Arch" = "0" ]; then exit 5 ;fi \
&& targetUrl=$(curl -s "${ReleaseApi}" | sed -e 's/"/\n/g' | grep http | grep linux | grep "${Arch}.tar") \
&& echo ">>>>>> AssetUrl: ${targetUrl}" \
&& curl -L --max-redirs 10 -o ./cloudreve.tar.gz "${targetUrl}"
RUN tar xzf ./cloudreve.tar.gz
# build final image # build final image
FROM alpine:latest FROM alpine:latest
WORKDIR /cloudreve WORKDIR /cloudreve
RUN apk update && apk add --no-cache tzdata RUN apk update && apk add --no-cache gcompat tzdata
# we using the `Asia/Shanghai` timezone by default, you can do modification at your will # we using the `Asia/Shanghai` timezone by default, you can do modification at your will
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone && echo "Asia/Shanghai" > /etc/timezone
COPY --from=cloudreve_builder /cloudreve_builder/Cloudreve/cloudreve ./ COPY --from=cloudreve_builder /ProjectCloudreve/cloudreve ./
# prepare permissions and aria2 dir # prepare permissions and aria2 dir(directory only)
RUN chmod +x ./cloudreve && mkdir -p /data/aria2 && chmod -R 766 /data/aria2 RUN chmod +x ./cloudreve && mkdir -p /data/aria2 && chmod /data/aria2
EXPOSE 5212 EXPOSE 5212
VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"] VOLUME ["/cloudreve/uploads", "/cloudreve/avatar", "/data"]

Loading…
Cancel
Save