mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-24 09:15:05 +03:00
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:
@@ -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" "$@"
|
||||
@@ -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" "$@"
|
||||
|
||||
Reference in New Issue
Block a user