1+ # this cannot upgrade to Alpine 3.5 due to https://github.com/libressl-portable/portable/issues/147
2+ # given that 2.2.x is a "legacy branch", and is in security-fixes-only mode upstream, this should be reasonably fine
3+ # "Minimal maintenance patches of 2.2.x are expected throughout this period, and users are strongly encouraged to promptly complete their transitions to the the 2.4.x flavour of httpd to benefit from a much larger assortment of minor security and bug fixes as well as new features."
4+ # https://httpd.apache.org/
5+ FROM wodby/alpine:3.4-1.0.0
6+
7+ # ensure www-data user exists
8+ RUN set -x \
9+ && addgroup -g 82 -S www-data \
10+ && adduser -u 82 -D -S -G www-data www-data
11+ # 82 is the standard uid/gid for "www-data" in Alpine
12+ # http://git.alpinelinux.org/cgit/aports/tree/main/apache2/apache2.pre-install?h=v3.3.2
13+ # http://git.alpinelinux.org/cgit/aports/tree/main/lighttpd/lighttpd.pre-install?h=v3.3.2
14+ # http://git.alpinelinux.org/cgit/aports/tree/main/nginx-initscripts/nginx-initscripts.pre-install?h=v3.3.2
15+
16+ ENV HTTPD_PREFIX /usr/local/apache2
17+ ENV PATH $HTTPD_PREFIX/bin:$PATH
18+ RUN mkdir -p "$HTTPD_PREFIX" \
19+ && chown www-data:www-data "$HTTPD_PREFIX"
20+ WORKDIR $HTTPD_PREFIX
21+
22+ ENV HTTPD_VERSION 2.2.34
23+ ENV HTTPD_SHA256 e53183d5dfac5740d768b4c9bea193b1099f4b06b57e5f28d7caaf9ea7498160
24+
25+ # https://httpd.apache.org/security/vulnerabilities_22.html
26+ ENV HTTPD_PATCHES="CVE-2017-9798-patch-2.2.patch 42c610f8a8f8d4d08664db6d9857120c2c252c9b388d56f238718854e6013e46"
27+
28+ ENV APACHE_DIST_URLS \
29+ # https://issues.apache.org/jira/browse/INFRA-8753?focusedCommentId=14735394#comment-14735394
30+ https://www.apache.org/dyn/closer.cgi?action=download&filename= \
31+ # if the version is outdated (or we're grabbing the .asc file), we might have to pull from the dist/archive :/
32+ https://www-us.apache.org/dist/ \
33+ https://www.apache.org/dist/ \
34+ https://archive.apache.org/dist/
35+
36+ # see https://httpd.apache.org/docs/2.2/install.html#requirements
37+ RUN set -eux; \
38+ \
39+ runDeps=' \
40+ apr-dev \
41+ apr-util-dev \
42+ apr-util-ldap \
43+ perl \
44+ '; \
45+ apk add --no-cache --virtual .build-deps \
46+ $runDeps \
47+ ca-certificates \
48+ coreutils \
49+ dpkg-dev dpkg \
50+ gcc \
51+ gnupg \
52+ libc-dev \
53+ make \
54+ openssl \
55+ openssl-dev \
56+ pcre-dev \
57+ tar \
58+ # install GNU wget (Busybox wget in Alpine 3.4 gives us "wget: error getting response: Connection reset by peer" for some reason)
59+ wget \
60+ ; \
61+ \
62+ ddist() { \
63+ local f="$1"; shift; \
64+ local distFile="$1"; shift; \
65+ local success=; \
66+ local distUrl=; \
67+ for distUrl in $APACHE_DIST_URLS; do \
68+ if wget -O "$f" "$distUrl$distFile"; then \
69+ success=1; \
70+ break; \
71+ fi; \
72+ done; \
73+ [ -n "$success" ]; \
74+ }; \
75+ \
76+ ddist 'httpd.tar.bz2' "httpd/httpd-$HTTPD_VERSION.tar.bz2"; \
77+ echo "$HTTPD_SHA256 *httpd.tar.bz2" | sha256sum -c -; \
78+ \
79+ # see https://httpd.apache.org/download.cgi#verify
80+ ddist 'httpd.tar.bz2.asc' "httpd/httpd-$HTTPD_VERSION.tar.bz2.asc"; \
81+ export GNUPGHOME="$(mktemp -d)"; \
82+ gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B1B96F45DFBDCCF974019235193F180AB55D9977; \
83+ gpg --batch --verify httpd.tar.bz2.asc httpd.tar.bz2; \
84+ rm -rf "$GNUPGHOME" httpd.tar.bz2.asc; \
85+ \
86+ mkdir -p src; \
87+ tar -xf httpd.tar.bz2 -C src --strip-components=1; \
88+ rm httpd.tar.bz2; \
89+ cd src; \
90+ \
91+ patches() { \
92+ while [ "$#" -gt 0 ]; do \
93+ local patchFile="$1"; shift; \
94+ local patchSha256="$1"; shift; \
95+ ddist "$patchFile" "httpd/patches/apply_to_$HTTPD_VERSION/$patchFile"; \
96+ echo "$patchSha256 *$patchFile" | sha256sum -c -; \
97+ patch -p0 < "$patchFile"; \
98+ rm -f "$patchFile"; \
99+ done; \
100+ }; \
101+ patches $HTTPD_PATCHES; \
102+ \
103+ gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \
104+ ./configure \
105+ --build="$gnuArch" \
106+ --prefix="$HTTPD_PREFIX" \
107+ --with-mpm=event \
108+ # https://httpd.apache.org/docs/2.2/programs/configure.html
109+ # Caveat: --enable-mods-shared=all does not actually build all modules. To build all modules then, one might use:
110+ --enable-mods-shared='all ssl ldap cache proxy authn_alias mem_cache file_cache authnz_ldap charset_lite dav_lock disk_cache' \
111+ ; \
112+ make -j "$(nproc)"; \
113+ make install; \
114+ \
115+ cd ..; \
116+ rm -r src man manual; \
117+ \
118+ sed -ri \
119+ -e 's!^(\s*CustomLog)\s+\S+!\1 /proc/self/fd/1!g' \
120+ -e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g' \
121+ "$HTTPD_PREFIX/conf/httpd.conf"; \
122+ \
123+ runDeps="$runDeps $( \
124+ scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
125+ | tr ',' '\n' \
126+ | sort -u \
127+ | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
128+ )"; \
129+ apk add --virtual .httpd-rundeps $runDeps; \
130+ apk del .build-deps
131+
132+ COPY httpd-foreground /usr/local/bin/
133+
134+ EXPOSE 80
135+ CMD ["httpd-foreground"]
0 commit comments