-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
executable file
·101 lines (81 loc) · 3.13 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#######################################################################################################################
# Build static libfuse
#######################################################################################################################
ARG ARCHITECTURE
FROM multiarch/alpine:${ARCHITECTURE}-v3.12 as libfuse
ENV VERSION=fuse-2.9.9
RUN apk --no-cache add \
git \
build-base \
cmake \
pkgconf \
eudev-dev \
libtool \
m4 \
gettext-dev \
autoconf \
automake \
linux-headers
RUN git clone --depth 1 --branch "${VERSION}" https://github.com/libfuse/libfuse.git /libfuse
WORKDIR /libfuse
RUN CORES=$(grep -c '^processor' /proc/cpuinfo); \
export MAKEFLAGS="-j$((CORES+1)) -l${CORES}"; \
./makeconf.sh && \
./configure && \
make CFLAGS="-Wall -O3 -static"
#######################################################################################################################
# Build static ttnvt
#######################################################################################################################
ARG ARCHITECTURE
FROM multiarch/alpine:${ARCHITECTURE}-v3.12 as builder
ENV VERSION=master
# Add root without shell
RUN echo "root:x:0:0:root:/:" > /etc_passwd
# Install basic gcc tools
# autoconf is needed for autoreconf command
# autoreconf needs aclocal which is part of automake
RUN apk --no-cache add \
git \
build-base \
openssl-dev \
autoconf \
automake \
linux-headers \
upx
RUN git clone --depth 1 --branch "${VERSION}" https://gitlab.com/lars-thrane-as/ttynvt.git /ttynvt
WORKDIR /ttynvt
# Copy header files and static library
COPY --from=libfuse /libfuse/lib/.libs/libfuse.a /lib/fuse/
COPY --from=libfuse /libfuse/include/ /usr/include/fuse/
# Work around pkg-config
ENV FUSE_CFLAGS="-I/usr/include/fuse" \
FUSE_LIBS="-lfuse -L/lib/fuse"
# Makeflags source: https://math-linux.com/linux/tip-of-the-day/article/speedup-gnu-make-build-and-compilation-process
# -Wno-cpp is needed for:
# /usr/include/sys/poll.h:1:2: error: #warning redirecting incorrect #include <sys/poll.h> to <poll.h> [-Werror=cpp]
RUN CORES=$(grep -c '^processor' /proc/cpuinfo); \
export MAKEFLAGS="-j$((CORES+1)) -l${CORES}"; \
autoreconf -vif && \
./configure && \
make \
CFLAGS="-Wall -O3 -static -Wno-cpp -D_FILE_OFFSET_BITS=64"
# Minify binaries
# --brute does not work
RUN upx --best /ttynvt/src/ttynvt && \
upx -t /ttynvt/src/ttynvt
#######################################################################################################################
# Final scratch image
#######################################################################################################################
FROM scratch
# Add description
LABEL org.label-schema.description="Static compiled ttynvt in a scratch container"
# Copy the unprivileged user
COPY --from=builder /etc_passwd /etc/passwd
# Copy static binary
COPY --from=builder /ttynvt/src/ttynvt /ttynvt
# Needs to run as since /dev/fuse is root:root
USER root
# -f run in foreground, no forking
# -E log to stdout
ENTRYPOINT ["/ttynvt", "-f", "-E"]
CMD ["--help"]