Skip to content

Commit 8352f73

Browse files
Merge pull request #34 from STaRDoGG/main
Update docker-entrypoint.sh
2 parents a93e5cf + 231fb1e commit 8352f73

2 files changed

Lines changed: 98 additions & 23 deletions

File tree

Dockerfile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM alpine:3.16
1+
FROM alpine:3.16.0
22
LABEL maintainer="JulianPrieber"
33
LABEL description="LittleLink Custom Docker"
44

5+
EXPOSE 80 443
6+
57
# Setup apache and php
68
RUN apk --no-cache --update \
79
add apache2 \
@@ -31,17 +33,27 @@ RUN apk --no-cache --update \
3133
php8-xml \
3234
php8-tokenizer \
3335
php8-zip \
36+
tzdata \
3437
&& mkdir /htdocs
3538

3639
COPY littlelink-custom /htdocs
3740
RUN chown -R apache:apache /htdocs
3841
RUN find /htdocs -type d -print0 | xargs -0 chmod 0755
39-
RUN find /htdocs -type f -print0 | xargs -0 chmod 0644
42+
RUN find /htdocs -type f -print0 | xargs -0 chmod 0644
4043

41-
EXPOSE 80 443
44+
COPY --chmod=0755 docker-entrypoint.sh /usr/local/bin/
45+
46+
HEALTHCHECK CMD curl -f http://localhost -A "HealthCheck" || exit 1
4247

43-
ADD docker-entrypoint.sh /
48+
# Forward Apache access and error logs to Docker's log collector.
49+
# Optional last line adds extra verbosity with for example:
50+
# [ssl:info] [pid 33] [client 10.0.5.8:45542] AH01964: Connection to child 2 established (server your.domain:443)
51+
RUN ln -sf /dev/stdout /var/www/logs/access.log \
52+
&& ln -sf /dev/stderr /var/www/logs/error.log \
53+
&& ln -sf /dev/stderr /var/www/logs/ssl-access.log
54+
# && ln -sf /dev/stderr /var/www/logs/ssl-error.log
4455

45-
HEALTHCHECK CMD wget -q --no-cache --spider localhost
56+
# Set console entry path
57+
WORKDIR /htdocs/littlelink
4658

47-
ENTRYPOINT ["/docker-entrypoint.sh"]
59+
CMD ["docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Exit on non defined variables and on non zero exit codes
44
set -eu
55

6+
# + ---------- + #
7+
# | -- VARS -- | #
8+
# + ---------- + #
9+
610
SERVER_ADMIN="${SERVER_ADMIN:-you@example.com}"
711
HTTP_SERVER_NAME="${HTTP_SERVER_NAME:-localhost}"
812
HTTPS_SERVER_NAME="${HTTPS_SERVER_NAME:-localhost}"
@@ -11,41 +15,100 @@ TZ="${TZ:-UTC}"
1115
PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:-256M}"
1216
UPLOAD_MAX_FILESIZE="${UPLOAD_MAX_FILESIZE:-8M}"
1317

14-
echo 'Updating configurations'
18+
# If TRUE, outputs pre and post-change config files, if a /debug folder has also been mounted.
19+
# i.e. - '/opt/docker/configs/littlelink/debug:/debug:rw'
20+
# Useful for comparing (and fixing) changes, if necessary.
21+
DEBUG="TRUE"
22+
23+
# Read Current LLC Version
24+
# When version.json has CR/LF, it fx up, so have to add tr to remove the line endings.
25+
v="$(cat /htdocs/version.json | tr -d '\r\n')"
26+
27+
# Calc length of whitespace we need, based on version length.
28+
vlen="$((27-${#v}))"
29+
30+
echo '+ ------------------------------------------------------------------ +'
31+
printf '| LITTLELINK CUSTOM v%s%*s|\n' "${v}" "$vlen" | tr ' ' " "
32+
33+
# + ---------------- + #
34+
# | -- HTTPD.CONF -- | #
35+
# + ---------------- + #
36+
37+
echo '+ ------------------------------------------------------------------ +'
38+
echo '| Updating Configuration: Apache Base (/etc/apache2/httpd.conf) |'
39+
40+
# ALTER: Server Admin, Name, Document Root.
41+
42+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/apache2/httpd.conf /debug/httpd.BEFORE.conf;fi
1543

16-
# Change Server Admin, Name, Document Root
1744
sed -i "s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN}/" /etc/apache2/httpd.conf
18-
sed -i "s/#ServerName\ localhost:80/ServerName\ ${HTTP_SERVER_NAME}/" /etc/apache2/httpd.conf
45+
sed -i "s/#ServerName\ www.example.com:80/ServerName\ ${HTTP_SERVER_NAME}/" /etc/apache2/httpd.conf
1946
sed -i 's#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/httpd.conf
2047
sed -i 's#Directory "/var/www/localhost/htdocs"#Directory "/htdocs"#g' /etc/apache2/httpd.conf
2148
sed -i 's#AllowOverride None#AllowOverride All#' /etc/apache2/httpd.conf
2249

