The previous approach (custom CMD on gitea-app) failed because: - Gitea's entrypoint generates app.ini as root, then drops to git user - Overriding CMD ran our script before app.ini was generated - su-exec to git user lost access to the entrypoint-generated config Now uses the same pattern as nocodb-init: a separate container that depends on gitea-app being healthy, shares the gitea-data volume (which has app.ini), and runs gitea admin user create. Bunker Admin
45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# =============================================================================
|
|
# Gitea Admin User Initialization
|
|
# =============================================================================
|
|
# Runs as a separate init container (like nocodb-init) AFTER gitea-app is healthy.
|
|
# Shares the gitea-data volume so the app.ini config is available.
|
|
# Creates the admin user if it doesn't exist, then exits.
|
|
# =============================================================================
|
|
set -e
|
|
|
|
PREFIX="[gitea-init]"
|
|
log() { echo "$PREFIX $1"; }
|
|
|
|
# The gitea binary needs app.ini to know the database connection.
|
|
# On the Gitea Docker image, GITEA_CUSTOM defaults to /data/gitea
|
|
# and app.ini lives at /data/gitea/conf/app.ini (created by gitea-app's entrypoint).
|
|
export GITEA_CUSTOM="${GITEA_CUSTOM:-/data/gitea}"
|
|
|
|
if [ ! -f "$GITEA_CUSTOM/conf/app.ini" ]; then
|
|
log "ERROR: No app.ini found at $GITEA_CUSTOM/conf/app.ini"
|
|
log "This means gitea-app hasn't completed its first startup yet."
|
|
exit 1
|
|
fi
|
|
|
|
log "Found app.ini at $GITEA_CUSTOM/conf/app.ini"
|
|
|
|
if [ -z "$GITEA_ADMIN_USER" ] || [ -z "$GITEA_ADMIN_PASSWORD" ] || [ -z "$GITEA_ADMIN_EMAIL" ]; then
|
|
log "No GITEA_ADMIN_USER/PASSWORD/EMAIL set — skipping"
|
|
exit 0
|
|
fi
|
|
|
|
# Create admin user (idempotent — returns non-zero if user exists)
|
|
log "Creating admin user '${GITEA_ADMIN_USER}' (${GITEA_ADMIN_EMAIL})..."
|
|
if gitea admin user create --admin \
|
|
--username "$GITEA_ADMIN_USER" \
|
|
--password "$GITEA_ADMIN_PASSWORD" \
|
|
--email "$GITEA_ADMIN_EMAIL" \
|
|
--must-change-password false 2>&1; then
|
|
log "Admin user created successfully"
|
|
else
|
|
log "Admin user already exists (or creation skipped)"
|
|
fi
|
|
|
|
log "Done"
|