Skip to content

Commit 71b07a2

Browse files
committed
Bump Alpine version to 3.23 and reduce Docker image size via multi-stage build
- Bump base image from Alpine 3.19 to 3.23 - Implement multi-stage build to reduce image size
1 parent 6410fba commit 71b07a2

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

docker/alpine/Dockerfile

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
FROM alpine:3.19
2-
LABEL maintainer="kev <noreply@datageek.info>, Sah <contact@leesah.name>, vndroid <waveworkshop@outlook.com>"
1+
FROM alpine:3.23 AS builder
32

4-
ENV SERVER_ADDR=0.0.0.0
5-
ENV SERVER_PORT=8388
6-
ENV PASSWORD=
7-
ENV METHOD=aes-256-gcm
8-
ENV TIMEOUT=300
9-
ENV DNS_ADDRS="8.8.8.8,8.8.4.4"
10-
ENV TZ=UTC
11-
ENV ARGS=
3+
# Temporary root directory for build output
4+
ENV DEST_DIR=/tmp/dest
125

136
COPY . /tmp/repo
147
RUN set -x \
@@ -28,20 +21,37 @@ RUN set -x \
2821
&& mkdir -p build && cd build \
2922
&& cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=OFF -DWITH_STATIC=OFF -DCMAKE_BUILD_TYPE=Release \
3023
&& make -j$(getconf _NPROCESSORS_ONLN) \
31-
&& make install \
32-
&& cd /usr/local/bin \
33-
&& ls /usr/local/bin/ss-* | xargs -n1 setcap cap_net_bind_service+ep \
34-
&& strip $(scanelf --nobanner -E ET_DYN -E ET_EXEC /usr/local/bin/ss-* | awk '{print $2}') \
35-
&& apk del .build-deps \
24+
&& mkdir -p ${DEST_DIR} \
25+
&& make install DESTDIR=${DEST_DIR} \
26+
&& cd ${DEST_DIR}/usr/local/bin \
27+
&& ls ${DEST_DIR}/usr/local/bin/ss-* | xargs -n1 setcap cap_net_bind_service+ep \
28+
&& strip $(scanelf --nobanner -E ET_DYN -E ET_EXEC ${DEST_DIR}/usr/local/bin/ss-* | awk '{print $2}')
29+
30+
# Final runtime environment
31+
FROM alpine:3.23
32+
LABEL maintainer="kev <noreply@datageek.info>, Sah <contact@leesah.name>, vndroid <waveworkshop@outlook.com>"
33+
34+
ENV SERVER_ADDR=0.0.0.0
35+
ENV SERVER_PORT=8388
36+
ENV PASSWORD=
37+
ENV METHOD=aes-256-gcm
38+
ENV TIMEOUT=300
39+
ENV DNS_ADDRS="8.8.8.8,8.8.4.4"
40+
ENV TZ=UTC
41+
ENV ARGS=
42+
43+
# Import build artifacts from the builder stage
44+
COPY --from=builder /tmp/dest/ /
45+
46+
RUN set -x \
3647
# Runtime dependencies setup
3748
&& apk add --no-cache \
3849
ca-certificates \
3950
rng-tools \
4051
tzdata \
4152
$(scanelf --needed --nobanner /usr/local/bin/ss-* \
4253
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
43-
| sort -u) \
44-
&& rm -rf /tmp/repo
54+
| sort -u)
4555

4656
COPY ./docker/alpine/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
4757
ENTRYPOINT ["docker-entrypoint.sh"]

0 commit comments

Comments
 (0)