Skip to content

Commit 6d43e9b

Browse files
Merge pull request #29 from sherifabdlnaby/php-8.1
- Use PHP 8.1 by default - Add `command-loop-w-cooldown` Script - Security Patches
2 parents 86f1354 + 4120540 commit 6d43e9b

File tree

5 files changed

+89
-31
lines changed

5 files changed

+89
-31
lines changed

.github/auto-release.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@ version-resolver:
2222
default: 'patch'
2323

2424
categories:
25+
- title: '🚀 Features'
26+
labels:
27+
- 'feature'
2528
- title: '🚀 Enhancements'
2629
labels:
2730
- 'enhancement'
28-
- 'feature'
29-
- 'patch'
3031
- title: '🐛 Bug Fixes'
3132
labels:
3233
- 'fix'
3334
- 'bugfix'
3435
- 'bug'
3536
- 'hotfix'
37+
- title: '⬆️ Upgrades & Patches'
38+
labels:
39+
- 'patch'
40+
- 'upgrades'
41+
- title: '🔒 Security Patches'
42+
labels:
43+
- 'security-patch'
44+
- 'security-fix'
3645
- title: '🤖 Automatic Updates'
3746
labels:
3847
- 'auto-update'
@@ -44,15 +53,22 @@ autolabeler:
4453
- label: 'chore'
4554
files:
4655
- '*.md'
56+
4757
- label: 'enhancement'
48-
title: '/enhancement/i'
58+
title: '/enhancement/i'
4959

5060
- label: 'bugfix'
5161
title: '/bugfix/i'
5262

5363
- label: 'bug'
5464
title: '/🐛|🐞|fixes/i'
5565

66+
- label: 'security-patch'
67+
title: '/🔒|security fix/i'
68+
69+
- label: 'upgrades'
70+
title: '/⬆️|upgrade/i'
71+
5672
- label: 'auto-update'
5773
title: '/🤖/i'
5874

@@ -71,10 +87,3 @@ template: |
7187
7288
$CHANGES
7389
74-
replacers:
75-
# Remove irrelevant information from Renovate bot
76-
- search: '/(?<=---\s+)+^#.*(Renovate configuration|Configuration)(?:.|\n)*?This PR has been generated .*/gm'
77-
replace: ''
78-
# Remove Renovate bot banner image
79-
- search: '/\[!\[[^\]]*Renovate\][^\]]*\](\([^)]*\))?\s*\n+/gm'
80-
replace: ''

.github/workflows/build-test-scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
with:
3636
dev: no
3737
command: create-project
38-
args: --no-install --no-scripts symfony/symfony-demo app
39-
php_version: 7.4
38+
args: --no-install --no-scripts symfony/symfony-demo:v2.1.0 app
39+
php_version: 8.1
4040
- name: Build & Deploy
4141
run: make deploy
4242
- name: Test the App Startup

Dockerfile

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ---------------------------------------------- Build Time Arguments --------------------------------------------------
2-
ARG PHP_VERSION="7.4"
3-
ARG PHP_ALPINE_VERSION="3.15"
2+
ARG PHP_VERSION="8.1"
3+
ARG PHP_ALPINE_VERSION="3.16"
44
ARG NGINX_VERSION="1.21"
55
ARG COMPOSER_VERSION="2"
66
ARG XDEBUG_VERSION="3.1.3"
@@ -30,9 +30,9 @@ SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
3030

3131
# ------------------------------------- Install Packages Needed Inside Base Image --------------------------------------
3232

33-
RUN IMAGE_DEPS="tini gettext"; \
34-
RUNTIME_DEPS="fcgi"; \
35-
apk add --no-cache ${IMAGE_DEPS} ${RUNTIME_DEPS}
33+
RUN RUNTIME_DEPS="tini fcgi"; \
34+
SECURITY_UPGRADES="curl"; \
35+
apk add --no-cache --upgrade ${RUNTIME_DEPS} ${SECURITY_UPGRADES}
3636

3737
# ---------------------------------------- Install / Enable PHP Extensions ---------------------------------------------
3838

