Skip to content

Commit f2e907b

Browse files
author
刘敏
committed
feat:optimize dockerfile to combine build stage and runtime stage,bump python version to 3.12
1 parent 9cd68ba commit f2e907b

4 files changed

Lines changed: 78 additions & 28 deletions

File tree

docker/amd64/dockerfile

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
FROM python:3.10-slim-bookworm
1+
# Build stage
2+
FROM golang:1.23-bookworm AS builder
23

34
# if you located in China, you can use aliyun mirror to speed up
4-
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list
5-
RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
6-
&& apt-get update \
5+
# RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
6+
7+
# Install build dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
pkg-config \
10+
gcc \
11+
libseccomp-dev \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Copy source code
15+
COPY . /workspace
16+
WORKDIR /workspace
17+
18+
# using goproxy if you have network issues
19+
# ENV GOPROXY=https://goproxy.cn,direct
20+
21+
# Build binaries
22+
RUN chmod +x build/build_amd64.sh \
23+
&& go mod tidy \
24+
&& ./build/build_amd64.sh
25+
26+
# Runtime stage
27+
FROM python:3.12-slim-bookworm
28+
29+
# if you located in China, you can use aliyun mirror to speed up
30+
# RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
31+
32+
RUN apt-get update \
733
&& apt-get install -y --no-install-recommends \
8-
pkg-config \
9-
libseccomp-dev \
1034
wget \
1135
curl \
1236
xz-utils \
1337
zlib1g \
1438
expat \
1539
perl \
1640
libsqlite3-0 \
41+
libseccomp2 \
1742
&& apt-get clean \
1843
&& rm -rf /var/lib/apt/lists/*
1944

20-
# copy main binary to /main
21-
COPY main /main
22-
# copy initial env
23-
COPY env /env
45+
# copy built binaries from builder stage
46+
COPY --from=builder /workspace/main /main
47+
COPY --from=builder /workspace/env /env
2448

2549
# copy config file
2650
COPY conf/config.yaml /conf/config.yaml
@@ -29,11 +53,12 @@ COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt
2953
# copy entrypoint
3054
COPY docker/entrypoint.sh /entrypoint.sh
3155

56+
# if you located in China, you can use tsinghua mirror to speed up pip install
57+
# RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
3258
RUN chmod +x /main /env /entrypoint.sh \
3359
&& pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks] \
3460
&& wget -O /opt/node-v20.11.1-linux-x64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-x64.tar.xz \
35-
&& /env \
36-
&& rm -f /env
61+
&& /env
3762

3863
ENV NODE_TAR_XZ=/opt/node-v20.11.1-linux-x64.tar.xz
3964
ENV NODE_DIR=/opt/node-v20.11.1-linux-x64

docker/arm64/dockerfile

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
FROM python:3.10-slim-bookworm
1+
# Build stage
2+
FROM golang:1.23-bookworm AS builder
23

34
# if you located in China, you can use aliyun mirror to speed up
4-
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list
5-
RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
6-
&& apt-get update \
5+
# RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
6+
7+
# Install build dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
pkg-config \
10+
gcc \
11+
libseccomp-dev \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Copy source code
15+
COPY . /workspace
16+
WORKDIR /workspace
17+
18+
# using goproxy if you have network issues
19+
# ENV GOPROXY=https://goproxy.cn,direct
20+
21+
# Build binaries
22+
RUN chmod +x build/build_arm64.sh \
23+
&& go mod tidy \
24+
&& ./build/build_arm64.sh
25+
26+
# Runtime stage
27+
FROM python:3.12-slim-bookworm
28+
29+
# if you located in China, you can use aliyun mirror to speed up
30+
# RUN sed -i 's@deb.debian.org@mirrors.aliyun.com@g' /etc/apt/sources.list.d/debian.sources
31+
32+
RUN apt-get update \
733
&& apt-get install -y --no-install-recommends \
8-
pkg-config \
9-
libseccomp-dev \
1034
wget \
1135
curl \
1236
xz-utils \
1337
zlib1g \
1438
expat \
1539
perl \
1640
libsqlite3-0 \
41+
libseccomp2 \
1742
&& apt-get clean \
1843
&& rm -rf /var/lib/apt/lists/*
1944

20-
# copy main binary to /main
21-
COPY main /main
22-
# copy initial env
23-
COPY env /env
45+
# copy built binaries from builder stage
46+
COPY --from=builder /workspace/main /main
47+
COPY --from=builder /workspace/env /env
2448

2549
# copy config file
2650
COPY conf/config.yaml /conf/config.yaml
@@ -29,11 +53,12 @@ COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt
2953
# copy entrypoint
3054
COPY docker/entrypoint.sh /entrypoint.sh
3155

56+
# if you located in China, you can use tsinghua mirror to speed up pip install
57+
# RUN pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
3258
RUN chmod +x /main /env /entrypoint.sh \
3359
&& pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.1.6 PySocks httpx[socks] \
3460
&& wget -O /opt/node-v20.11.1-linux-arm64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-arm64.tar.xz \
35-
&& /env \
36-
&& rm -f /env
61+
&& /env
3762

3863
ENV NODE_TAR_XZ=/opt/node-v20.11.1-linux-arm64.tar.xz
3964
ENV NODE_DIR=/opt/node-v20.11.1-linux-arm64

internal/static/config_default_amd64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package static
44

55
var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
6-
"/usr/local/lib/python3.10",
7-
"/usr/lib/python3.10",
6+
"/usr/local/lib/python3.12",
7+
"/usr/lib/python3.12",
88
"/usr/lib/python3",
99
"/usr/lib/x86_64-linux-gnu",
1010
"/etc/ssl/certs/ca-certificates.crt",

internal/static/config_default_arm64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package static
44

55
var DEFAULT_PYTHON_LIB_REQUIREMENTS = []string{
6-
"/usr/local/lib/python3.10",
7-
"/usr/lib/python3.10",
6+
"/usr/local/lib/python3.12",
7+
"/usr/lib/python3.12",
88
"/usr/lib/python3",
99
"/usr/lib/aarch64-linux-gnu",
1010
"/etc/ssl/certs/ca-certificates.crt",

0 commit comments

Comments
 (0)