mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:53:00 +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,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
DB_PATH="./backend/data/pocket-id.db"
|
||||
# TODO: Should parse DB_CONNECTION_STRING
|
||||
DB_PATH="/app/data/pocket-id.db"
|
||||
DB_PROVIDER="${DB_PROVIDER:=sqlite}"
|
||||
|
||||
# Parse command-line arguments for the -d flag (database path)
|
||||
@@ -108,7 +109,7 @@ fi
|
||||
echo "================================================="
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "A one-time access token valid for 1 hour has been created for \"$USER_IDENTIFIER\"."
|
||||
echo "Use the following URL to sign in once: ${PUBLIC_APP_URL:=https://<your-pocket-id-domain>}/lc/$SECRET_TOKEN"
|
||||
echo "Use the following URL to sign in once: ${APP_URL:=https://<your-pocket-id-domain>}/lc/$SECRET_TOKEN"
|
||||
else
|
||||
echo "Error creating access token."
|
||||
exit 1
|
||||
|
||||
57
scripts/development/build-binaries.sh
Normal file
57
scripts/development/build-binaries.sh
Normal file
@@ -0,0 +1,57 @@
|
||||
set -eu
|
||||
cd backend
|
||||
mkdir -p .bin
|
||||
|
||||
# Function to build for a specific platform
|
||||
build_platform() {
|
||||
target=$1
|
||||
os=$2
|
||||
arch=$3
|
||||
arm_version=${4:-""}
|
||||
pocket_id_version=$(cat ../.version)
|
||||
|
||||
# Set the binary extension to exe for Windows
|
||||
binary_ext=""
|
||||
if [ "$os" = "windows" ]; then
|
||||
binary_ext=".exe"
|
||||
fi
|
||||
|
||||
output_dir=".bin/pocket-id-${target}${binary_ext}"
|
||||
|
||||
printf "Building %s/%s%s" "$os" "$arch" "$([ -n "$arm_version" ] && echo " GOARM=$arm_version" || echo "")... "
|
||||
|
||||
# Build environment variables
|
||||
env_vars="GOOS=${os} GOARCH=${arch}"
|
||||
if [ -n "$arm_version" ]; then
|
||||
env_vars="${env_vars} GOARM=${arm_version}"
|
||||
fi
|
||||
|
||||
# Build the binary
|
||||
eval "${env_vars} go build \
|
||||
-ldflags='-X github.com/pocket-id/pocket-id/backend/internal/common.Version=${pocket_id_version}' \
|
||||
-o \"${output_dir}\" \
|
||||
-trimpath \
|
||||
./cmd"
|
||||
|
||||
printf "Done\n"
|
||||
}
|
||||
|
||||
# linux builds
|
||||
build_platform "linux-amd64" "linux" "amd64" ""
|
||||
build_platform "linux-386" "linux" "386" ""
|
||||
build_platform "linux-arm64" "linux" "arm64" ""
|
||||
build_platform "linux-armv7" "linux" "arm" "7"
|
||||
|
||||
# macOS builds
|
||||
build_platform "macos-x64" "darwin" "amd64" ""
|
||||
build_platform "macos-arm64" "darwin" "arm64" ""
|
||||
|
||||
# Windows builds
|
||||
build_platform "windows-x64" "windows" "amd64" ""
|
||||
build_platform "windows-arm64" "windows" "arm64" ""
|
||||
|
||||
# FreeBSD builds
|
||||
build_platform "freebsd-amd64" "freebsd" "amd64" ""
|
||||
build_platform "freebsd-arm64" "freebsd" "arm64" ""
|
||||
|
||||
echo "Compilation done"
|
||||
@@ -112,7 +112,7 @@ fi
|
||||
|
||||
# Create the release on GitHub
|
||||
echo "Creating GitHub release..."
|
||||
gh release create "v$NEW_VERSION" --title "v$NEW_VERSION" --notes "$CHANGELOG"
|
||||
gh release create "v$NEW_VERSION" --title "v$NEW_VERSION" --notes "$CHANGELOG" --draft
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "GitHub release created successfully."
|
||||
|
||||
@@ -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