docker-compose environment for the entire v.st system https://v.st/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
env/gitea/setup

106 lines
2.7 KiB

#!/bin/bash
die() { echo >&2 "gitea: ERROR $*" ; exit 1 ; }
info() { echo >&2 "gitea: $*" ; }
DIRNAME="$(dirname $0)"
cd "$DIRNAME"
source ../env.production || die "no top level environment"
source ./env.production || die "no local environment"
DATA="../data/gitea"
SECRETS="$DATA/env.secrets"
INI="$DATA/gitea/conf/app.ini"
if [ -r "$SECRETS" ]; then
docker-compose up -d || die "unable to start"
exit 0
fi
GITEA_CLIENT_SECRET="$(openssl rand -hex 32)"
GITEA_ADMIN_PASSWORD="$(openssl rand -hex 8)"
info "creating new secrets $SECRETS"
mkdir -p "$DATA"
cat <<EOF > "$SECRETS"
# DO NOT CHECK IN
GITEA_CLIENT_SECRET=$GITEA_CLIENT_SECRET
GITEA_ADMIN_PASSWORD=$GITEA_ADMIN_PASSWORD
GITEA__server__ROOT_URL=https://$GITEA_HOSTNAME/
EOF
docker-compose down 2>/dev/null
../keycloak/client-delete gitea 2>/dev/null
../keycloak/client-create <<EOF || die "unable to create gitea client"
{
"clientId": "gitea",
"rootUrl": "https://$GITEA_HOSTNAME",
"adminUrl": "https://$GITEA_HOSTNAME",
"redirectUris": [ "https://$GITEA_HOSTNAME/*" ],
"webOrigins": [ "https://$GITEA_HOSTNAME" ],
"clientAuthenticatorType": "client-secret",
"secret": "$GITEA_CLIENT_SECRET"
}
EOF
docker-compose up -d || die "unable to start container"
info "waiting for startup..."
sleep 5
info "attempting to finish install"
curl "https://${GITEA_HOSTNAME}/" \
-X POST \
-f "db_type=postgres" \
-f "db_host=db:5432" \
-f "db_user=gitea" \
-f "db_passwd=gitea" \
-f "db_name=gitea" \
-f "ssl_mode=disable" \
-f "db_schema=" \
-f "charset=utf8" \
-f "db_path=/data/gitea/gitea.db" \
-f "app_name=${REALM} Gitea" \
-f "repo_root_path=/data/git/repositories" \
-f "lfs_root_path=/data/git/lfs" \
-f "run_user=git" \
-f "domain=${GITEA_HOSTNAME}" \
-f "ssh_port=22" \
-f "http_port=3000" \
-f "app_url=https://${GITEA_HOSTNAME}/" \
-f "log_root_path=/data/gitea/log" \
-f "smtp_host=" \
-f "smtp_from=" \
-f "smtp_user=" \
-f "smtp_passwd=" \
-f "enable_federated_avatar=on" \
-f "enable_open_id_sign_in=on" \
-f "allow_only_external_registration=on" \
-f "default_allow_create_organization=on" \
-f "default_enable_timetracking=on" \
-f "no_reply_address=noreply.${GITEA_HOSTNAME}" \
-f "password_algorithm=pbkdf2" \
-f "admin_name=root" \
-f "admin_passwd=${GITEA_ADMIN_PASSWORD}" \
-f "admin_confirm_passwd=${GITEA_ADMIN_PASSWORD}" \
-f "admin_email=" \
|| die "unable to initiate install"
sleep 10
info "adding oauth login"
docker-compose exec -u git gitea \
gitea admin auth add-oauth \
--name "keycloak" \
--provider "openidConnect" \
--key "gitea" \
--secret "$GITEA_CLIENT_SECRET" \
--auto-discover-url "https://${KEYCLOAK_HOSTNAME}/realms/${REALM}/.well-known/openid-configuration" \
--group-claim-name "groups" \
--admin-group "admin" \
|| die "unable to add oauth interface"