-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnc.dockerfile
More file actions
92 lines (77 loc) · 2.91 KB
/
Copy pathnc.dockerfile
File metadata and controls
92 lines (77 loc) · 2.91 KB
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
# ╔═════════════════════════════════════════════════════╗
# ║ SETUP ║
# ╚═════════════════════════════════════════════════════╝
# GLOBAL
ARG APP_UID=1000 \
APP_GID=1000 \
BUILD_SRC=https://salsa.debian.org/debian/netcat-openbsd.git \
BUILD_ROOT=/netcat-openbsd
ARG BUILD_BIN=${BUILD_ROOT}/nc
# :: FOREIGN IMAGES
FROM 11notes/util:bin AS util-bin
# ╔═════════════════════════════════════════════════════╗
# ║ BUILD ║
# ╚═════════════════════════════════════════════════════╝
# :: NC
FROM alpine AS build
COPY --from=util-bin / /
ARG APP_VERSION \
APP_VERSION_BUILD \
BUILD_SRC \
BUILD_ROOT \
BUILD_BIN
RUN set -ex; \
apk --update --no-cache add \
git \
g++ \
make \
patch \
libbsd-dev \
libbsd-static;
RUN set -ex; \
if [ -z "${APP_VERSION_BUILD}" ]; then \
git clone ${BUILD_SRC} -b debian/${APP_VERSION}; \
else \
git clone ${BUILD_SRC} -b debian/${APP_VERSION}-${APP_VERSION_BUILD}; \
fi;
COPY ./src/nc/ /
RUN set -ex; \
cd ${BUILD_ROOT}; \
git apply b64.patch; \
sed -i -e "/SRCS=/s;\(.*\);& base64.c;" Makefile; \
while read -r PATCH; do \
patch -Np1 < debian/patches/${PATCH} || echo "warning"; \
done < debian/patches/series;
RUN set -ex; \
cd ${BUILD_ROOT}; \
make -s -j $(nproc) LDFLAGS="--static" 2>&1 > /dev/null;
RUN set -ex; \
eleven distroless ${BUILD_BIN};
# ╔═════════════════════════════════════════════════════╗
# ║ IMAGE ║
# ╚═════════════════════════════════════════════════════╝
# :: HEADER
FROM scratch
# :: default arguments
ARG TARGETPLATFORM \
TARGETOS \
TARGETARCH \
TARGETVARIANT \
APP_IMAGE \
APP_NAME \
APP_VERSION \
APP_ROOT \
APP_UID \
APP_GID \
APP_NO_CACHE
# :: default environment
ENV APP_IMAGE=${APP_IMAGE} \
APP_NAME=${APP_NAME} \
APP_VERSION=${APP_VERSION} \
APP_ROOT=${APP_ROOT}
# :: multi-stage
COPY --from=build ${APP_ROOT}/ /
# :: EXECUTE
USER ${APP_UID}:${APP_GID}
ENTRYPOINT ["/usr/local/bin/nc"]
CMD ["-version"]