-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
60 lines (45 loc) · 1.94 KB
/
Dockerfile
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
#######################################################################################################################
# Build static Ser2Sock
#######################################################################################################################
ARG ARCHITECTURE
FROM multiarch/alpine:${ARCHITECTURE}-v3.12 as builder
ENV VERSION=1.5.5
# Add unprivileged user
RUN echo "ser2sock:x:1000:1000:ser2sock:/:" > /etc_passwd
RUN apk --no-cache add \
git \
build-base \
openssl-dev
RUN git clone --depth 1 --branch "v${VERSION}" https://github.com/nutechsoftware/ser2sock.git /ser2sock
WORKDIR /ser2sock
# Needed until version >1.5.6 is released
# https://github.com/nutechsoftware/ser2sock/pull/13
RUN sed -i 's/LIBS="-lcrypto $LIBS"/LIBS="$LIBS -lcrypto"/g' configure
# Makeflags source: https://math-linux.com/linux/tip-of-the-day/article/speedup-gnu-make-build-and-compilation-process
RUN CORES=$(grep -c '^processor' /proc/cpuinfo); \
export MAKEFLAGS="-j$((CORES+1)) -l${CORES}"; \
./configure && \
make \
CFLAGS="-Wall -O3 -static" \
LDFLAGS="-static"
# Minify binaries
# --brute does not work
RUN apk add --no-cache upx && \
upx --best /ser2sock/ser2sock && \
upx -t /ser2sock/ser2sock
#######################################################################################################################
# Final scratch image
#######################################################################################################################
FROM scratch
# Add description
LABEL org.label-schema.description="Static compiled Ser2Sock in a scratch container"
# Copy the unprivileged user
COPY --from=builder /etc_passwd /etc/passwd
# Copy static binary
COPY --from=builder /ser2sock/ser2sock /ser2sock
# Add default configuration
COPY examples/docker-compose/config/ser2sock.conf /config/ser2sock.conf
USER ser2sock
ENTRYPOINT ["/ser2sock"]
CMD ["-f", "/config/ser2sock.conf"]
EXPOSE 10000