⚡️ feat: Support use PUID PGID set file permissions.
This commit is contained in:
parent
ea78120b36
commit
c30e318186
3 changed files with 78 additions and 20 deletions
|
|
@ -56,7 +56,7 @@ ENV JAVA_HOME=/jre \
|
||||||
|
|
||||||
RUN npm install -g pm2 && \
|
RUN npm install -g pm2 && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nginx wget curl unzip tini && \
|
apt-get install -y --no-install-recommends nginx wget curl unzip tini gosu && \
|
||||||
mkdir -p $LIB_PATH && \
|
mkdir -p $LIB_PATH && \
|
||||||
wget --no-check-certificate -q -O libs.zip https://github.com/p-vorobyev/spring-boot-starter-telegram/releases/download/1.15.0/libs.zip && \
|
wget --no-check-certificate -q -O libs.zip https://github.com/p-vorobyev/spring-boot-starter-telegram/releases/download/1.15.0/libs.zip && \
|
||||||
unzip -q libs.zip -d /tmp/tdlib && \
|
unzip -q libs.zip -d /tmp/tdlib && \
|
||||||
|
|
@ -89,7 +89,6 @@ COPY --chown=1000:1000 ./web/pm2.json /app/web/
|
||||||
COPY --chown=1000:1000 ./entrypoint.sh .
|
COPY --chown=1000:1000 ./entrypoint.sh .
|
||||||
COPY --chown=1000:1000 ./nginx.conf /etc/nginx/nginx.conf
|
COPY --chown=1000:1000 ./nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
USER 1000
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ services:
|
||||||
container_name: telegram-files
|
container_name: telegram-files
|
||||||
image: ghcr.io/jarvis2f/telegram-files:latest
|
image: ghcr.io/jarvis2f/telegram-files:latest
|
||||||
restart: always
|
restart: always
|
||||||
# Default use 1000:1000 for user:group. If you want to use root, uncomment the line below.
|
|
||||||
# user: "root"
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "curl", "-f", "http://127.0.0.1/api/health" ]
|
test: [ "CMD", "curl", "-f", "http://127.0.0.1/api/health" ]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
|
@ -12,6 +10,9 @@ services:
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
environment:
|
environment:
|
||||||
|
# PUID and PGID are the user id and group id of the user who owns the files in the mounted volume.
|
||||||
|
# PUID: 1000
|
||||||
|
# PGID: 1000
|
||||||
APP_ENV: "prod"
|
APP_ENV: "prod"
|
||||||
APP_ROOT: "/app/data"
|
APP_ROOT: "/app/data"
|
||||||
TELEGRAM_API_ID: ${TELEGRAM_API_ID}
|
TELEGRAM_API_ID: ${TELEGRAM_API_ID}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,82 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
on_terminate() {
|
set -e # Exit on error
|
||||||
echo "Caught termination signal. Shutting down processes..."
|
|
||||||
kill -TERM "$JAVA_PID" 2>/dev/null
|
# Default configuration
|
||||||
kill -TERM "$PM2_PID" 2>/dev/null
|
PUID=${PUID:-0}
|
||||||
kill -TERM "$NGINX_PID" 2>/dev/null
|
PGID=${PGID:-0}
|
||||||
wait
|
|
||||||
echo "All processes have been terminated."
|
# Store PIDs in variables
|
||||||
exit 0
|
JAVA_PID=""
|
||||||
|
PM2_PID=""
|
||||||
|
NGINX_PID=""
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
echo "Cleaning up processes..."
|
||||||
|
|
||||||
|
# Check and kill each process individually
|
||||||
|
if [ -n "$JAVA_PID" ]; then
|
||||||
|
kill -TERM "$JAVA_PID" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
if [ -n "$PM2_PID" ]; then
|
||||||
|
kill -TERM "$PM2_PID" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
if [ -n "$NGINX_PID" ]; then
|
||||||
|
kill -TERM "$NGINX_PID" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
wait || true
|
||||||
|
echo "All processes have been terminated"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
trap 'on_terminate' 15 2
|
setup_permissions() {
|
||||||
|
if [ "$(id -u)" = "0" ] && [ "$PUID" != "0" ]; then
|
||||||
|
echo "Setting up directory permissions..."
|
||||||
|
mkdir -p /.pm2
|
||||||
|
chown -R "${PUID}:${PGID}" /app /etc/nginx /var/lib/nginx /var/log/nginx /run/nginx.pid /etc/nginx/nginx.conf /.pm2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
java -jar -Djava.library.path=/app/tdlib /app/api.jar &
|
start_services() {
|
||||||
JAVA_PID=$!
|
cmd_prefix=""
|
||||||
|
if [ "$(id -u)" = "0" ] && [ "$PUID" != "0" ]; then
|
||||||
|
cmd_prefix="gosu ${PUID}:${PGID}"
|
||||||
|
fi
|
||||||
|
|
||||||
pm2 start /app/web/pm2.json --no-daemon --silent &
|
echo "Starting Java service..."
|
||||||
PM2_PID=$!
|
if [ -n "$cmd_prefix" ]; then
|
||||||
|
$cmd_prefix java -jar -Djava.library.path=/app/tdlib /app/api.jar &
|
||||||
|
else
|
||||||
|
java -jar -Djava.library.path=/app/tdlib /app/api.jar &
|
||||||
|
fi
|
||||||
|
JAVA_PID=$!
|
||||||
|
|
||||||
nginx -g 'daemon off;' &
|
echo "Starting PM2 service..."
|
||||||
NGINX_PID=$!
|
if [ -n "$cmd_prefix" ]; then
|
||||||
|
$cmd_prefix pm2 start /app/web/pm2.json --no-daemon --silent &
|
||||||
|
else
|
||||||
|
pm2 start /app/web/pm2.json --no-daemon --silent &
|
||||||
|
fi
|
||||||
|
PM2_PID=$!
|
||||||
|
|
||||||
|
echo "Starting Nginx service..."
|
||||||
|
if [ -n "$cmd_prefix" ]; then
|
||||||
|
$cmd_prefix nginx -g 'daemon off;' &
|
||||||
|
else
|
||||||
|
nginx -g 'daemon off;' &
|
||||||
|
fi
|
||||||
|
NGINX_PID=$!
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up signal handlers
|
||||||
|
trap cleanup TERM INT
|
||||||
|
|
||||||
|
# Set up permissions
|
||||||
|
setup_permissions
|
||||||
|
|
||||||
|
# Start services
|
||||||
|
start_services
|
||||||
|
|
||||||
|
# Wait for all services to complete
|
||||||
wait
|
wait
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue