From 7d760c25e38fc9826599a930f2e58ef2c7d7bfa0 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Tue, 6 Feb 2024 00:20:42 +0100 Subject: [PATCH] Initial commit --- Dockerfile | 22 +++++++++++++ Makefile | 48 +++++++++++++++++++++++++++++ README.md | 3 ++ config/entrypoint.sh | 26 ++++++++++++++++ config/frameworks/00-nginx-site.sh | 9 ++++++ config/frameworks/10-symfony.sh | 9 ++++++ config/frameworks/90-composer.sh | 9 ++++++ config/frameworks/99-sorry.sh | 3 ++ config/supervisor/exit-on-error.ini | 3 ++ config/supervisor/nginx.ini | 9 ++++++ config/supervisor/php-fpm.ini | 9 ++++++ 11 files changed, 150 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100755 config/entrypoint.sh create mode 100644 config/frameworks/00-nginx-site.sh create mode 100644 config/frameworks/10-symfony.sh create mode 100644 config/frameworks/90-composer.sh create mode 100644 config/frameworks/99-sorry.sh create mode 100644 config/supervisor/exit-on-error.ini create mode 100644 config/supervisor/nginx.ini create mode 100644 config/supervisor/php-fpm.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7204fb7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# NoccyLabs Alpine Nginx+PHP 8.3 Base Image +FROM alpine:3.19 + +RUN apk add --no-cache \ + php83-fpm php83-cli \ + php83-curl php83-iconv php83-gd php83-mbstring php83-posix \ + php83-phar php83-openssl php83-ctype php83-tokenizer php83-xml php83-session \ + php83-dom php83-pecl-imagick php83-zip php83-xmlwriter php83-simplexml php83-xmlreader \ + php83-pdo php83-pdo_sqlite php83-pdo_mysql php83-fileinfo php83-exif \ + tini \ + nginx \ + supervisor + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +COPY ./config/supervisor/* /etc/supervisor.d/ +COPY ./config/frameworks/* /scripts/frameworks/ +COPY ./config/entrypoint.sh /scripts/entrypoint.sh + +ENTRYPOINT [ "/sbin/tini", "--" ] +CMD /scripts/entrypoint.sh +WORKDIR /application +EXPOSE 80 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..174aa9f --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.SILENT: +.PHONY: help + +DOCKER_IMAGE = dev.noccylabs.info/noccylabs/alpine-php83-aio:latest + +COLOR_RESET = \033[0m +COLOR_INFO = \033[32m +COLOR_COMMENT = \033[33m + +### Help +help: + printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n" + printf " make [target]\n\n" + printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n" + awk '/^[a-zA-Z\-\_0-9\.@]+:/ { \ + helpMessage = match(lastLine, /^### (.*)/); \ + if (helpMessage) { \ + helpCommand = substr($$1, 0, index($$1, ":")); \ + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ + printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ + } \ + } \ + { lastLine = $$0 }' $(MAKEFILE_LIST) + +.PHONY: docker +### Build docker image +docker: + docker build -t ${DOCKER_IMAGE} . + +.PHONY: docker-push +### Publish image +docker-push: + docker push ${DOCKER_IMAGE} + +.PHONY: docker-test +### Test docker image +docker-test: + #docker create --name php83-aio ${DOCKER_IMAGE} + #docker start -i php83-aio || true + #docker stop php83-aio + #docker rm php83-aio + docker run --rm -it ${DOCKER_IMAGE} + +.PHONY: docker-shell +### Open a shell in the container +docker-shell: + docker run --rm -it ${DOCKER_IMAGE} sh || true + diff --git a/README.md b/README.md new file mode 100644 index 0000000..96fb4e7 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# NoccyLabs PHP 8.3 Alpine All-in-One Base Image + + diff --git a/config/entrypoint.sh b/config/entrypoint.sh new file mode 100755 index 0000000..46f479f --- /dev/null +++ b/config/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# run scripts in /entrypoint.d/ +if [ -d /entrypoint.d ]; then + echo "[-] Calling entrypoint scripts..." + for filename in /entrypoint.d/*.sh; do + echo " -> $filename" + if ! sh "$filename"; then exit 1; fi + done +else + echo "[!] No scripts matching *.sh found in /entrypoint.d" +fi + +# run framework setups +if [ -d /scripts/frameworks ]; then + echo "[-] Calling framework setup scripts..." + for filename in /scripts/frameworks/*.sh; do + sh "$filename" && break + done +else + echo "[!] No scripts matching *.sh found in /scripts/frameworks" +fi + +# pass off to supervisor +echo "[-] Spawning supervisor" +exec /usr/bin/supervisord -n -c /etc/supervisord.conf diff --git a/config/frameworks/00-nginx-site.sh b/config/frameworks/00-nginx-site.sh new file mode 100644 index 0000000..4be6dca --- /dev/null +++ b/config/frameworks/00-nginx-site.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -f /application/.nginx-site.conf ]; then + echo " -- Installing nginx website config..." + cp -F /application/.nginx-site.conf /etc/nginx/sites-enabled/default.conf +fi + +# scripts at level 00 should not end the framework setup +exit 1 diff --git a/config/frameworks/10-symfony.sh b/config/frameworks/10-symfony.sh new file mode 100644 index 0000000..0d91cc1 --- /dev/null +++ b/config/frameworks/10-symfony.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -f /application/symfony.lock ]; then + exit 1 +fi + +echo " == Detected symfony project." +cd /application +/usr/bin/composer install --no-dev --no-cache --optimize-autoloader --no-progress diff --git a/config/frameworks/90-composer.sh b/config/frameworks/90-composer.sh new file mode 100644 index 0000000..0650593 --- /dev/null +++ b/config/frameworks/90-composer.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -f /application/composer.json ]; then + exit 1 +fi + +echo " == Detected composer project." +cd /application +/usr/bin/composer install --no-dev --no-cache --optimize-autoloader --no-progress diff --git a/config/frameworks/99-sorry.sh b/config/frameworks/99-sorry.sh new file mode 100644 index 0000000..3074ff1 --- /dev/null +++ b/config/frameworks/99-sorry.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo " ** Sorry, no framework detected." diff --git a/config/supervisor/exit-on-error.ini b/config/supervisor/exit-on-error.ini new file mode 100644 index 0000000..3a7f4ba --- /dev/null +++ b/config/supervisor/exit-on-error.ini @@ -0,0 +1,3 @@ +[eventlistener:process-trap] +command=sh -c "echo READY && read line && kill -SIGQUIT $PPID" +events=PROCESS_STATE_STOPPED,PROCESS_STATE_EXITED,PROCESS_STATE_FATAL diff --git a/config/supervisor/nginx.ini b/config/supervisor/nginx.ini new file mode 100644 index 0000000..62deac9 --- /dev/null +++ b/config/supervisor/nginx.ini @@ -0,0 +1,9 @@ +[program:nginx] +command=/usr/sbin/nginx -c /etc/nginx/nginx.conf -g 'daemon off;' +autostart=true +autorestart=false +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +exitcodes=0 diff --git a/config/supervisor/php-fpm.ini b/config/supervisor/php-fpm.ini new file mode 100644 index 0000000..5663d72 --- /dev/null +++ b/config/supervisor/php-fpm.ini @@ -0,0 +1,9 @@ +[program:php-fpm] +command=/usr/sbin/php-fpm83 -F +autostart=true +autorestart=false +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +exitcodes=0