@@ -57,17 +57,12 @@ RUN apk add --no-cache --virtual .build-deps \
5757
# - Detect Runtime Dependencies of the installed extensions. \
5858
# - src: https://github.com/docker-library/wordpress/blob/master/latest/php8.0/fpm-alpine/Dockerfile \
5959
out="$(php -r 'exit(0);')"; \
60-
[ -z "$out" ]; \
61-
err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
62-
[ -z "$err" ]; \
63-
\
64-
extDir="$(php -r 'echo ini_get("extension_dir");')"; \
60+
[ -z "$out" ]; err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; \
61+
[ -z "$err" ]; extDir="$(php -r 'echo ini_get("extension_dir");')"; \
6562
[ -d "$extDir" ]; \
6663
runDeps="$( \
6764
scanelf --needed --nobanner --format '%n#p' --recursive "$extDir" \
68-
| tr ',' '\n' \
69-
| sort -u \
70-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
65+
| tr ',' '\n' | sort -u | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
7166
)"; \
7267
# Save Runtime Deps in a virtual deps
7368
apk add --no-network --virtual .php-extensions-rundeps $runDeps; \
@@ -99,12 +94,12 @@ COPY docker/fpm/*.conf /usr/local/etc/php-fpm.d/
9994
# --------------------------------------------------- Scripts ----------------------------------------------------------
10095

10196
COPY docker/entrypoint/*-base docker/post-build/*-base docker/pre-run/*-base \
102-
docker/fpm/healthcheck-fpm \
103-
docker/command-loop \
97+
docker/fpm/healthcheck-fpm \
98+
docker/scripts/command-loop* \
10499
# to
105100
/usr/local/bin/
106101

107-
RUN chmod +x /usr/local/bin/*-base /usr/local/bin/healthcheck-fpm /usr/local/bin/command-loop
102+
RUN chmod +x /usr/local/bin/*-base /usr/local/bin/healthcheck-fpm /usr/local/bin/command-loop*
108103

109104
# ---------------------------------------------------- Composer --------------------------------------------------------
110105

@@ -274,6 +269,13 @@ ENTRYPOINT ["nginx-entrypoint"]
274269

275270
FROM nginx AS web
276271

272+
USER root
273+
274+
RUN SECURITY_UPGRADES="curl"; \
275+
apk add --no-cache --upgrade ${SECURITY_UPGRADES}
276+
277+
USER www-data
278+
277279
# Copy Public folder + Assets that's going to be served from Nginx
278280
COPY --chown=www-data:www-data --from=app /app/public /app/public
279281

docker/command-loop renamed to docker/scripts/command-loop

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,4 @@ while true; do
4141
echo "Command exited with status code $STATUS, loop interrupted. shutting down...";
4242
exit $STATUS;
4343
fi
44-
45-
# Add 0.5 Sec sleep to avoid instant shutdowns
46-
sleep 0.5
4744
done
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
# Reference: https://github.com/facile-it/terminable-loop-command
3+
# When running a PHP application, you may encounter the need of a background command that runs continuously.
4+
# You can try to write it as a long running process, but it can be prone to memory leaks and other issues.
5+
#
6+
# With this small Shell+PHP combination, you can have a simple loop that:
7+
# 1. starts the command
8+
# 2. does something
9+
# 3. sleeps for a custom amount of time
10+
# 4. shuts down and restarts back again
11+
# 5. The shell script intercepts SIGTERM/SIGINT signals so, when they are received, the PHP script is stopped ASAP but gracefully,
12+
# since the execution of the body of the command is never truncated.
13+
14+
# This means that you can easily obtain a daemon PHP script without running in memory issues; if you run this in a Kubernetes environment this will be very powerful, since the orchestrator will take care of running the script,
15+
# and at the same time it will apply the proper restart policies in case of crashes. Last but not least, the signal handling will play nice with shutdown requests, like during the roll out of a new deployment.
16+
17+
18+
cooldown=${@:1:1}
19+
command=${@:2}
20+
21+
echo "Starting command: '$command' with cooldown: '$cooldown' seconds"
22+
23+
# Send Termination to Child
24+
_term() {
25+
kill -TERM $CHILD 2>/dev/null
26+
wait $CHILD
27+
}
28+
29+
# If we received termination signal we need to pass it to child
30+
trap _term TERM
31+
32+
while true; do
33+
# Start Command in BG
34+
$command &
35+
36+
# Get It's PID
37+
CHILD=$!
38+
39+
# Wait for it to be finished
40+
wait $CHILD
41+
42+
# Get its status code and break if it exited.
43+
STATUS=$?
44+
if [ $STATUS -ne 0 ]; then
45+
echo "Command exited with status code $STATUS, loop interrupted. shutting down...";
46+
exit $STATUS;
47+
fi
48+
49+
sleep $cooldown
50+
done

0 commit comments

Comments
 (0)