Skip to content

Commit 2a8c885

Browse files
committed
add first test with apache
1 parent c293b94 commit 2a8c885

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed

Dockerfile-apache

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#
2+
# This image uses 2 interstage and an php:7.1-apache final stage
3+
#
4+
# Interstages are:
5+
# - composer
6+
# - npm & yarn & grunt
7+
#
8+
# Final stage gets all that generated stuff and add it to the final image
9+
#
10+
11+
############################
12+
#=== composer interstage ===
13+
############################
14+
FROM composer:latest as composer
15+
WORKDIR /app
16+
17+
#=== Get PMF source code ===
18+
ARG PMF_BRANCH="3.0"
19+
RUN set -x \
20+
&& git clone \
21+
--depth 1 \
22+
-b $PMF_BRANCH \
23+
https://github.com/thorsten/phpMyFAQ.git \
24+
/app
25+
26+
#=== Call composer ===
27+
RUN set -x \
28+
&& composer install --no-dev
29+
30+
########################
31+
#=== yarn interstage ===
32+
########################
33+
FROM node:latest as yarn
34+
WORKDIR /app
35+
36+
COPY --from=composer /app /app
37+
38+
RUN set -x \
39+
&& npm install node-sass -g --unsafe-perm
40+
41+
RUN set -x \
42+
&& yarn install \
43+
&& yarn build
44+
45+
#################################
46+
#=== Final stage with payload ===
47+
#################################
48+
FROM php:7.1-apache
49+
50+
#=== Install gd php dependencie ===
51+
RUN set -x \
52+
&& buildDeps="libpng-dev libjpeg-dev libfreetype6-dev" \
53+
&& apt-get update && apt-get install -y ${buildDeps} --no-install-recommends \
54+
\
55+
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
56+
&& docker-php-ext-install gd \
57+
\
58+
&& apt-get purge -y ${buildDeps} \
59+
&& rm -rf /var/lib/apt/lists/*
60+
61+
#=== Install ldap php dependencie ===
62+
RUN set -x \
63+
&& buildDeps="libldap2-dev" \
64+
&& apt-get update && apt-get install -y ${buildDeps} --no-install-recommends \
65+
\
66+
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
67+
&& docker-php-ext-install ldap \
68+
\
69+
&& apt-get purge -y ${buildDeps} \
70+
&& rm -rf /var/lib/apt/lists/*
71+
72+
#=== Install intl, soap opcache, and zip php dependencie ===
73+
RUN set -x \
74+
&& buildDeps="libicu-dev zlib1g-dev libxml2-dev" \
75+
&& apt-get update && apt-get install -y ${buildDeps} --no-install-recommends \
76+
\
77+
&& docker-php-ext-configure intl \
78+
&& docker-php-ext-install intl \
79+
&& docker-php-ext-install zip \
80+
&& docker-php-ext-install soap \
81+
&& docker-php-ext-install opcache \
82+
\
83+
&& apt-get purge -y ${buildDeps} \
84+
&& rm -rf /var/lib/apt/lists/*
85+
86+
#=== Install mysqli php dependencie ===
87+
RUN set -x \
88+
&& docker-php-ext-install mysqli
89+
90+
#=== Install pgsql dependencie ===
91+
RUN set -ex \
92+
&& buildDeps="libpq-dev" \
93+
&& apt-get update && apt-get install -y $buildDeps \
94+
\
95+
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
96+
&& docker-php-ext-install pdo pdo_pgsql pgsql \
97+
\
98+
&& apt-get purge -y ${buildDeps} \
99+
&& rm -rf /var/lib/apt/lists/*
100+
101+
#=== php default ===
102+
ENV PMF_TIMEZONE="Europe/Berlin" \
103+
PMF_ENABLE_UPLOADS=On \
104+
PMF_MEMORY_LIMIT=64M \
105+
PMF_DISABLE_HTACCESS="" \
106+
PHP_LOG_ERRORS=On \
107+
PHP_ERROR_REPORTING=E_ALL
108+
109+
#=== Add source code from previously built interstage ===
110+
COPY --from=yarn /app/phpmyfaq .
111+
112+
#=== Ensure debug mode is disabled ===
113+
RUN set -x \
114+
&& sed -ri ./src/Bootstrap.php \
115+
-e "s~define\('DEBUG', true\);~define\('DEBUG', false\);~"
116+
117+
#=== Set custom entrypoint ===
118+
COPY docker-entrypoint.sh /entrypoint
119+
RUN chmod +x /entrypoint
120+
ENTRYPOINT [ "/entrypoint" ]
121+
122+
#=== Re-Set CMD as we changed the default entrypoint ===
123+
CMD [ "apache2-foreground" ]

docker-entrypoint.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#! /bin/sh
2+
3+
# Exit on error
4+
set -e
5+
6+
#=== Set folder permissions ===
7+
folders="attachments data images config"
8+
9+
mkdir -vp $folders
10+
11+
{
12+
if [ -f "$APACHE_ENVVARS" ]; then
13+
. "$APACHE_ENVVARS"
14+
chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" $folders
15+
else
16+
chown -R www-data:www-data $folders
17+
fi
18+
chmod 775 $folders
19+
}
20+
21+
##=== Check database vars ===
22+
#=== DB host ===
23+
if [ -z "$PMF_DB_HOST" -a ! -e "./config/database.php" ]; then
24+
echo >&2 'WARN: missing PMF_DB_HOST environment variable'
25+
echo >&2 ' Did you forget to --link some_mysql_container:db ?'
26+
else
27+
#=== DB user and pass ===
28+
: ${PMF_DB_USER:=root}
29+
if [ "$PMF_DB_USER" = 'root' ]; then
30+
: ${PMF_DB_PASS:=$DB_ENV_MYSQL_ROOT_PASSWORD}
31+
fi
32+
33+
if [ -z "$PMF_DB_PASS" ]; then
34+
echo >&2 'ERROR: missing required PMF_DB_PASS environment variable'
35+
echo >&2 ' Did you forget to -e PMF_DB_PASS=... ?'
36+
echo >&2
37+
echo >&2 ' (Also of interest might be PMF_DB_USER and PMF_DB_NAME.)'
38+
exit 1
39+
#=== Setup database if needed ===
40+
elif [ 0 -eq 1 ]; then # TODO : Add something like: php setup/maintenance.php --vars...
41+
{
42+
echo "<?php"
43+
echo "\$DB['server'] = '$PMF_DB_HOST';"
44+
echo "\$DB['user'] = '$PMF_DB_USER';"
45+
echo "\$DB['password'] = '$PMF_DB_PASS';"
46+
echo "\$DB['db'] = '${PMF_DB_NAME:-phpmyfaq}';"
47+
echo "\$DB['prefix'] = '${PMF_DB_PREFIX}';"
48+
echo "\$DB['type'] = '${PMF_DB_TYPE:-mysqli}';"
49+
} | tee ./config/database.php
50+
fi
51+
fi
52+
53+
if [ -f "$APACHE_ENVVARS" ]; then
54+
#=== Enable htaccess for search engine optimisations ===
55+
if [ "x${DISABLE_HTACCESS}" = "x" ]; then
56+
a2enmod rewrite headers
57+
[ ! -f /.htaccess ] && cp _.htaccess .htaccess
58+
sed -ri .htaccess \
59+
-e "s~RewriteBase /phpmyfaq/~RewriteBase /~"
60+
# Enabling permissions override
61+
sed -ri ${APACHE_CONFDIR}/conf-available/*.conf \
62+
-e "s~(.*AllowOverride).*~\1 All~g"
63+
else
64+
rm .htaccess
65+
# Disabling permissions override
66+
sed -ri ${APACHE_CONFDIR}/conf-available/*.conf \
67+
-e "s~(.*AllowOverride).*~\1 none~g"
68+
fi
69+
fi
70+
71+
#=== Configure php ===
72+
{
73+
echo "# php settings:"
74+
echo "register_globals = Off"
75+
echo "safe_mode = Off"
76+
echo "log_errors = $PHP_LOG_ERRORS"
77+
echo "error_reporting = $PHP_ERROR_REPORTING"
78+
echo "date.timezone = $PMF_TIMEZONE"
79+
echo "memory_limit = $PMF_MEMORY_LIMIT"
80+
echo "file_upload = $PMF_ENABLE_UPLOADS"
81+
} | tee $PHP_INI_DIR/conf.d/php.ini
82+
83+
#=== Set recommanded opcache settings ===
84+
# see https://secure.php.net/manual/en/opcache.installation.php
85+
{
86+
echo "opcache.memory_consumption=128"
87+
echo "opcache.interned_strings_buffer=8"
88+
echo "opcache.max_accelerated_files=4000"
89+
echo "opcache.revalidate_freq=2"
90+
echo "opcache.fast_shutdown=1"
91+
echo "opcache.enable_cli=1"
92+
} | tee $PHP_INI_DIR/conf.d/opcache-recommended.ini
93+
94+
docker-php-entrypoint "$@"

0 commit comments

Comments
 (0)