chore(docker): fix netgo, add comment

fix netgo, add comment

Signed-off-by: kovacs <mritd@linux.com>
pull/1349/head
kovacs 3 years ago
parent 1f74f7b082
commit b86d812cdd
No known key found for this signature in database
GPG Key ID: 150E1851F767CDDD

@ -10,8 +10,17 @@ RUN set -ex \
# 编译前端代码 # 编译前端代码
WORKDIR /source/assets WORKDIR /source/assets
# 允许通过 `docker build --build-args YARN_REGISTRY=https://xxxx` 覆盖默认仓库地址 # 允许通过 `docker build --build-args YARN_REGISTRY=https://registry.npmmirror.com` 覆盖默认仓库地址
ARG YARN_REGISTRY=https://registry.yarnpkg.com/ #
# 常用的仓库地址:
# npm ----- https://registry.npmjs.org
# cnpm ---- http://r.cnpmjs.org
# taobao -- https://registry.npmmirror.com
# nj ------ https://registry.nodejitsu.com
# rednpm -- http://registry.mirror.cqupt.edu.cn
# skimdb -- https://skimdb.npmjs.com/registry
# yarn ---- https://registry.yarnpkg.com
ARG YARN_REGISTRY=https://registry.yarnpkg.com
# 允许通过 `docker build --build-args GOPROXY=https://goproxy.cn` 添加 go mod 代理 # 允许通过 `docker build --build-args GOPROXY=https://goproxy.cn` 添加 go mod 代理
ARG GOPROXY="" ARG GOPROXY=""
@ -19,10 +28,10 @@ ARG GOPROXY=""
# 暂不确定未来 alpine 内的 Node 版本是否影响最终编译结果, 故暂时增加打印输出 # 暂不确定未来 alpine 内的 Node 版本是否影响最终编译结果, 故暂时增加打印输出
RUN set -ex \ RUN set -ex \
&& echo "Node Version: $(node -v)" \ && echo "Node Version: $(node -v)" \
&& sed -i -e "s@https://registry.yarnpkg.com/@${YARN_REGISTRY}@g" yarn.lock \ && sed -i -e "s@https://registry.yarnpkg.com@${YARN_REGISTRY}@g" yarn.lock \
&& yarn install \ && yarn install --network-timeout 1000000 \
&& yarn run build \ && yarn run build \
&& find . -name "*.map" -type f -delete && find ./build -name "*.map" -type f -delete
# 编译后端代码 # 编译后端代码
WORKDIR /source WORKDIR /source
@ -35,14 +44,21 @@ RUN set -ex \
-X github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$(git describe --tags) \ -X github.com/cloudreve/Cloudreve/v3/pkg/conf.BackendVersion=$(git describe --tags) \
-X github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$(git rev-parse --short HEAD)" -X github.com/cloudreve/Cloudreve/v3/pkg/conf.LastCommit=$(git rev-parse --short HEAD)"
# 多阶段构建: 构建最终镜像 # 多阶段构建: 构建最终镜像
FROM alpine:latest FROM alpine
# 允许通过 `docker build --build-args TIMEZONE=Africa/Abidjan` 覆盖默认时区 # 允许通过 `docker build --build-args TIMEZONE=Africa/Abidjan` 覆盖默认时区
ARG TZ="Asia/Shanghai" ARG TZ="Asia/Shanghai"
# netgo 兼容修复
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
RUN set -ex \ RUN set -ex \
&& apk add --no-cache tzdata bash \ && apk add --no-cache tzdata ca-certificates bash \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo "${TZ}" > /etc/timezone && echo "${TZ}" > /etc/timezone

@ -2,15 +2,9 @@
set -e set -e
# 创建 aria2 共享目录
mkdir -p /data/aria2
# 确保 aria2 可以被低权限用户写入
chmod -R 766 /data/aria2
# 强制刷新二进制文件 # 强制刷新二进制文件
rm -f /data/bin rm -f /data/bin
cp /usr/bin/cloudreve /data/.bin cp /usr/bin/cloudreve /data/.cloudreve.bin
# 使用 exec 执行并拼接外部 CMD 指令参数 # 使用 exec 执行并拼接外部 CMD 指令参数
exec /data/.bin $@ exec /data/.cloudreve.bin $@

Loading…
Cancel
Save