-
Notifications
You must be signed in to change notification settings - Fork 8
/
Dockerfile.14-apache-bullseye-build
230 lines (179 loc) · 7.62 KB
/
Dockerfile.14-apache-bullseye-build
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.blueprint)
FROM debian:bullseye-slim
LABEL authors="Julien Neuhart <[email protected]>, David Négrier <[email protected]>"
# |--------------------------------------------------------------------------
# | Required libraries
# |--------------------------------------------------------------------------
# |
# | Installs required libraries.
# |
RUN apt-get update &&\
apt-get install -y --no-install-recommends curl git nano sudo ca-certificates procps libfontconfig tini --no-install-recommends
# |--------------------------------------------------------------------------
# | Supercronic
# |--------------------------------------------------------------------------
# |
# | Supercronic is a drop-in replacement for cron (for containers).
# |
RUN SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-$( dpkg --print-architecture ) \
&& SUPERCRONIC=supercronic-linux-$( dpkg --print-architecture ) \
&& curl -fsSLO "$SUPERCRONIC_URL" \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
# |--------------------------------------------------------------------------
# | User
# |--------------------------------------------------------------------------
# |
# | Define a default user with sudo rights.
# |
RUN useradd -ms /bin/bash docker && adduser docker sudo
# Users in the sudoers group can sudo as root without password.
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# |--------------------------------------------------------------------------
# | Apache
# |--------------------------------------------------------------------------
# |
# | Installs Apache.
# |
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apache2 \
&& rm -rf /var/lib/apt/lists/*
ENV APACHE_CONFDIR /etc/apache2
ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars
RUN set -ex \
\
# generically convert lines like
# export APACHE_RUN_USER=www-data
# into
# : ${APACHE_RUN_USER:=www-data}
# export APACHE_RUN_USER
# so that they can be overridden at runtime ("-e APACHE_RUN_USER=...")
&& sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" \
\
# setup directories and permissions
&& . "$APACHE_ENVVARS" \
&& for dir in \
"$APACHE_LOCK_DIR" \
"$APACHE_RUN_DIR" \
"$APACHE_LOG_DIR" \
/var/www/html \
; do \
rm -rvf "$dir" \
&& mkdir -p "$dir" \
&& chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; \
done
# logs should go to stdout / stderr
RUN set -ex \
&& . "$APACHE_ENVVARS" \
&& ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \
&& ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"
ENV APACHE_DOCUMENT_ROOT /
RUN { \
echo 'DirectoryIndex disabled'; \
echo 'DirectoryIndex index.html'; \
echo; \
echo '<Directory /var/www/>'; \
echo '\tOptions -Indexes'; \
echo '\tAllowOverride All'; \
echo '</Directory>'; \
} | tee "$APACHE_CONFDIR/conf-available/nodejs.conf" \
&& a2enconf nodejs
RUN sed -ri -e 's!/var/www/html!/var/www/html/${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# |--------------------------------------------------------------------------
# | Apache mod_rewrite
# |--------------------------------------------------------------------------
# |
# | Enables Apache mod_rewrite.
# |
RUN a2enmod rewrite
# |--------------------------------------------------------------------------
# | NodeJS
# |--------------------------------------------------------------------------
# |
# | Installs NodeJS and npm.
# |
RUN apt-get update &&\
apt-get install -y --no-install-recommends gnupg &&\
curl -sL https://deb.nodesource.com/setup_14.x | bash - &&\
apt-get update &&\
apt-get install -y --no-install-recommends nodejs
# |--------------------------------------------------------------------------
# | yarn
# |--------------------------------------------------------------------------
# |
# | Installs yarn. It provides some nice improvements over npm.
# |
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
apt-get update &&\
apt-get install -y --no-install-recommends yarn
# |--------------------------------------------------------------------------
# | PATH updating
# |--------------------------------------------------------------------------
# |
# | Let's add ./node_modules/.bin to the PATH (utility function to use NPM bin easily)
# |
ENV PATH="$PATH:./node_modules/.bin"
RUN sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:./node_modules/.bin#g' /etc/sudoers
USER docker
# |--------------------------------------------------------------------------
# | SSH client
# |--------------------------------------------------------------------------
# |
# | Let's set-up the SSH client (for connections to private git repositories)
# | We create an empty known_host file and we launch the ssh-agent
# |
RUN mkdir ~/.ssh && touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts && eval $(ssh-agent -s)
# |--------------------------------------------------------------------------
# | .bashrc updating
# |--------------------------------------------------------------------------
# |
# | Let's update the .bashrc to add nice aliases
# |
RUN { \
echo "alias ls='ls --color=auto'"; \
echo "alias ll='ls --color=auto -alF'"; \
echo "alias la='ls --color=auto -A'"; \
echo "alias l='ls --color=auto -CF'"; \
} >> ~/.bashrc
USER root
# |--------------------------------------------------------------------------
# | Entrypoint
# |--------------------------------------------------------------------------
# |
# | Defines the entrypoint.
# |
ENV NODE_VERSION=14.x
RUN mkdir -p /var/www/html && chown docker:docker /var/www/html
WORKDIR /var/www/html
COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY utils/docker-entrypoint-as-root.sh /usr/local/bin/docker-entrypoint-as-root.sh
COPY utils/startup_commands.js /usr/local/bin/startup_commands.js
COPY utils/generate_cron.js /usr/local/bin/generate_cron.js
COPY utils/enable_apache_mods.js /usr/local/bin/enable_apache_mods.js
COPY utils/apache-expose-envvars.sh /usr/local/bin/apache-expose-envvars.sh
# Let's register a servername to remove the message "apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message"
RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf
RUN a2enconf servername
EXPOSE 80
# |--------------------------------------------------------------------------
# | Apache user
# |--------------------------------------------------------------------------
# |
# | Defines Apache user. By default, we switch this to "docker" user.
# | This way, no problem to write from Apache in the current working directory.
# | Important! This should be changed back to www-data in production.
# |
ENV APACHE_RUN_USER=docker \
APACHE_RUN_GROUP=docker
COPY utils/apache2-foreground /usr/local/bin/
CMD ["apache2-foreground"]
# Let's install the build tools (useful for node-gyp)
RUN apt-get update &&\
apt-get install -y --no-install-recommends build-essential
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
USER docker