refactor!: serve the static frontend trough the backend (#520)

Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
Elias Schneider
2025-05-17 00:36:58 +02:00
parent bf710aec56
commit f8a7467ec0
74 changed files with 773 additions and 819 deletions

View File

@@ -1,31 +0,0 @@
# If we aren't running as root, just exec the CMD
[ "$(id -u)" -ne 0 ] && exec "$@"
echo "Creating user and group..."
PUID=${PUID:-1000}
PGID=${PGID:-1000}
# Check if the group with PGID exists; if not, create it
if ! getent group pocket-id-group > /dev/null 2>&1; then
addgroup -g "$PGID" pocket-id-group
fi
# Check if a user with PUID exists; if not, create it
if ! id -u pocket-id > /dev/null 2>&1; then
if ! getent passwd "$PUID" > /dev/null 2>&1; then
adduser -u "$PUID" -G pocket-id-group pocket-id
else
# If a user with the PUID already exists, use that user
existing_user=$(getent passwd "$PUID" | cut -d: -f1)
echo "Using existing user: $existing_user"
fi
fi
# Change ownership of the /app directory
mkdir -p /app/backend/data
find /app/backend/data \( ! -group "${PGID}" -o ! -user "${PUID}" \) -exec chown "${PUID}:${PGID}" {} +
# Switch to the non-root user
exec su-exec "$PUID:$PGID" "$@"

View File

@@ -1,28 +1,38 @@
echo "Starting frontend..."
node frontend/build &
#!/bin/sh
echo "Starting backend..."
cd backend && ./pocket-id-backend &
# Ensure we are in the /app folder
cd /app
if [ "$CADDY_DISABLED" != "true" ]; then
echo "Starting Caddy..."
# https://caddyserver.com/docs/conventions#data-directory
export XDG_DATA_HOME=${XDG_DATA_HOME:-/app/backend/data/.local/share}
# https://caddyserver.com/docs/conventions#configuration-directory
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-/app/backend/data/.config}
# Check if TRUST_PROXY is set to true and use the appropriate Caddyfile
if [ "$TRUST_PROXY" = "true" ]; then
caddy run --adapter caddyfile --config /etc/caddy/Caddyfile.trust-proxy &
else
caddy run --adapter caddyfile --config /etc/caddy/Caddyfile &
fi
else
echo "Caddy is disabled. Skipping..."
# If we aren't running as root, just exec the CMD
if [ "$(id -u)" -ne 0 ] ; then
exec "$@"
exit 0
fi
# Set up trap to catch child process terminations
trap 'exit 1' SIGCHLD
PUID=${PUID:-1000}
PGID=${PGID:-1000}
wait
# Check if the group with PGID exists; if not, create it
if ! getent group pocket-id-group > /dev/null 2>&1; then
echo "Creating group $PGID..."
addgroup -g "$PGID" pocket-id-group
fi
# Check if a user with PUID exists; if not, create it
if ! id -u pocket-id > /dev/null 2>&1; then
if ! getent passwd "$PUID" > /dev/null 2>&1; then
echo "Creating user $PUID..."
adduser -u "$PUID" -G pocket-id-group pocket-id > /dev/null 2>&1
else
# If a user with the PUID already exists, use that user
existing_user=$(getent passwd "$PUID" | cut -d: -f1)
echo "Using existing user: $existing_user"
fi
fi
# Change ownership of the /app/data directory
mkdir -p /app/data
find /app/data \( ! -group "${PGID}" -o ! -user "${PUID}" \) -exec chown "${PUID}:${PGID}" {} +
# Switch to the non-root user
exec su-exec "$PUID:$PGID" "$@"