Skip to content

Commit 2021981

Browse files
committed
Added docker files
0 parents  commit 2021981

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM alpine:3.16
2+
LABEL maintainer="JulianPrieber"
3+
LABEL description="LittleLink Custom Docker"
4+
5+
# Setup apache and php
6+
RUN apk --no-cache --update \
7+
add apache2 \
8+
apache2-ssl \
9+
curl \
10+
php8-apache2 \
11+
php8-bcmath \
12+
php8-bz2 \
13+
php8-calendar \
14+
php8-common \
15+
php8-ctype \
16+
php8-curl \
17+
php8-dom \
18+
php8-gd \
19+
php8-iconv \
20+
php8-mbstring \
21+
php8-mysqli \
22+
php8-mysqlnd \
23+
php8-openssl \
24+
php8-pdo_mysql \
25+
php8-pdo_pgsql \
26+
php8-pdo_sqlite \
27+
php8-phar \
28+
php8-session \
29+
php8-xml \
30+
php8-tokenizer \
31+
php8-zip \
32+
&& mkdir /htdocs
33+
34+
COPY littlelink-custom /htdocs
35+
RUN chown -R apache:apache /htdocs
36+
RUN find /htdocs -type d -print0 | xargs -0 chmod 0755
37+
RUN find /htdocs -type f -print0 | xargs -0 chmod 0644
38+
39+
EXPOSE 80 443
40+
41+
ADD docker-entrypoint.sh /
42+
43+
HEALTHCHECK CMD wget -q --no-cache --spider localhost
44+
45+
ENTRYPOINT ["/docker-entrypoint.sh"]

autotest.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
# Exit on non defined variables and on non zero exit codes
4+
set -eu
5+
6+
echo 'Building the container'
7+
8+
docker build ./ -t alpine-apache-php-ci:latest
9+
10+
NET="${DOCKER_NETWORK:-alpine-apache-php-autotest}"
11+
12+
# use failure to switch on create
13+
docker network inspect ${NET} 1>/dev/null 2> /dev/null || docker network create ${NET}
14+
15+
echo 'Preparing test folder'
16+
17+
TMP_DIR="$(mktemp -d --suffix alpine-apache-php)"
18+
19+
printf "<?php \n\
20+
echo 'PHP: ' . PHP_MAJOR_VERSION . PHP_EOL;\n\
21+
echo 'Admin: ' . \$_SERVER['SERVER_ADMIN'] . PHP_EOL;\n\
22+
echo 'Host: ' . \$_SERVER['SERVER_NAME'] . PHP_EOL;\n\
23+
echo 'Memory-limit: ' . ini_get('memory_limit') . PHP_EOL;\n\
24+
echo 'Timezone: ' . ini_get('date.timezone') . PHP_EOL;\n\
25+
" > "${TMP_DIR}/index.php"
26+
27+
chmod 777 "${TMP_DIR}"
28+
chmod 666 "${TMP_DIR}/index.php"
29+
30+
echo 'Running test containers'
31+
32+
# stop if exists or silently exit
33+
docker stop alpine-apache-php-test 1>/dev/null 2> /dev/null || echo '' >/dev/null
34+
35+
docker run --rm --detach \
36+
--name alpine-apache-php-test \
37+
--network ${NET} \
38+
--volume ${TMP_DIR}:/htdocs \
39+
--env HTTP_SERVER_NAME="www.example.xyz" \
40+
--env HTTPS_SERVER_NAME="www.example.xyz" \
41+
--env SERVER_ADMIN="admin@example.xyz" \
42+
--env TZ="Europe/Paris" \
43+
--env PHP_MEMORY_LIMIT="512M" \
44+
alpine-apache-php-ci:latest 1>/dev/null
45+
46+
47+
# stop if exists or silently exit
48+
docker stop alpine-apache-php-test-normal 1>/dev/null 2> /dev/null || echo '' >/dev/null
49+
50+
docker run --rm --detach \
51+
--name alpine-apache-php-test-normal \
52+
--network ${NET} \
53+
--volume ${TMP_DIR}:/htdocs \
54+
alpine-apache-php-ci:latest 1>/dev/null
55+
56+
echo ''
57+
echo 'Running custom tests'
58+
59+
docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test -H 'Host: www.example.xyz'
60+
docker run --rm --network ${NET} curlimages/curl:latest -s http://alpine-apache-php-test
61+
docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test
62+
63+
echo ''
64+
echo 'Running normal tests'
65+
66+
docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test-normal -H 'Host: www.example.xyz'
67+
docker run --rm --network ${NET} curlimages/curl:latest -s http://alpine-apache-php-test-normal
68+
docker run --rm --network ${NET} curlimages/curl:latest -s -k https://alpine-apache-php-test-normal
69+
70+
echo ''
71+
echo 'Cleaning up'
72+
docker stop alpine-apache-php-test 1>/dev/null
73+
docker stop alpine-apache-php-test-normal 1>/dev/null
74+
docker network rm ${NET} 1>/dev/null
75+
76+
rm "${TMP_DIR}/index.php"
77+
rmdir "${TMP_DIR}"

