#!/bin/env fish begin set -l dir (status dirname) set -l source "$dir/docker-compose.templates.yml" source "$dir/../service.fish" set -l environments \ forgejo mydrone "" \ github drone "" 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 dockerTemplate (yq -oj (getServiceKey docker-template) "$source") set -l sshTemplate (yq -oj (getServiceKey ssh-template) "$source") initializeServiceInstallation $argv echo "{}" | sudo tee "$config" >/dev/null echo "{}" | sudo tee "$overrides" >/dev/null cp "$dir"/{ci.Dockerfile,docker-compose.core.yml,.dockerignore} "$root" echo "DRONE_JSONNET_ENABLED=true" | sudo tee "$root/server.common.env" >/dev/null echo "DRONE_RUNNER_CAPACITY=2" | sudo tee "$root/runner.common.env" >/dev/null 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 user $environments[(math $i + 3)] set -l secret (openssl rand -hex 16) set -l runners ssh docker set -l services ci $runners set -l tmpConfig (mktemp) set -l tmpOverrides (mktemp) set -l ciName "$name-ci" set -l sshName "$name-ssh-runner" set -l dockerName "$name-docker-runner" set -l ciEnv set -l sshEnv set -l dockerEnv cp "$config" "$tmpConfig" cp "$overrides" "$tmpOverrides" for serviceName in $services set -l file (mktemp) set -l nameVar "$serviceName""Name" set -l serviceKey ".services.[\"$$nameVar\"]" set "$serviceName""Key" "$serviceKey" set "$serviceName""Env" "$serviceKey.environment" end CI_NAME=$ciName \ SECRET_ENV="$name.secret.env" \ RUNNER_ENV="$name.runner.env" begin begin printf "%s\n" \ DRONE_RPC_PROTO=http \ "DRONE_RPC_HOST=$name-ci" end | sudo tee "$root/$RUNNER_ENV" >/dev/null echo "DRONE_RPC_SECRET=$secret" | sudo tee "$root/$SECRET_ENV" >/dev/null yq "$ciKey = $ciTemplate" "$tmpConfig" | ENTRY="./data/$name:/data" yq "$ciKey.volumes = [ env(ENTRY) ]" | yq "$ciKey.env_file |= . + [ env(SECRET_ENV) ]" | PROTO=https yq "$ciEnv.DRONE_SERVER_PROTO = env(PROTO)" | HOST=(getServiceDomain "$subdomain" "$domain") yq "$ciEnv.DRONE_SERVER_HOST = env(HOST)" | yq "$dockerKey = $dockerTemplate" | yq "$sshKey = $sshTemplate" | yq "$dockerKey.depends_on = [ env(CI_NAME) ]" | sudo tee "$config" >/dev/null for key in $dockerKey $sshKey set -l file (mktemp) yq "$key.depends_on = [ env(CI_NAME) ]" "$config" | yq "$key.env_file |= . + [ env(RUNNER_ENV), env(SECRET_ENV) ]" | tee "$file" >/dev/null sudo cp "$file" "$config" rm "$file" end PORT="127.0.0.1:1337:80" yq "$ciKey.ports = [ env(PORT) ]" "$tmpOverrides" | 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