23-
# Change TransferLog after ErrorLog
24-
sed -i 's#^ErrorLog .*#ErrorLog "/dev/stderr"\nTransferLog "/dev/stdout"#g' /etc/apache2/httpd.conf
25-
sed -i 's#CustomLog .* combined#CustomLog "/dev/stdout" combined#g' /etc/apache2/httpd.conf
26-
27-
# SSL DocumentRoot and Log locations
28-
sed -i 's#^ErrorLog .*#ErrorLog "/dev/stderr"#g' /etc/apache2/conf.d/ssl.conf
29-
sed -i 's#^TransferLog .*#TransferLog "/dev/stdout"#g' /etc/apache2/conf.d/ssl.conf
30-
sed -i 's#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/conf.d/ssl.conf
31-
sed -i "s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN}/" /etc/apache2/conf.d/ssl.conf
32-
sed -i "s/ServerName\ localhost:443/ServerName\ ${HTTPS_SERVER_NAME}/" /etc/apache2/conf.d/ssl.conf
50+
# ALTER: TransferLog after ErrorLog.
51+
sed -i 's#^ErrorLog .*#ErrorLog "logs/error.log"#g' /etc/apache2/httpd.conf
52+
sed -i 's#LogFormat .* %t#LogFormat "[%{%a %b %d %H:%M:%S}t.%{usec_frac}t %{%Y}t] [httpd.conf] %h %l %u#g' /etc/apache2/httpd.conf
53+
sed -i 's#CustomLog logs.* combined#BrowserMatchNoCase ^healthcheck nolog\n\n CustomLog "logs/access.log" combinedio env=!nolog\n#g' /etc/apache2/httpd.conf
3354

34-
# Re-define LogLevel
55+
# ALTER: LogLevel.
3556
sed -i "s#^LogLevel .*#LogLevel ${LOG_LEVEL}#g" /etc/apache2/httpd.conf
3657

3758
# Enable commonly used apache modules
38-
sed -i 's/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/' /etc/apache2/httpd.conf
3959
sed -i 's/#LoadModule\ deflate_module/LoadModule\ deflate_module/' /etc/apache2/httpd.conf
4060
sed -i 's/#LoadModule\ expires_module/LoadModule\ expires_module/' /etc/apache2/httpd.conf
61+
sed -i 's/#LoadModule\ logio_module/LoadModule\ logio_module/' /etc/apache2/httpd.conf
62+
sed -i 's/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/' /etc/apache2/httpd.conf
63+
64+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/apache2/httpd.conf /debug/httpd.AFTER.conf;fi
4165

42-
# Modify php memory limit and timezone
66+
# + -------------- + #
67+
# | -- SSL.CONF -- | #
68+
# + -------------- + #
69+
70+
echo '| Updating Configuration: Apache SSL (/etc/apache2/conf.d/ssl.conf) |'
71+
72+
# ALTER: SSL DocumentRoot and Log locations
73+
74+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/apache2/conf.d/ssl.conf /debug/ssl.BEFORE.conf;fi
75+
76+
sed -i 's#^ErrorLog .*#ErrorLog "logs/ssl-error.log"#g' /etc/apache2/conf.d/ssl.conf
77+
sed -i "s/^TransferLog .*/#TransferLog \"logs\/ssl-transfer.log\"\nLogLevel ${LOG_LEVEL}/g" /etc/apache2/conf.d/ssl.conf
78+
sed -i 's#^DocumentRoot ".*#DocumentRoot "/htdocs"#g' /etc/apache2/conf.d/ssl.conf
79+
sed -i "s/ServerAdmin\ you@example.com/ServerAdmin\ ${SERVER_ADMIN}/" /etc/apache2/conf.d/ssl.conf
80+
sed -i "s/ServerName\ www.example.com:443/ServerName\ ${HTTPS_SERVER_NAME}/" /etc/apache2/conf.d/ssl.conf
81+
82+
sed -i 's#CustomLog .*#LogFormat "[%{%a %b %d %H:%M:%S}t.%{usec_frac}t %{%Y}t] [ssl.conf] %h %l %u \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\"" combined\n\nCustomLog "logs/ssl-access.log" combined#g' /etc/apache2/conf.d/ssl.conf
83+
sed -i '/.*%{SSL_PROTOCOL}x.*/d' /etc/apache2/conf.d/ssl.conf
84+
85+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/apache2/conf.d/ssl.conf /debug/ssl.AFTER.conf;fi
86+
87+
# + ------------- + #
88+
# | -- PHP.INI -- | #
89+
# + ------------- + #
90+
91+
echo '| Updating Configuration: PHP (/etc/php8/php.ini) |'
92+
93+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/php8/php.ini /debug/php.BEFORE.ini;fi
94+
95+
# ALTER: Modify php memory limit and timezone
4396
sed -i "s/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/" /etc/php8/php.ini
4497
sed -i "s/upload_max_filesize = .*/upload_max_filesize = ${UPLOAD_MAX_FILESIZE}/" /etc/php8/php.ini
4598
sed -i "s#^;date.timezone =\$#date.timezone = \"${TZ}\"#" /etc/php8/php.ini
4699

47100
echo "is_llc_docker = true" >> /etc/php8/php.ini
48101

49-
echo 'Running Apache'
102+
if [[ ${DEBUG} == "TRUE" && -d /debug ]]; then cp /etc/php8/php.ini /debug/php.AFTER.ini;fi
103+
104+
# + ---------- + #
105+
# | -- MISC -- | #
106+
# + ---------- + #
107+
108+
echo '| Updating Configuration: Complete |'
109+
echo '| ------------------------------------------------------------------ |'
110+
echo '| Running Apache |'
111+
echo '+ ------------------------------------------------------------------ +'
112+
echo
50113

51114
httpd -D FOREGROUND

0 commit comments

Comments
 (0)