docker-entrypoint.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
# Exit on non defined variables and on non zero exit codes
4+
set -eu
5+
6+
SERVER_ADMIN="${SERVER_ADMIN:-you@example.com}"
7+
HTTP_SERVER_NAME="${HTTP_SERVER_NAME:-www.example.com}"
8+
HTTPS_SERVER_NAME="${HTTPS_SERVER_NAME:-www.example.com}"
9+
LOG_LEVEL="${LOG_LEVEL:-info}"
10+
TZ="${TZ:-UTC}"
11+
PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:-256M}"
12+
13+
echo 'Updating configurations'
14+
15+
# Change Server Admin, Name, Document Root
16+
sed -i "s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN}/" /etc/apache2/httpd.conf
17+
sed -i "s/#ServerName\ www.example.com:80/ServerName\ ${HTTP_SERVER_NAME}/" /etc/apache2/httpd.conf
18+
sed -i 's#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/httpd.conf
19+
sed -i 's#Directory "/var/www/localhost/htdocs"#Directory "/htdocs"#g' /etc/apache2/httpd.conf
20+
sed -i 's#AllowOverride None#AllowOverride All#' /etc/apache2/httpd.conf
21+
22+
# Change TransferLog after ErrorLog
23+
sed -i 's#^ErrorLog .*#ErrorLog "/dev/stderr"\nTransferLog "/dev/stdout"#g' /etc/apache2/httpd.conf
24+
sed -i 's#CustomLog .* combined#CustomLog "/dev/stdout" combined#g' /etc/apache2/httpd.conf
25+
26+
# SSL DocumentRoot and Log locations
27+
sed -i 's#^ErrorLog .*#ErrorLog "/dev/stderr"#g' /etc/apache2/conf.d/ssl.conf
28+
sed -i 's#^TransferLog .*#TransferLog "/dev/stdout"#g' /etc/apache2/conf.d/ssl.conf
29+
sed -i 's#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/conf.d/ssl.conf
30+
sed -i "s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN}/" /etc/apache2/conf.d/ssl.conf
31+
sed -i "s/ServerName\ www.example.com:443/ServerName\ ${HTTPS_SERVER_NAME}/" /etc/apache2/conf.d/ssl.conf
32+
33+
# Re-define LogLevel
34+
sed -i "s#^LogLevel .*#LogLevel ${LOG_LEVEL}#g" /etc/apache2/httpd.conf
35+
36+
# Enable commonly used apache modules
37+
sed -i 's/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/' /etc/apache2/httpd.conf
38+
sed -i 's/#LoadModule\ deflate_module/LoadModule\ deflate_module/' /etc/apache2/httpd.conf
39+
sed -i 's/#LoadModule\ expires_module/LoadModule\ expires_module/' /etc/apache2/httpd.conf
40+
41+
# Modify php memory limit and timezone
42+
sed -i "s/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/" /etc/php8/php.ini
43+
sed -i "s#^;date.timezone =\$#date.timezone = \"${TZ}\"#" /etc/php8/php.ini
44+
45+
echo 'Running Apache'
46+
47+
httpd -D FOREGROUND

0 commit comments

Comments
 (0)