Skip to content

Commit

Permalink
refactor: custom init
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschubek committed Nov 26, 2024
1 parent b29025c commit 4dcab15
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
22 changes: 13 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# includes redis

FROM php:8.4-fpm-alpine AS base

ENV DIRBROWSER_VERSION=3.9.0

RUN apk update && apk upgrade

RUN docker-php-ext-install opcache
Expand All @@ -20,7 +20,7 @@ RUN apk add --no-cache redis

RUN apk add --no-cache nginx

RUN apk add --no-cache supervisor
RUN apk add --no-cache bash

RUN apk add --no-cache curl \
&& curl -fSsL https://github.com/adrianschubek/utpp/releases/download/0.5.0/utpp-alpine -o /usr/local/bin/utpp && chmod +x /usr/local/bin/utpp\
Expand All @@ -40,16 +40,19 @@ COPY server/nginx/nginx.conf /etc/nginx/nginx.conf

COPY server/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

COPY server/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY server/php/fpm-pool.conf /usr/local/etc/php-fpm.d/www.conf

COPY server/php/php.ini /usr/local/etc/php/conf.d/custom.ini

COPY src/index.php /var/www/html

# skipped in v3.9
# COPY src/worker.php /var/www/html

COPY src/init.sh /init.sh

RUN chmod +x /init.sh

ENV THEME=default

ENV DATE_FORMAT=relative
Expand Down Expand Up @@ -109,12 +112,13 @@ ENV BATCH_MAX_TOTAL_SIZE=500
ENV BATCH_MAX_FILE_SIZE=100
# MB, how much system disk space to keep free at all times
ENV BATCH_MIN_SYSTEM_FREE_DISK=500
# watch filesystem
ENV WORKER_WATCH=true
# seconds re-scan
ENV WORKER_SCAN_INTERVAL=60

# TODO Ratelimiting?

RUN chmod +x /init.sh
ENV WORKER_FORCE_RESCAN=

EXPOSE 8080

# Let supervisord start nginx & php-fpm
CMD ["/init.sh"]
18 changes: 10 additions & 8 deletions src/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ YELLOW='\033[0;33m'
RED='\033[0;31m'
GREEN_BG_BLACK_TEXT='\033[42;30m'
NC='\033[0m' # reset
MAX_STEPS=5

dbv=$DIRBROWSER_VERSION
echo -e "${GREEN_BG_BLACK_TEXT} dir-browser v${dbv} by Adrian Schubek${NC}"
echo -e "${CYAN} -> https://dir.adriansoftware.de <- ${NC}"

echo -e "${YELLOW}[ 1/6 ] Pre-processing configs using utpp... ${NC}"
echo -e "${YELLOW}[ 1/$MAX_STEPS ] Pre-processing configs using utpp... ${NC}"
utpp "/etc/nginx/**;/usr/local/etc/php*/**;/var/www/html/*.php"

echo -e "${YELLOW}[ 2/6 ] Starting php-fpm... ${NC}"
echo -e "${YELLOW}[ 2/$MAX_STEPS ] Starting php-fpm... ${NC}"
php-fpm -RF &

echo -e "${YELLOW}[ 3/6 ] Starting worker... ${NC}"
php /var/www/html/worker.php &
# skipped in v3.9
# echo -e "${YELLOW}[ 3/$MAX_STEPS ] Starting worker... ${NC}"
# php /var/www/html/worker.php &

echo -e "${YELLOW}[ 4/6 ] Starting nginx... ${NC}"
echo -e "${YELLOW}[ 3/$MAX_STEPS ] Starting nginx... ${NC}"
nginx -g 'daemon off;' &

echo -e "${YELLOW}[ 5/6 ] Starting redis... ${NC}"
echo -e "${YELLOW}[ 4/$MAX_STEPS ] Starting redis... ${NC}"
redis-server /etc/redis.conf --save 60 1 &

echo -e "${GREEN}[ 6/6 ] All services running!${NC}"
echo -e "${GREEN}[ 5/$MAX_STEPS ] All services running!${NC}"
wait -n

echo -e "${RED}Error: Terminating due to a service exiting...${NC}"
echo -e "${RED}[ Error ] Terminating due to a service exiting...${NC}"
exit $?

0 comments on commit 4dcab15

Please sign in to comment.