#!/bin/env fish begin set -l dir (status dirname) set -l source "$dir/docker-compose.templates.yml" source "$dir/../service.fish" set -l environments \ my ci "" \ codeberg bergwache "" \ github gh.ci "" function installSW -V dir -V environments -V source set -l root (getServiceRoot $argv) set -l config "$root/docker-compose.base.yml" set -l overrides (getServiceOverrides $argv) set -l ciTemplate (yq -oj (getServiceKey ci-template) "$source") set -l agentTemplate (yq -oj (getServiceKey agent-template) "$source") set -l dbTemplate (yq -oj (getServiceKey db-template) "$source") initializeServiceInstallation $argv echo "{}" | sudo tee "$config" >/dev/null echo "{}" | sudo tee "$overrides" >/dev/null cp "$dir/.dockerignore" "$root" sudo touch "$root"/{agent,ci}.common.env for i in (seq 1 3 (count $environments)) set -l name $environments[$i] set -l domain $environments[(math $i + 2)] set -l subdomain $environments[(math $i + 1)] set -l secret (openssl rand -hex 32) set -l services ci db agent set -l tmpConfig (mktemp) set -l tmpOverrides (mktemp) set -l ciName "$name-ci" set -l dbName "$name-db" set -l agentName "$name-agent" set -l ciEnv set -l dbEnv set -l agentEnv set -l ciKey set -l dbKey set -l agentKey set -l db Woodpecker set -l dbUser woodpecker set -l pw (nix-shell -p keepassxc --run "keepassxc-cli generate --length 32") set -l domain (getServiceDomain "$subdomain" "$domain") cp "$config" "$tmpConfig" cp "$overrides" "$tmpOverrides" for serviceName in $services set -l file (mktemp) set -l nameVar "$serviceName""Name" set -l serviceKey (getServiceKey "$$nameVar") set "$serviceName""Key" "$serviceKey" set "$serviceName""Env" "$serviceKey.environment" end CI_NAME=$ciName \ SECRET_ENV="$name.secret.env" begin begin echo "WOODPECKER_AGENT_SECRET=$secret" end | sudo tee "$root/$SECRET_ENV" >/dev/null yq "$ciKey = $ciTemplate" "$tmpConfig" | DB="$dbName" yq "$ciKey.depends_on |= . + [ env(DB) ]" | ENTRY="./data/$name/ci:/var/lib/woodpecker" yq "$ciKey.volumes = [ env(ENTRY) ]" | yq "$ciKey.env_file |= . + [ env(SECRET_ENV) ]" | yq "$agentKey = $agentTemplate" | yq "$agentKey.depends_on |= . + [ env(CI_NAME) ]" | yq "$agentKey.env_file |= . + [ env(SECRET_ENV) ]" | SERVER="$ciName:9000" yq "$agentEnv.WOODPECKER_SERVER = env(SERVER)" | yq "$dbKey = $dbTemplate" | ENTRY="./data/$name/db:/var/lib/mysql" yq "$dbKey.volumes |= . + [ env(ENTRY) ]" | sudo tee "$config" >/dev/null HOST="https://$domain" yq "$ciEnv.WOODPECKER_HOST = env(HOST)" "$tmpOverrides" | PORT="127.0.0.1:1337:8000" yq "$ciKey.ports = [ env(PORT) ]" | DB="$dbUser:$pw@tcp($dbName:3306)/$db?parseTime=true" yq "$ciEnv.WOODPECKER_DATABASE_DATASOURCE = env(DB)" | USER="$dbUser" yq "$dbEnv.MARIADB_USER = env(USER)" | PW="$pw" yq "$dbEnv.MARIADB_PASSWORD = env(PW)" | DB="$db" yq "$dbEnv.MARIADB_DATABASE = env(DB)" | sudo tee "$overrides" >/dev/null end end installDockerService $argv end function configureSW -V dir configureDockerService $argv end function getServiceServers -V environments argparse -i "name=" -- $argv set -l name "$_flag_name" for i in (seq 1 3 (count $environments)) set -l domain $environments[(math $i + 2)] set -l subdomain $environments[(math $i + 1)] printf "%s\0" "$subdomain" "$domain" end end function getServiceLocations -a index -V environments set -l i (math (math (math $index - 1) / 2 "*" 3) + 1) set -l name $environments[$i] printf "%s\0" "$name-ci" / end function getExtraBackupPatterns echo "\.secret\.env\$" end runInstaller --force $argv end