Skip to content

Commit 24313a0

Browse files
committed
Update some Dockerfiles and Kubernetes scripts/docs
1 parent d7e5092 commit 24313a0

34 files changed

+3629
-172
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# build with docker build -t REPO/crossbuild-riscv64 -f Dockerfile.crossbuild-riscv64 .
2+
FROM python:3-buster
3+
4+
ENV DEBIAN_FRONTEND noninteractive
5+
ENV TOOLCHAIN_URL https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64/tarballs/riscv64--glibc--bleeding-edge-2020.08-1.tar.bz2
6+
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends \
9+
build-essential \
10+
autoconf \
11+
curl \
12+
wget \
13+
git \
14+
python3 \
15+
python3-pip \
16+
bzip2 \
17+
ca-certificates && \
18+
rm -rf /var/lib/apt/lists/*
19+
20+
WORKDIR /build
21+
22+
RUN wget $TOOLCHAIN_URL && \
23+
mkdir -p /opt/riscv64-toolchain && \
24+
tar vxf $(basename $TOOLCHAIN_URL) -C /opt/riscv64-toolchain --strip-components=1 && \
25+
rm -rf $(basename $TOOLCHAIN_URL)
26+
27+
ENV PATH $PATH:/opt/riscv64-toolchain/bin
28+
ENV CROSS_COMPILE riscv64-linux-
29+
30+
RUN riscv64-linux-gcc --version
31+
32+
CMD ["/bin/bash"]

Dockerfiles/Dockerfile.debian

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
55
debootstrap
66

77
RUN echo "deb http://ftp.ports.debian.org/debian-ports sid main \
8-
deb http://deb.debian.org/debian-ports unstable main \
9-
deb http://deb.debian.org/debian-ports unreleased main \
10-
" >> /etc/apt/sources.list && \
8+
deb http://ftp.ports.debian.org/debian-ports unstable main \
9+
deb http://ftp.ports.debian.org/debian-ports unreleased main \
10+
deb http://ftp.ports.debian.org/debian-ports experimental main \
11+
" >> /etc/apt/sources.list && \
1112
apt-get install -y debian-ports-archive-keyring && \
1213
dpkg --add-architecture riscv64 && \
1314
apt-get update

Dockerfiles/nginx/10-listen-on-ipv6-by-default.sh

Lines changed: 1433 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
ME=$(basename $0)
6+
7+
auto_envsubst() {
8+
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
9+
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
10+
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
11+
12+
local template defined_envs relative_path output_path subdir
13+
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
14+
[ -d "$template_dir" ] || return 0
15+
if [ ! -w "$output_dir" ]; then
16+
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
17+
return 0
18+
fi
19+
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
20+
relative_path="${template#$template_dir/}"
21+
output_path="$output_dir/${relative_path%$suffix}"
22+
subdir=$(dirname "$relative_path")
23+
# create a subdirectory where the template file exists
24+
mkdir -p "$output_dir/$subdir"
25+
echo >&3 "$ME: Running envsubst on $template to $output_path"
26+
envsubst "$defined_envs" < "$template" > "$output_path"
27+
done
28+
}
29+
30+
auto_envsubst
31+
32+
exit 0
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/sh
2+
# vim:sw=2:ts=2:sts=2:et
3+
4+
set -eu
5+
6+
LC_ALL=C
7+
ME=$( basename "$0" )
8+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9+
10+
[ "${NGINX_ENTRYPOINT_WORKER_PROCESSES_AUTOTUNE:-}" ] || exit 0
11+
12+
touch /etc/nginx/nginx.conf 2>/dev/null || { echo >&2 "$ME: error: can not modify /etc/nginx/nginx.conf (read-only file system?)"; exit 0; }
13+
14+
ceildiv() {
15+
num=$1
16+
div=$2
17+
echo $(( (num + div - 1) / div ))
18+
}
19+
20+
get_cpuset() {
21+
cpusetroot=$1
22+
cpusetfile=$2
23+
ncpu=0
24+
[ -f "$cpusetroot/$cpusetfile" ] || return
25+
for token in $( tr ',' ' ' < "$cpusetroot/$cpusetfile" ); do
26+
case "$token" in
27+
*-*)
28+
count=$( seq $(echo "$token" | tr '-' ' ') | wc -l )
29+
ncpu=$(( ncpu+count ))
30+
;;
31+
*)
32+
ncpu=$(( ncpu+1 ))
33+
;;
34+
esac
35+
done
36+
echo "$ncpu"
37+
}
38+
39+
get_quota() {
40+
cpuroot=$1
41+
ncpu=0
42+
[ -f "$cpuroot/cpu.cfs_quota_us" ] || return
43+
[ -f "$cpuroot/cpu.cfs_period_us" ] || return
44+
cfs_quota=$( cat "$cpuroot/cpu.cfs_quota_us" )
45+
cfs_period=$( cat "$cpuroot/cpu.cfs_period_us" )
46+
[ "$cfs_quota" = "-1" ] && return
47+
[ "$cfs_period" = "0" ] && return
48+
ncpu=$( ceildiv "$cfs_quota" "$cfs_period" )
49+
[ "$ncpu" -gt 0 ] || return
50+
echo "$ncpu"
51+
}
52+
53+
get_quota_v2() {
54+
cpuroot=$1
55+
ncpu=0
56+
[ -f "$cpuroot/cpu.max" ] || return
57+
cfs_quota=$( cut -d' ' -f 1 < "$cpuroot/cpu.max" )
58+
cfs_period=$( cut -d' ' -f 2 < "$cpuroot/cpu.max" )
59+
[ "$cfs_quota" = "max" ] && return
60+
[ "$cfs_period" = "0" ] && return
61+
ncpu=$( ceildiv "$cfs_quota" "$cfs_period" )
62+
[ "$ncpu" -gt 0 ] || return
63+
echo "$ncpu"
64+
}
65+
66+
get_cgroup_v1_path() {
67+
needle=$1
68+
found=
69+
foundroot=
70+
mountpoint=
71+
72+
[ -r "/proc/self/mountinfo" ] || return
73+
[ -r "/proc/self/cgroup" ] || return
74+
75+
while IFS= read -r line; do
76+
case "$needle" in
77+
"cpuset")
78+
case "$line" in
79+
*cpuset*)
80+
found=$( echo "$line" | cut -d ' ' -f 4,5 )
81+
;;
82+
esac
83+
;;
84+
"cpu")
85+
case "$line" in
86+
*cpuset*)
87+
;;
88+
*cpu,cpuacct*|*cpuacct,cpu|*cpuacct*|*cpu*)
89+
found=$( echo "$line" | cut -d ' ' -f 4,5 )
90+
;;
91+
esac
92+
esac
93+
done << __EOF__
94+
$( grep -F -- '- cgroup ' /proc/self/mountinfo )
95+
__EOF__
96+
97+
while IFS= read -r line; do
98+
controller=$( echo "$line" | cut -d: -f 2 )
99+
case "$needle" in
100+
"cpuset")
101+
case "$controller" in
102+
cpuset)
103+
mountpoint=$( echo "$line" | cut -d: -f 3 )
104+
;;
105+
esac
106+
;;
107+
"cpu")
108+
case "$controller" in
109+
cpu,cpuacct|cpuacct,cpu|cpuacct|cpu)
110+
mountpoint=$( echo "$line" | cut -d: -f 3 )
111+
;;
112+
esac
113+
;;
114+
esac
115+
done << __EOF__
116+
$( grep -F -- 'cpu' /proc/self/cgroup )
117+
__EOF__
118+
119+
case "${found%% *}" in
120+
"/")
121+
foundroot="${found##* }$mountpoint"
122+
;;
123+
"$mountpoint")
124+
foundroot="${found##* }"
125+
;;
126+
esac
127+
echo "$foundroot"
128+
}
129+
130+
get_cgroup_v2_path() {
131+
found=
132+
foundroot=
133+
mountpoint=
134+
135+
[ -r "/proc/self/mountinfo" ] || return
136+
[ -r "/proc/self/cgroup" ] || return
137+
138+
while IFS= read -r line; do
139+
found=$( echo "$line" | cut -d ' ' -f 4,5 )
140+
done << __EOF__
141+
$( grep -F -- '- cgroup2 ' /proc/self/mountinfo )
142+
__EOF__
143+
144+
while IFS= read -r line; do
145+
mountpoint=$( echo "$line" | cut -d: -f 3 )
146+
done << __EOF__
147+
$( grep -F -- '0::' /proc/self/cgroup )
148+
__EOF__
149+
150+
case "${found%% *}" in
151+
"")
152+
return
153+
;;
154+
"/")
155+
foundroot="${found##* }$mountpoint"
156+
;;
157+
"$mountpoint")
158+
foundroot="${found##* }"
159+
;;
160+
esac
161+
echo "$foundroot"
162+
}
163+
164+
ncpu_online=$( getconf _NPROCESSORS_ONLN )
165+
ncpu_cpuset=
166+
ncpu_quota=
167+
ncpu_cpuset_v2=
168+
ncpu_quota_v2=
169+
170+
cpuset=$( get_cgroup_v1_path "cpuset" )
171+
[ "$cpuset" ] && ncpu_cpuset=$( get_cpuset "$cpuset" "cpuset.effective_cpus" )
172+
[ "$ncpu_cpuset" ] || ncpu_cpuset=$ncpu_online
173+
174+
cpu=$( get_cgroup_v1_path "cpu" )
175+
[ "$cpu" ] && ncpu_quota=$( get_quota "$cpu" )
176+
[ "$ncpu_quota" ] || ncpu_quota=$ncpu_online
177+
178+
cgroup_v2=$( get_cgroup_v2_path )
179+
[ "$cgroup_v2" ] && ncpu_cpuset_v2=$( get_cpuset "$cgroup_v2" "cpuset.cpus.effective" )
180+
[ "$ncpu_cpuset_v2" ] || ncpu_cpuset_v2=$ncpu_online
181+
182+
[ "$cgroup_v2" ] && ncpu_quota_v2=$( get_quota_v2 "$cgroup_v2" )
183+
[ "$ncpu_quota_v2" ] || ncpu_quota_v2=$ncpu_online
184+
185+
ncpu=$( printf "%s\n%s\n%s\n%s\n%s\n" \
186+
"$ncpu_online" \
187+
"$ncpu_cpuset" \
188+
"$ncpu_quota" \
189+
"$ncpu_cpuset_v2" \
190+
"$ncpu_quota_v2" \
191+
| sort -n \
192+
| head -n 1 )
193+
194+
sed -i.bak -r 's/^(worker_processes)(.*)$/# Commented out by '"$ME"' on '"$(date)"'\n#\1\2\n\1 '"$ncpu"';/' /etc/nginx/nginx.conf

Dockerfiles/nginx/Dockerfile.nginx

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
FROM carlosedp/debian:sid
2+
3+
LABEL maintainer="NGINX Docker Maintainers <[email protected]>"
4+
5+
ENV NGINX_VERSION 1.19.8
6+
ENV NJS_VERSION 0.5.2
7+
ENV PKG_RELEASE 1~buster
8+
9+
RUN set -x \
10+
# create nginx user/group first, to be consistent throughout docker variants
11+
&& addgroup --system --gid 101 nginx \
12+
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \
13+
&& apt-get update \
14+
&& apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates \
15+
&& \
16+
NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
17+
found=''; \
18+
for server in \
19+
ha.pool.sks-keyservers.net \
20+
hkp://keyserver.ubuntu.com:80 \
21+
hkp://p80.pool.sks-keyservers.net:80 \
22+
pgp.mit.edu \
23+
; do \
24+
echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
25+
apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
26+
done; \
27+
test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
28+
apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
29+
&& dpkgArch="$(dpkg --print-architecture)" \
30+
&& nginxPackages=" \
31+
nginx=${NGINX_VERSION}-${PKG_RELEASE} \
32+
nginx-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} \
33+
nginx-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} \
34+
nginx-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} \
35+
nginx-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${PKG_RELEASE} \
36+
" \
37+
&& case "$dpkgArch" in \
38+
amd64|i386|arm64) \
39+
# arches officialy built by upstream
40+
echo "deb https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list \
41+
&& apt-get update \
42+
;; \
43+
*) \
44+
# we're on an architecture upstream doesn't officially build for
45+
# let's build binaries from the published source packages
46+
echo "deb-src https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list \
47+
\
48+
# new directory for storing sources and .deb files
49+
&& tempDir="$(mktemp -d)" \
50+
&& chmod 777 "$tempDir" \
51+
# (777 to ensure APT's "_apt" user can access it too)
52+
\
53+
# save list of currently-installed packages so build dependencies can be cleanly removed later
54+
&& savedAptMark="$(apt-mark showmanual)" \
55+
\
56+
# build .deb files from upstream's source packages (which are verified by apt-get)
57+
&& apt-get update \
58+
&& apt-get build-dep -y $nginxPackages \
59+
&& ( \
60+
cd "$tempDir" \
61+
&& DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" \
62+
apt-get source --compile $nginxPackages \
63+
) \
64+
# we don't remove APT lists here because they get re-downloaded and removed later
65+
\
66+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
67+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
68+
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
69+
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
70+
\
71+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
72+
&& ls -lAFh "$tempDir" \
73+
&& ( cd "$tempDir" && dpkg-scanpackages . > Packages ) \
74+
&& grep '^Package: ' "$tempDir/Packages" \
75+
&& echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list \
76+
# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
77+
# Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
78+
# ...
79+
# E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
80+
&& apt-get -o Acquire::GzipIndexes=false update \
81+
;; \
82+
esac \
83+
\
84+
&& apt-get install --no-install-recommends --no-install-suggests -y \
85+
$nginxPackages \
86+
gettext-base \
87+
curl \
88+
&& apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list \
89+
\
90+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
91+
&& if [ -n "$tempDir" ]; then \
92+
apt-get purge -y --auto-remove \
93+
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
94+
fi \
95+
# forward request and error logs to docker log collector
96+
&& ln -sf /dev/stdout /var/log/nginx/access.log \
97+
&& ln -sf /dev/stderr /var/log/nginx/error.log \
98+
# create a docker-entrypoint.d directory
99+
&& mkdir /docker-entrypoint.d
100+
101+
COPY docker-entrypoint.sh /
102+
COPY 10-listen-on-ipv6-by-default.sh /docker-entrypoint.d
103+
COPY 20-envsubst-on-templates.sh /docker-entrypoint.d
104+
COPY 30-tune-worker-processes.sh /docker-entrypoint.d
105+
ENTRYPOINT ["/docker-entrypoint.sh"]
106+
107+
EXPOSE 80
108+
109+
STOPSIGNAL SIGQUIT
110+
111+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)