-
Notifications
You must be signed in to change notification settings - Fork 526
/
Dockerfile.build-and-run
69 lines (49 loc) · 1.81 KB
/
Dockerfile.build-and-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#docker build -t bililive-go:build . -f Dockerfile.build-and-run
FROM golang:1.23.4-bullseye AS builder
WORKDIR /build
#安装tar解压xz需要的xz-utils和构建web页面所需的yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y yarn xz-utils
#根据架构安装构建web页面所需的node.js
RUN ARCH=$(uname -m) && \
if [ $ARCH = 'x86_64' ]; then \
NODE_ARCH='x64'; \
elif [ $ARCH = 'aarch64' ]; then \
NODE_ARCH='arm64'; \
else \
echo '不支持的架构: $ARCH'; \
fi && \
wget https://nodejs.org/dist/v18.20.3/node-v18.20.3-linux-${NODE_ARCH}.tar.xz && \
tar Jxvf /build/node-v18.20.3-linux-${NODE_ARCH}.tar.xz && \
rm -rf /usr/bin/node /usr/bin/npm && \
ln -s /build/node-v18.20.3-linux-${NODE_ARCH}/bin/node /usr/bin/node && \
ln -s /build/node-v18.20.3-linux-${NODE_ARCH}/bin/npm /usr/bin/npm
COPY . .
#配置golang编译环境并进行构建
RUN go env -w GO111MODULE=on && \
make build-web && \
make
RUN sh -c "/build/bin/bililive* --version"
FROM alpine
ARG tag
ENV WORKDIR="/srv/bililive"
ENV OUTPUT_DIR="/srv/bililive" \
CONF_DIR="/etc/bililive-go" \
PORT=8080
ENV PUID=0 PGID=0 UMASK=022
RUN mkdir -p $OUTPUT_DIR && \
mkdir -p $CONF_DIR && \
apk update && \
apk --no-cache add ffmpeg libc6-compat curl su-exec tzdata && \
cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY --from=builder /build/bin/bililive* /usr/bin/bililive-go
COPY config.docker.yml $CONF_DIR/config.yml
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
VOLUME $OUTPUT_DIR
EXPOSE $PORT
WORKDIR ${WORKDIR}
ENTRYPOINT [ "sh" ]
CMD [ "/entrypoint.sh" ]