generated from bandogora/nunit-Ceasy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile.minsize
189 lines (177 loc) · 6.11 KB
/
Dockerfile.minsize
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
FROM debian:stable-slim
LABEL org.opencontainers.image.title="Unit (C)"
LABEL org.opencontainers.image.description="Unofficial build of Unit for Docker."
LABEL org.opencontainers.image.url="https://github.com/bandogora/nunit-Ceasy"
LABEL org.opencontainers.image.source="https://github.com/bandogora/nunit-Ceasy"
LABEL org.opencontainers.image.documentation="https://unit.nginx.org/installation/#docker-images"
ARG prefix="/usr"
ARG exec_prefix="$prefix"
ARG bin_dir="$exec_prefix/bin"
ARG include_dir="$prefix/include"
ARG lib_dir="$exec_prefix/lib"
ARG data_root_dir="$prefix/share"
ARG man_dir="$data_root_dir/man"
ARG local_state_dir="$prefix/var"
ARG lib_state_dir="$local_state_dir/run/unit"
ARG log_dir="$local_state_dir/log/unit"
ARG log_file="$log_dir/unit.log"
ARG tmp_dir="/tmp"
ARG unit_group="unit"
ARG unit_user="unit"
ARG unit_clone_dir="$prefix/src/unit"
ARG srv_dir="/srv"
ARG app_assets_dir="$srv_dir/assets"
ARG app_bin_dir="$bin_dir"
ARG app_clone_dir="$prefix/src/app"
ARG app_src_dir="$app_clone_dir/src"
ARG app_include_dir="$app_clone_dir/include"
ARG app_lib_dir="$app_clone_dir/lib"
ARG app_group="iots"
ARG app_user="iots"
ARG app_firmware_dir="$srv_dir/firmware"
ARG ncpu="getconf _NPROCESSORS_ONLN"
ENV UNIT_RUN_STATE_DIR="$local_state_dir/run/unit"
ENV UNIT_PID_PATH="$UNIT_RUN_STATE_DIR/unit.pid"
ENV UNIT_SOCKET="$UNIT_RUN_STATE_DIR/control.unit.sock"
ENV UNIT_SBIN_DIR="$exec_prefix/sbin"
ENV DEB_CFLAGS_MAINT_APPEND="-Wp,-D_FORTIFY_SOURCE=2 -march=native -fPIC"
ENV DEB_LDFLAGS_MAINT_APPEND="-Wl,--as-needed -pie"
ENV DEB_BUILD_MAINT_OPTIONS="hardening=+all,-pie"
ARG cc_opt="dpkg-buildflags --get CFLAGS"
ARG ld_opt="dpkg-buildflags --get LDFLAGS"
ARG unit_config_args=\
"--cc=gcc \
--openssl \
--user=$unit_user \
--group=$unit_group \
--prefix=$prefix \
--exec-prefix=$exec_prefix \
--bindir=$bin_dir \
--sbindir=$UNIT_SBIN_DIR \
--includedir=$include_dir \
--libdir=$lib_dir \
--modulesdir=$modules_dir \
--datarootdir=$data_root_dir \
--mandir=$man_dir \
--localstatedir=$local_state_dir \
--logdir=$log_dir \
--log=$log_file \
--runstatedir=$UNIT_RUN_STATE_DIR \
--pid=$UNIT_PID_PATH \
--control=unix:$UNIT_SOCKET \
--tmpdir=$tmp_dir"
RUN set -x \
&& mkdir -p \
$app_src_dir \
$app_include_dir \
$app_lib_dir \
$app_clone_dir/config \
$app_clone_dir/modules/jsmn \
$app_clone_dir/modules/nibble-and-a-half \
/docker-entrypoint.d \
$app_assets_dir/images \
$app_assets_dir/javascripts \
$app_assets_dir/stylesheets
# Copy app source files
COPY --link ./src/* "$app_src_dir"
COPY --link ./include/* "$app_include_dir"
COPY --link ./Makefile "$app_clone_dir"
COPY --link ./modules/jsmn/* "$app_clone_dir"/modules/jsmn
COPY --link ./modules/nibble-and-a-half/* "$app_clone_dir"/modules/nibble-and-a-half
COPY --link ./assets/*.html "$app_assets_dir"
COPY --link ./assets/images/* "$app_assets_dir/images"
COPY --link ./assets/javascripts/* "$app_assets_dir/javascripts"
COPY --link ./assets/stylesheets/* "$app_assets_dir/stylesheets"
# Copy initial config
COPY --link config/config.json /docker-entrypoint.d/
# Copy the default entrypoint
COPY --link ./docker-entrypoint.sh /usr/local/bin/
RUN --mount=type=secret,id=vzw_secrets.h set -x \
# Install dependencies
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y ca-certificates git \
build-essential libssl-dev libpcre2-dev curl pkg-config libcurl4-openssl-dev \
# Prepare dirs, group, and user
&& mkdir -p \
$bin_dir \
$UNIT_SBIN_DIR \
$include_dir \
$lib_dir \
$data_root_dir \
$man_dir \
$local_state_dir/lib/unit/certs \
$local_state_dir/lib/unit/scripts \
$log_dir \
$UNIT_RUN_STATE_DIR \
$tmp_dir \
$app_firmware_dir \
$app_src_dir \
$app_include_dir \
$app_lib_dir \
$app_clone_dir/config \
$app_clone_dir/modules/jsmn \
$app_clone_dir/modules/nibble-and-a-half \
&& mkdir -p -m=700 $lib_state_dir \
&& groupadd --gid 999 $unit_group \
&& groupadd --gid 1000 $app_group \
&& useradd \
--uid 999 \
--gid $unit_group \
--no-create-home \
--home /nonexistent \
--comment "unit user" \
--shell /bin/false \
$unit_user \
&& useradd \
--uid 1000 \
--gid $app_group \
--no-create-home \
--home /nonexistent \
--comment "iot server app user" \
--shell /bin/false \
$app_user \
&& chown root:$app_group $app_firmware_dir \
&& chmod -R 775 $app_firmware_dir \
# Clone NGINX Unit
&& git clone --depth 1 -b 1.32.1-1 https://github.com/nginx/unit $unit_clone_dir \
# Configure and make unitd
&& cd $unit_clone_dir \
&& ./configure $unit_config_args --cc-opt="$(eval $cc_opt)" --ld-opt="$(eval $ld_opt)" \
&& make -j $(eval $ncpu) unitd \
# Install unitd
&& install -pm755 ./build/sbin/unitd "$UNIT_SBIN_DIR/unitd" \
# Link stdout to log file
&& ln -sf /dev/stdout "$log_file" \
# Make libunit.a
&& make -j $(eval $ncpu) libunit-install \
# Add nxt_clang.h to include location
&& cp ./src/nxt_clang.h $include_dir/. \
# Save/apt-mark unitd dependencies
&& cd \
&& savedAptMark="$(apt-mark showmanual)" \
&& for f in $UNIT_SBIN_DIR/unitd; do \
ldd $f | awk '/=>/{print $(NF-1)}' | while read n; do dpkg-query -S $n; done | sed 's/^\([^:]\+\):.*$/\1/' | sort | uniq >> /requirements.apt; \
done \
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
&& /bin/true \
&& apt-get update \
&& apt-get --no-install-recommends --no-install-suggests -y install $(cat /requirements.apt) \
# Compile and link C app against libunit.a
&& cd $app_clone_dir \
&& cp /run/secrets/vzw_secrets.h config/vzw_secrets.h \
&& make -j $(eval $ncpu) \
&& make install \
# Cleanup
&& rm -f config/vzw_secrets.h \
&& apt-get purge -y --auto-remove build-essential \
&& rm -rf $unit_clone_dir \
&& rm -rf $app_clone_dir \
&& rm -rf /var/lib/apt/lists/* \
&& rm -f /requirements.apt
# Make sure the entrypoint is executable
RUN ["chmod", "+x", "/usr/local/bin/docker-entrypoint.sh"]
STOPSIGNAL SIGTERM
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
EXPOSE 80
CMD ["unitd", "--no-daemon", "--control", "unix:$UNIT_SOCKET"]