|
| 1 | +# DO NOT EDIT THIS FILE : Make yours changes in /utils/Dockerfile.blueprint) |
| 2 | +FROM debian:bullseye-slim |
| 3 | + |
| 4 | +LABEL authors="Julien Neuhart < [email protected]>, David Négrier < [email protected]>" |
| 5 | + |
| 6 | +# |-------------------------------------------------------------------------- |
| 7 | +# | Required libraries |
| 8 | +# |-------------------------------------------------------------------------- |
| 9 | +# | |
| 10 | +# | Installs required libraries. |
| 11 | +# | |
| 12 | + |
| 13 | +RUN apt-get update &&\ |
| 14 | + apt-get install -y --no-install-recommends curl git nano sudo ca-certificates procps libfontconfig tini --no-install-recommends |
| 15 | + |
| 16 | +# |-------------------------------------------------------------------------- |
| 17 | +# | Supercronic |
| 18 | +# |-------------------------------------------------------------------------- |
| 19 | +# | |
| 20 | +# | Supercronic is a drop-in replacement for cron (for containers). |
| 21 | +# | |
| 22 | + |
| 23 | +RUN SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-$( dpkg --print-architecture ) \ |
| 24 | + && SUPERCRONIC=supercronic-linux-$( dpkg --print-architecture ) \ |
| 25 | + && curl -fsSLO "$SUPERCRONIC_URL" \ |
| 26 | + && chmod +x "$SUPERCRONIC" \ |
| 27 | + && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ |
| 28 | + && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic |
| 29 | + |
| 30 | + # |-------------------------------------------------------------------------- |
| 31 | + # | User |
| 32 | + # |-------------------------------------------------------------------------- |
| 33 | + # | |
| 34 | + # | Define a default user with sudo rights. |
| 35 | + # | |
| 36 | + |
| 37 | + RUN useradd -ms /bin/bash docker && adduser docker sudo |
| 38 | + # Users in the sudoers group can sudo as root without password. |
| 39 | + RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +# |-------------------------------------------------------------------------- |
| 44 | +# | Apache |
| 45 | +# |-------------------------------------------------------------------------- |
| 46 | +# | |
| 47 | +# | Installs Apache. |
| 48 | +# | |
| 49 | + |
| 50 | +RUN apt-get update \ |
| 51 | + && apt-get install -y --no-install-recommends \ |
| 52 | + apache2 \ |
| 53 | + && rm -rf /var/lib/apt/lists/* |
| 54 | + |
| 55 | +ENV APACHE_CONFDIR /etc/apache2 |
| 56 | +ENV APACHE_ENVVARS $APACHE_CONFDIR/envvars |
| 57 | + |
| 58 | +RUN set -ex \ |
| 59 | + \ |
| 60 | +# generically convert lines like |
| 61 | +# export APACHE_RUN_USER=www-data |
| 62 | +# into |
| 63 | +# : ${APACHE_RUN_USER:=www-data} |
| 64 | +# export APACHE_RUN_USER |
| 65 | +# so that they can be overridden at runtime ("-e APACHE_RUN_USER=...") |
| 66 | + && sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS" \ |
| 67 | + \ |
| 68 | +# setup directories and permissions |
| 69 | + && . "$APACHE_ENVVARS" \ |
| 70 | + && for dir in \ |
| 71 | + "$APACHE_LOCK_DIR" \ |
| 72 | + "$APACHE_RUN_DIR" \ |
| 73 | + "$APACHE_LOG_DIR" \ |
| 74 | + /var/www/html \ |
| 75 | + ; do \ |
| 76 | + rm -rvf "$dir" \ |
| 77 | + && mkdir -p "$dir" \ |
| 78 | + && chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; \ |
| 79 | + done |
| 80 | + |
| 81 | +# logs should go to stdout / stderr |
| 82 | +RUN set -ex \ |
| 83 | + && . "$APACHE_ENVVARS" \ |
| 84 | + && ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log" \ |
| 85 | + && ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log" \ |
| 86 | + && ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log" |
| 87 | + |
| 88 | +ENV APACHE_DOCUMENT_ROOT / |
| 89 | + |
| 90 | +RUN { \ |
| 91 | + echo 'DirectoryIndex disabled'; \ |
| 92 | + echo 'DirectoryIndex index.html'; \ |
| 93 | + echo; \ |
| 94 | + echo '<Directory /var/www/>'; \ |
| 95 | + echo '\tOptions -Indexes'; \ |
| 96 | + echo '\tAllowOverride All'; \ |
| 97 | + echo '</Directory>'; \ |
| 98 | + } | tee "$APACHE_CONFDIR/conf-available/nodejs.conf" \ |
| 99 | + && a2enconf nodejs |
| 100 | + |
| 101 | +RUN sed -ri -e 's!/var/www/html!/var/www/html/${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf |
| 102 | +RUN sed -ri -e 's!/var/www/!/var/www/html/${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf |
| 103 | + |
| 104 | +# |-------------------------------------------------------------------------- |
| 105 | +# | Apache mod_rewrite |
| 106 | +# |-------------------------------------------------------------------------- |
| 107 | +# | |
| 108 | +# | Enables Apache mod_rewrite. |
| 109 | +# | |
| 110 | + |
| 111 | +RUN a2enmod rewrite |
| 112 | + |
| 113 | + |
| 114 | +# |-------------------------------------------------------------------------- |
| 115 | +# | NodeJS |
| 116 | +# |-------------------------------------------------------------------------- |
| 117 | +# | |
| 118 | +# | Installs NodeJS and npm. |
| 119 | +# | |
| 120 | + |
| 121 | +RUN apt-get update &&\ |
| 122 | + apt-get install -y --no-install-recommends gnupg &&\ |
| 123 | + mkdir -p /etc/apt/keyrings && \ |
| 124 | + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ |
| 125 | + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list &&\ |
| 126 | + apt-get update &&\ |
| 127 | + apt-get install -y --no-install-recommends nodejs |
| 128 | + |
| 129 | +# |-------------------------------------------------------------------------- |
| 130 | +# | yarn |
| 131 | +# |-------------------------------------------------------------------------- |
| 132 | +# | |
| 133 | +# | Installs yarn. It provides some nice improvements over npm. |
| 134 | +# | |
| 135 | + |
| 136 | +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\ |
| 137 | + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\ |
| 138 | + apt-get update &&\ |
| 139 | + apt-get install -y --no-install-recommends yarn |
| 140 | + |
| 141 | +# |-------------------------------------------------------------------------- |
| 142 | +# | PATH updating |
| 143 | +# |-------------------------------------------------------------------------- |
| 144 | +# | |
| 145 | +# | Let's add ./node_modules/.bin to the PATH (utility function to use NPM bin easily) |
| 146 | +# | |
| 147 | + |
| 148 | +ENV PATH="$PATH:./node_modules/.bin" |
| 149 | +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 |
| 150 | + |
| 151 | +USER docker |
| 152 | +# |-------------------------------------------------------------------------- |
| 153 | +# | SSH client |
| 154 | +# |-------------------------------------------------------------------------- |
| 155 | +# | |
| 156 | +# | Let's set-up the SSH client (for connections to private git repositories) |
| 157 | +# | We create an empty known_host file and we launch the ssh-agent |
| 158 | +# | |
| 159 | + |
| 160 | +RUN mkdir ~/.ssh && touch ~/.ssh/known_hosts && chmod 644 ~/.ssh/known_hosts && eval $(ssh-agent -s) |
| 161 | + |
| 162 | +# |-------------------------------------------------------------------------- |
| 163 | +# | .bashrc updating |
| 164 | +# |-------------------------------------------------------------------------- |
| 165 | +# | |
| 166 | +# | Let's update the .bashrc to add nice aliases |
| 167 | +# | |
| 168 | +RUN { \ |
| 169 | + echo "alias ls='ls --color=auto'"; \ |
| 170 | + echo "alias ll='ls --color=auto -alF'"; \ |
| 171 | + echo "alias la='ls --color=auto -A'"; \ |
| 172 | + echo "alias l='ls --color=auto -CF'"; \ |
| 173 | + } >> ~/.bashrc |
| 174 | + |
| 175 | +USER root |
| 176 | + |
| 177 | +# |-------------------------------------------------------------------------- |
| 178 | +# | Entrypoint |
| 179 | +# |-------------------------------------------------------------------------- |
| 180 | +# | |
| 181 | +# | Defines the entrypoint. |
| 182 | +# | |
| 183 | + |
| 184 | +ENV NODE_VERSION=22.x |
| 185 | + |
| 186 | + |
| 187 | +RUN mkdir -p /var/www/html && chown docker:docker /var/www/html |
| 188 | +WORKDIR /var/www/html |
| 189 | + |
| 190 | + |
| 191 | +COPY utils/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh |
| 192 | +COPY utils/docker-entrypoint-as-root.sh /usr/local/bin/docker-entrypoint-as-root.sh |
| 193 | +COPY utils/startup_commands.js /usr/local/bin/startup_commands.js |
| 194 | +COPY utils/generate_cron.js /usr/local/bin/generate_cron.js |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +COPY utils/enable_apache_mods.js /usr/local/bin/enable_apache_mods.js |
| 199 | +COPY utils/apache-expose-envvars.sh /usr/local/bin/apache-expose-envvars.sh |
| 200 | + |
| 201 | +# 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" |
| 202 | +RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf |
| 203 | +RUN a2enconf servername |
| 204 | + |
| 205 | +EXPOSE 80 |
| 206 | + |
| 207 | +# |-------------------------------------------------------------------------- |
| 208 | +# | Apache user |
| 209 | +# |-------------------------------------------------------------------------- |
| 210 | +# | |
| 211 | +# | Defines Apache user. By default, we switch this to "docker" user. |
| 212 | +# | This way, no problem to write from Apache in the current working directory. |
| 213 | +# | Important! This should be changed back to www-data in production. |
| 214 | +# | |
| 215 | + |
| 216 | +ENV APACHE_RUN_USER=docker \ |
| 217 | + APACHE_RUN_GROUP=docker |
| 218 | + |
| 219 | +COPY utils/apache2-foreground /usr/local/bin/ |
| 220 | +CMD ["apache2-foreground"] |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] |
| 226 | + |
| 227 | + |
| 228 | +USER docker |
0 commit comments