Skip to content

Commit d65cc34

Browse files
author
Philipp Kübler
committed
add startup-command script
1 parent 8588329 commit d65cc34

File tree

2 files changed

+87
-38
lines changed

2 files changed

+87
-38
lines changed

Dockerfile

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,49 @@ RUN apk info \
1414
&& apk update \
1515
&& apk upgrade \
1616
&& apk add --no-cache --virtual .build-deps \
17-
$PHPIZE_DEPS \
17+
$PHPIZE_DEPS \
1818
&& apk add --no-cache \
19-
sudo \
20-
runit \
21-
nginx \
22-
zlib-dev \
23-
icu-dev \
24-
imagemagick \
25-
imagemagick-dev \
26-
libzip-dev \
27-
libjpeg-turbo-dev \
28-
libpng-dev \
29-
libxml2-dev \
30-
freetype-dev \
31-
bash \
32-
git \
33-
nodejs \
34-
composer \
35-
php7-tokenizer \
36-
php7-simplexml \
37-
php7-dom \
38-
mysql-client \
39-
yarn@edge \
40-
xvfb \
41-
chromium@3.9 \
42-
chromium-chromedriver@3.9 \
19+
sudo \
20+
runit \
21+
nginx \
22+
zlib-dev \
23+
icu-dev \
24+
imagemagick \
25+
imagemagick-dev \
26+
libzip-dev \
27+
libjpeg-turbo-dev \
28+
libpng-dev \
29+
libxml2-dev \
30+
freetype-dev \
31+
bash \
32+
git \
33+
nodejs \
34+
composer \
35+
php7-tokenizer \
36+
php7-simplexml \
37+
php7-dom \
38+
mysql-client \
39+
yarn@edge \
40+
xvfb \
41+
chromium@3.9 \
42+
chromium-chromedriver@3.9 \
4343
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
4444
&& docker-php-ext-install -j$(nproc) \
45-
gd \
46-
pdo_mysql \
47-
zip \
48-
bcmath \
49-
exif \
50-
intl \
51-
opcache \
52-
pcntl \
53-
iconv \
45+
gd \
46+
pdo_mysql \
47+
zip \
48+
bcmath \
49+
exif \
50+
intl \
51+
opcache \
52+
pcntl \
53+
iconv \
5454
&& pecl install \
55-
redis \
56-
imagick \
55+
redis \
56+
imagick \
5757
&& docker-php-ext-enable \
58-
redis \
59-
imagick \
58+
redis \
59+
imagick \
6060
&& apk del .build-deps
6161

6262
# fix iconv (see https://github.com/docker-library/php/issues/240#issuecomment-305038173)
@@ -90,6 +90,9 @@ COPY ./etc/nginx/ /etc/nginx/
9090
COPY ./usr/local/etc/php/ /usr/local/etc/php/
9191
COPY ./usr/local/etc/php-fpm.d/ /usr/local/etc/php-fpm.d/
9292

93+
# copy bin files
94+
COPY ./usr/local/bin/startup-commands.php /usr/local/bin/
95+
9396
# configure composer
9497
ENV COMPOSER_ALLOW_SUPERUSER=1 \
9598
COMPOSER_MEMORY_LIMIT=-1

usr/local/bin/startup-commands.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* A very simple script in charge of generating the startup commands based on environment variables.
4+
* The script is run on each start of the container.
5+
*
6+
* MIT License
7+
*
8+
* Copyright (c) 2018 TheCodingMachine
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*/
28+
29+
$commands = array_filter($_SERVER, function(string $key) {
30+
return strpos($key, 'STARTUP_COMMAND') === 0;
31+
}, ARRAY_FILTER_USE_KEY);
32+
33+
ksort($commands);
34+
35+
echo "set -e\n";
36+
37+
38+
// Let's run the commands as user $UID if env variable UID is set.
39+
40+
foreach ($commands as $command) {
41+
$line = $command;
42+
if (isset($_SERVER['UID'])) {
43+
$line = 'sudo -E -u \\#'.$_SERVER['UID'].' bash -c '.escapeshellarg($line);
44+
}
45+
echo $line."\n";
46+
}

0 commit comments

Comments
 (0)