-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
161 lines (143 loc) · 6.76 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
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
# global args
ARG __BUILD_DIR__="/build"
FROM debian:stretch as build
ARG __BUILD_DIR__
ARG OS_CODENAME="stretch"
ARG OS_VERSION="9.13"
ARG __USER__="root"
ARG __WORK_DIR__="/work"
ENV \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8" \
DEBCONF_NONINTERACTIVE_SEEN="true" \
DEBIAN_FRONTEND="noninteractive"
USER ${__USER__}
#COPY --chown="${__USER__}":${__USER__} "LICENSE" "files/" "${__WORK_DIR__}/"
COPY "LICENSE" "files/" "${__WORK_DIR__}/"
WORKDIR "${__WORK_DIR__}"
SHELL ["/bin/bash", "-c"]
RUN \
# build env
echo '=== setting build env ===' && \
time { \
set +h && \
export TIMEFORMAT='=== time taken: %lR (s:%lS u:%lU)' ; \
} && \
# build structure
echo '=== creating build structure ===' && \
time { \
for folder in '/licenses'; do install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}${folder}"; done ; \
} && \
# dependencies
echo '=== instaling dependencies ===' && \
time { \
apt-get -qq update && \
apt-get -qq -y -o=Dpkg::Use-Pty=0 --no-install-recommends install \
binutils \
ca-certificates \
coreutils \
curl \
dbus \
debian-archive-keyring \
debootstrap \
dpkg-dev \
wget \
> /dev/null 2>&1 ; \
} && \
# build base os
echo '=== building base os ===' && \
time { \
sed \
-i.orig \
-e '/in_target mount -t proc proc \/proc$/ s/$/ || true/' \
-e '/in_target mount -t sysfs sysfs \/sys/ s/$/ || true/' \
/usr/share/debootstrap/functions && \
debootstrap \
--variant='minbase' \
--arch=amd64 \
--exclude='sensible-utils' \
"${OS_CODENAME}" \
"${__BUILD_DIR__}" && \
install --directory --owner="${__USER__}" --group="${__USER__}" --mode=0755 "${__BUILD_DIR__}/licenses/debian" && \
(cd "${__BUILD_DIR__}/licenses/debian" && curl --silent --location --retry 3 --remote-name "http://ftp.debian.org/debian/doc/social-contract.txt") ; \
} && \
# update base os
echo '=== updating base os ===' && \
time { \
echo "deb http://deb.debian.org/debian ${OS_CODENAME} main non-free contrib" > "${__BUILD_DIR__}/etc/apt/sources.list" && \
echo "deb http://security.debian.org/ ${OS_CODENAME}/updates main contrib non-free" >> "${__BUILD_DIR__}/etc/apt/sources.list" && \
echo "deb http://deb.debian.org/debian ${OS_CODENAME}-updates main contrib non-free" >> "${__BUILD_DIR__}/etc/apt/sources.list" && \
chroot "${__BUILD_DIR__}" apt-get -qq update && \
chroot "${__BUILD_DIR__}" apt-get -qq -y -o Dpkg::Options::="--force-confdef" --no-install-recommends upgrade && \
chroot "${__BUILD_DIR__}" apt-get clean ; \
} && \
# copy tests
echo '=== copying test files ===' && \
time { \
install --owner="${__USER__}" --group="${__USER__}" --mode=0755 --target-directory="${__BUILD_DIR__}/usr/bin" "${__WORK_DIR__}/tests"/* ; \
} && \
# system settings / cleanup
echo '=== system settings / cleaning up ===' && \
time { \
rm -f "${__BUILD_DIR__}/etc/apt/apt.conf.d/01autoremove-kernels" && \
APT_GET_CLEAN='"rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true";' && \
printf 'DPkg::Post-Invoke { %s };\nAPT::Update::Post-Invoke { %s };\nDir::Cache::pkgcache "";\nDir::Cache::srcpkgcache "";\n' "${APT_GET_CLEAN}" "${APT_GET_CLEAN}" > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-clean" && \
printf 'DPkg::Use-Pty "false";\n' > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-no-dpkg-output" && \
printf 'Acquire::Languages "none";\n' > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-no-languages" && \
printf 'Acquire::GzipIndexes "true";\nAcquire::CompressionTypes::Order:: "gz";\n' > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-gzip-indexes" && \
printf 'APT::AutoRemove::SuggestsImportant "false";\n' > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-autoremove-suggests" && \
printf 'APT::Install-Recommends "false";\n' > "${__BUILD_DIR__}/etc/apt/apt.conf.d/90docker-no-recommends" && \
printf 'force-unsafe-io\n' > "${__BUILD_DIR__}/etc/dpkg/dpkg.cfg.d/90docker-apt-speedup" && \
printf 'path-exclude=/usr/share/doc/*\npath-exclude=/usr/share/info/*\npath-exclude=/usr/share/locale/*\npath-exclude=/usr/share/man/*\npath-include=/usr/share/doc/*/copyright\n' > "${__BUILD_DIR__}/etc/dpkg/dpkg.cfg.d/90docker-excludes" && \
echo '' > "${__BUILD_DIR__}/etc/resolv.conf" && \
echo 'host' > "${__BUILD_DIR__}/etc/hostname" && \
:> "${__BUILD_DIR__}/etc/machine-id" && \
find "${__BUILD_DIR__}/etc" -path '*/systemd/system/*.wants/*' \( -type l -o -type f \) -delete && \
if [ -x "${__BUILD_DIR__}/usr/bin/dpkg-divert" ]; then chroot "${__BUILD_DIR__}/" dpkg-divert --local --rename --add /sbin/initctl; fi && \
printf '#!/bin/sh\nexit 101\n' > "${__BUILD_DIR__}/usr/sbin/policy-rc.d" && \
printf '#!/bin/sh\nexit 0\n' > "${__BUILD_DIR__}/sbin/initctl" && \
chmod 0755 "${__BUILD_DIR__}/usr/sbin/policy-rc.d" "${__BUILD_DIR__}/sbin/initctl" && \
rm -rf "${__BUILD_DIR__}/usr/share/info"/* && \
rm -rf "${__BUILD_DIR__}/usr/share/man"/* && \
rm -rf "${__BUILD_DIR__}/var/cache/apt"/* && \
rm -rf "${__BUILD_DIR__}/var/lib/apt/lists"/* && \
rm -rf "${__BUILD_DIR__}/var/log"/* && \
rm -rf "${__BUILD_DIR__}/dev"/.??* && \
rm -rf "${__BUILD_DIR__}/home"/.??* && \
rm -rf "${__BUILD_DIR__}/root"/.??* && \
rm -rf "${__BUILD_DIR__}/tmp"/.??* && \
rm -rf "${__BUILD_DIR__}/boot" && \
rm -rf "${__BUILD_DIR__}/proc" && \
rm -rf "${__BUILD_DIR__}/sys" && \
find "${__BUILD_DIR__}/usr/lib/x86_64-linux-gnu/gconv" -mindepth 1 -maxdepth 1 -type f -not -name 'UTF*' -delete && \
find "${__BUILD_DIR__}/usr/share/locale" -mindepth 1 -maxdepth 1 -type d -not \( -name 'en' -o -name 'en_US' \) -exec rm -r {} + && \
find "${__BUILD_DIR__}/usr/share/doc" -mindepth 1 -not -type d -not \( -iname 'COPYING*' -o -iname 'GPL' -o -iname '*LICENSE*' -o -iname 'copyright' \) -delete && \
find "${__BUILD_DIR__}/usr/share/doc" -mindepth 1 -type d -empty -delete && \
find "${__BUILD_DIR__}/var/cache" -type f -delete ; \
} && \
# licenses
echo '=== project licenses ===' && \
time { \
install --owner=${__USER__} --group=${__USER__} --mode=0644 --target-directory="${__BUILD_DIR__}/licenses" "${__WORK_DIR__}/LICENSE" ; \
} && \
# check version
echo '=== os version ===' && \
time { \
cat "${__BUILD_DIR__}/etc/debian_version" ; \
} && \
# done
echo '=== all done! ==='
FROM scratch
ARG __BUILD_DIR__
LABEL \
maintainer="Frederico Martins <https://hub.docker.com/u/fscm/>" \
vendor="fscm" \
cmd="docker container run --interactive --rm --tty fscm/debian:stretch" \
params=""
ENV \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8" \
DEBCONF_NONINTERACTIVE_SEEN="true" \
DEBIAN_FRONTEND="noninteractive"
COPY --from=build "${__BUILD_DIR__}" "/"
CMD ["/bin/bash"]