Skip to content

Commit 8183cd4

Browse files
authored
Merge pull request #29 from mhzawadi/dev
Nginx unit build
2 parents e204c6b + c8bada0 commit 8183cd4

File tree

4 files changed

+87
-14
lines changed

4 files changed

+87
-14
lines changed

Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM alpine:3.20
2-
MAINTAINER Matthew Horwood <matt@horwood.biz>
2+
LABEL org.opencontainers.image.authors="matt@horwood.biz"
33

44
# Install required deb packages
55
RUN apk update && \
6-
apk add gnupg nginx php82-fpm php82-common php82-iconv php82-json php82-gd \
6+
apk add gnupg unit-php82 php82-common php82-iconv php82-json php82-gd \
77
php82-curl php82-xml php82-mysqli php82-imap php82-pdo php82-pdo_mysql \
88
php82-soap php82-posix php82-gettext php82-ldap \
99
php82-ctype php82-dom php82-session php82-mbstring curl \
@@ -14,8 +14,8 @@ RUN apk update && \
1414
ln -s /usr/bin/php82 /usr/bin/php;
1515

1616
# Calculate download URL
17-
ENV VERSION 5.2.1
18-
ENV URL https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-all-languages.tar.xz
17+
ENV VERSION=5.2.1
18+
ENV URL=https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-all-languages.tar.xz
1919
LABEL version=$VERSION
2020

2121
# Download tarball, verify it using gpg and extract
@@ -47,14 +47,12 @@ RUN set -ex; \
4747
cp -R /usr/src/phpmyadmin/* /var/www/html/; \
4848
cp /config/config.inc.php /etc/phpmyadmin/config.inc.php && \
4949
cp /config/php.ini /etc/php82/php.ini && \
50-
cp /config/php_fpm_site.conf /etc/php82/php-fpm.d/www.conf; \
51-
chown -R nobody:nginx /var/www/html /sessions; \
52-
cp /config/nginx_site.conf /etc/nginx/http.d/default.conf; \
50+
chown -R unit:unit /var/www/html /sessions; \
5351
cp /config/healthcheck.php /var/www/html/;
5452

5553
EXPOSE 80
5654
ENTRYPOINT ["/config/start.sh"]
57-
CMD ["nginx", "-g", "daemon off;"]
55+
CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock"]
5856

5957
## Health Check
6058
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.5'
1+
---
22

33
# docker stack deploy --compose-file stack-phpmyadmin.yml phpmyadmin
44

setup/start.sh

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#!/bin/sh
22

3-
ln -s /dev/stdout /var/log/php82/error.log
4-
ln -s /dev/stdout /var/log/nginx/access.log
5-
ln -s /dev/stdout /var/log/nginx/error.log
6-
73
if [ ! -f /etc/phpmyadmin/config.secret.inc.php ]; then
84
cat > /etc/phpmyadmin/config.secret.inc.php <<EOT
95
<?php
@@ -15,6 +11,51 @@ if [ ! -f /etc/phpmyadmin/config.user.inc.php ]; then
1511
touch /etc/phpmyadmin/config.user.inc.php
1612
fi
1713

18-
php-fpm82
14+
ln -s /dev/stdout /var/log/unit.log
15+
ln -s /dev/stdout /var/log/unit/access.log
16+
17+
if [ "$1" = "unitd" ] || [ "$1" = "unitd-debug" ]; then
18+
if /usr/bin/find "/var/lib/unit/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
19+
echo "$0: /var/lib/unit/ is not empty, skipping initial configuration..."
20+
else
21+
echo "$0: Launching Unit daemon to perform initial configuration..."
22+
/usr/sbin/$1 --control unix:/var/run/control.unit.sock
23+
24+
for i in $(/usr/bin/seq $WAITLOOPS); do
25+
if [ ! -S /var/run/control.unit.sock ]; then
26+
echo "$0: Waiting for control socket to be created..."
27+
/bin/sleep $SLEEPSEC
28+
else
29+
break
30+
fi
31+
done
32+
# even when the control socket exists, it does not mean unit has finished initialisation
33+
# this curl call will get a reply once unit is fully launched
34+
/usr/bin/curl -s -X GET --unix-socket /var/run/control.unit.sock http://localhost/
35+
36+
curl -X PUT --data-binary @/config/unit.json --unix-socket \
37+
/var/run/control.unit.sock http://localhost/config/
38+
39+
echo "$0: Stopping Unit daemon after initial configuration..."
40+
kill -TERM $(/bin/cat /var/run/unit.pid)
41+
42+
for i in $(/usr/bin/seq $WAITLOOPS); do
43+
if [ -S /var/run/control.unit.sock ]; then
44+
echo "$0: Waiting for control socket to be removed..."
45+
/bin/sleep $SLEEPSEC
46+
else
47+
break
48+
fi
49+
done
50+
if [ -S /var/run/control.unit.sock ]; then
51+
kill -KILL $(/bin/cat /var/run/unit.pid)
52+
rm -f /var/run/control.unit.sock
53+
fi
54+
55+
echo
56+
echo "$0: Unit initial configuration complete; ready for start up..."
57+
echo
58+
fi
59+
fi
1960

2061
exec "$@"

setup/unit.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"listeners": {
3+
"*:80": {
4+
"pass": "routes"
5+
}
6+
},
7+
8+
"routes": [
9+
{
10+
"match": {
11+
"uri": "~\\.(css|gif|html?|ico|jpg|js(on)?|png|svg|ttf|woff2?)$"
12+
},
13+
14+
"action": {
15+
"share": "/var/www/html$uri"
16+
}
17+
},
18+
{
19+
"action": {
20+
"pass": "applications/phpmyadmin"
21+
}
22+
}
23+
],
24+
25+
"applications": {
26+
"phpmyadmin": {
27+
"type": "php",
28+
"root": "/var/www/html/"
29+
}
30+
},
31+
"access_log": {
32+
"path": "/var/log/unit/access.log"
33+
}
34+
}

0 commit comments

Comments
 (0)