jms-gitea/gcloud-version/entrypoint.sh
2026-06-13 11:23:36 +01:00

84 lines
2.4 KiB
Bash

#!/bin/bash
set -e
# Define standard storage paths inside our writeable volume
DB_PATH="/data/gitea/gitea.db"
CONF_DIR="/data/gitea/conf"
CONF_PATH="$CONF_DIR/app.ini"
# 1. Initialize writeable working directories safely
mkdir -p "$CONF_DIR"
mkdir -p /data/gitea/app_data/repositories # Ensure mount path target exists
# FIX: Only chown local assets. Explicitly avoid running a recursive chown on the GCS FUSE mount!
chown git:git /data /data/gitea /data/gitea/gitea.db /data/gitea/conf 2>/dev/null || true
# 2. Restore SQLite database if it exists in Cloud Storage
if [ ! -f "$DB_PATH" ]; then
echo "[Litestream] SQLite database not found locally. Checking GCS for replica..."
if litestream restore -config /etc/litestream.yml "$DB_PATH"; then
echo "[Litestream] Database successfully restored from GCS."
chown git:git "$DB_PATH"
else
echo "[Litestream] No backup replica found. Initializing new database."
fi
fi
# 3. Launch the Litestream background replication process
echo "[Litestream] Starting replication backend process..."
litestream replicate -config /etc/litestream.yml &
# 4. MANUALLY WRITE THE APP.INI CONFIG FILE (Explicit Block Overrides)
echo "[Gitea] Writing configuration profile to app.ini..."
cat <<EOF > "$CONF_PATH"
APP_NAME = Serverless Git
RUN_MODE = prod
RUN_USER = git
[database]
DB_TYPE = sqlite3
PATH = $DB_PATH
[security]
INSTALL_LOCK = true
[server]
HTTP_PORT = 3000
PROTOCOL = http
DOMAIN = gitea.jms.rocks
ROOT_URL = https://gitea.jms.rocks/
DISABLE_SSH = true
LIMIT_SIZE_REJECT_REQUEST = false
DISABLE_QUERY_STR_CHECK = true
[queue]
TYPE = level
[repository]
ROOT = /data/gitea/app_data/repositories
DISABLE_FORK_TIME_CHECK = true
MAX_CREATION_LIMIT = 0
[picture]
AVATAR_UPLOAD_PATH = /data/gitea/app_data/repositories/avatars
REPOSITORY_AVATAR_UPLOAD_PATH = /data/gitea/app_data/repositories/repo-avatars
[attachment]
STORAGE_TYPE = local
PATH = /data/gitea/app_data/repositories/attachments
[lfs]
STORAGE_TYPE = local
PATH = /data/gitea/app_data/repositories/lfs
[repo-archive]
STORAGE_TYPE = local
PATH = /data/gitea/app_data/repositories/repo-archive
EOF
# Ensure the config file is fully readable and writeable by the git user
chown git:git "$CONF_PATH"
# 5. Drop Root Privileges and boot the Gitea Web server pointing to our manual config
echo "[Gitea] Dropping privileges to 'git' user and booting web service core..."
exec su git -c "/app/gitea/gitea web --config $CONF_PATH --port 3000"