tools tools tools!
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# THIS SHOULD NOT BE USED TO CREATE THE PRODUCTION BUILD IT'S FOR DEBUGGING ONLY
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
ENTRYPOINT ["dotnet", "run"]
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# REPO MAINTAINERS: KEEP CHANGES TO THIS IN SYNC WITH /tools/tgs4_scripts/PreCompile.sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
#load dep exports
|
||||
#need to switch to game dir for Dockerfile weirdness
|
||||
original_dir=$PWD
|
||||
cd "$1"
|
||||
. dependencies.sh
|
||||
cd "$original_dir"
|
||||
|
||||
#find out what we have (+e is important for this)
|
||||
set +e
|
||||
has_git="$(command -v git)"
|
||||
has_cargo="$(command -v ~/.cargo/bin/cargo)"
|
||||
has_sudo="$(command -v sudo)"
|
||||
has_grep="$(command -v grep)"
|
||||
DATABASE_EXISTS="$(mysqlshow --host mariadb --port 3306 --user=root --password=$MYSQL_ROOT_PASSWORD ss13_db| grep -v Wildcard | grep -o ss13_db)"
|
||||
set -e
|
||||
|
||||
# install cargo if needful
|
||||
if ! [ -x "$has_cargo" ]; then
|
||||
echo "Installing rust..."
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-host i686-unknown-linux-gnu
|
||||
. ~/.profile
|
||||
fi
|
||||
|
||||
# apt packages, libssl needed by rust-g but not included in TGS barebones install
|
||||
if ! { [ -x "$has_git" ] && [ -x "$has_grep" ] && [ -f "/usr/lib/i386-linux-gnu/libssl.so" ] && [ -f "/usr/bin/mysql" ] && [ -d "/usr/include/mysql" ]; }; then
|
||||
echo "Installing apt dependencies..."
|
||||
if ! [ -x "$has_sudo" ]; then
|
||||
dpkg --add-architecture i386
|
||||
apt-get update
|
||||
apt-get install -y git libssl-dev:i386 grep mysql-client
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
else
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git libssl-dev:i386 grep mysql-client
|
||||
sudo rm -rf /var/lib/apt/lists/*
|
||||
fi
|
||||
fi
|
||||
|
||||
#update rust-g
|
||||
if [ ! -d "rust-g" ]; then
|
||||
echo "Cloning rust-g..."
|
||||
git clone https://github.com/tgstation/rust-g
|
||||
else
|
||||
echo "Fetching rust-g..."
|
||||
cd rust-g
|
||||
git fetch
|
||||
cd ..
|
||||
fi
|
||||
|
||||
echo "Deploying rust-g..."
|
||||
cd rust-g
|
||||
git checkout "$RUST_G_VERSION"
|
||||
~/.cargo/bin/cargo build --release
|
||||
mv target/release/librust_g.so "$1/rust_g"
|
||||
cd ..
|
||||
|
||||
if [ ! -d "../GameStaticFiles/config" ]; then
|
||||
echo "Creating initial config..."
|
||||
cp -r "$1/config" "../GameStaticFiles/config"
|
||||
echo -e "SQL_ENABLED\nFEEDBACK_TABLEPREFIX SS13_\nADDRESS mariadb\nPORT 3306\nFEEDBACK_DATABASE ss13_db\nFEEDBACK_LOGIN root\nFEEDBACK_PASSWORD $MYSQL_ROOT_PASSWORD\nASYNC_QUERY_TIMEOUT 10\nBLOCKING_QUERY_TIMEOUT 5\nBSQL_THREAD_LIMIT 50" > "../GameStaticFiles/config/dbconfig.txt"
|
||||
echo "$TGS_ADMIN_CKEY = Host" > "../GameStaticFiles/config/admins.txt"
|
||||
fi
|
||||
|
||||
if [ "$DATABASE_EXISTS" != "ss13_db" ]; then
|
||||
echo "Creating initial SS13 database..."
|
||||
mysql -u root --password=$MYSQL_ROOT_PASSWORD -h mariadb -P 3306 -e 'CREATE DATABASE IF NOT EXISTS ss13_db;'
|
||||
cat "$1/$TGS_PREFIXED_SCHEMA_FILE"
|
||||
mysql -u root --password=$MYSQL_ROOT_PASSWORD -h mariadb -P 3306 ss13_db < "$1/$TGS_PREFIXED_SCHEMA_FILE"
|
||||
mysql -u root --password=$MYSQL_ROOT_PASSWORD -h mariadb -P 3306 ss13_db -e "INSERT INTO \`SS13_schema_revision\` (\`major\`, \`minor\`) VALUES ($TGS_SCHEMA_MAJOR_VERSION, $TGS_SCHEMA_MINOR_VERSION)"
|
||||
fi
|
||||
@@ -0,0 +1,208 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Client;
|
||||
using Tgstation.Server.Client.Components;
|
||||
|
||||
namespace SetupProgram
|
||||
{
|
||||
class Program
|
||||
{
|
||||
public static async Task<int> Main()
|
||||
{
|
||||
var repo = Environment.GetEnvironmentVariable("TGS_REPO")?.Trim();
|
||||
if (String.IsNullOrWhiteSpace(repo))
|
||||
{
|
||||
Console.WriteLine("ERROR: Environment variable TGS_REPO not set to a git url!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var byondStr = Environment.GetEnvironmentVariable("TGS_BYOND")?.Trim();
|
||||
if (String.IsNullOrWhiteSpace(byondStr) || !Version.TryParse(byondStr, out Version byond) || byond.Build != -1)
|
||||
{
|
||||
Console.WriteLine("ERROR: Environment variable TGS_BYOND not set to a valid BYOND version!");
|
||||
return 2;
|
||||
}
|
||||
|
||||
var clientFactory = new ServerClientFactory(new ProductHeaderValue("LinuxOneShot", "1.0.0"));
|
||||
|
||||
IServerClient serverClient = null;
|
||||
Instance instance = null;
|
||||
IInstanceClient instanceClient;
|
||||
void CreateInstanceClient() => instanceClient = serverClient.Instances.CreateClient(instance);
|
||||
|
||||
async Task CreateAdminClient()
|
||||
{
|
||||
Console.WriteLine("Attempting to reestablish connection to TGS (120s max wait)...");
|
||||
var giveUpAt = DateTimeOffset.Now.AddSeconds(60);
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
serverClient = await clientFactory.CreateServerClient(new Uri("http://tgs:80"), User.AdminName, User.DefaultAdminPassword, default, default);
|
||||
if (instance != null)
|
||||
CreateInstanceClient();
|
||||
break;
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
//migrating, to be expected
|
||||
if (DateTimeOffset.Now > giveUpAt)
|
||||
throw;
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
catch (ServiceUnavailableException)
|
||||
{
|
||||
// migrating, to be expected
|
||||
if (DateTimeOffset.Now > giveUpAt)
|
||||
throw;
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
async Task WaitForJob(Job originalJob, CancellationToken cancellationToken)
|
||||
{
|
||||
var job = originalJob;
|
||||
int? lastProgress = null;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
|
||||
job = await instanceClient.Jobs.GetId(job, cancellationToken).ConfigureAwait(false);
|
||||
if (job.Progress != lastProgress)
|
||||
{
|
||||
Console.WriteLine($"Progress: {job.Progress}");
|
||||
lastProgress = job.Progress;
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedException)
|
||||
{
|
||||
await CreateAdminClient();
|
||||
}
|
||||
}
|
||||
while (!job.StoppedAt.HasValue);
|
||||
|
||||
if (job.ExceptionDetails != null)
|
||||
{
|
||||
Console.WriteLine(job.ExceptionDetails);
|
||||
Environment.Exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
await CreateAdminClient();
|
||||
|
||||
Console.WriteLine("Listing instances...");
|
||||
var instances = await serverClient.Instances.List(default);
|
||||
if (instances.Any())
|
||||
{
|
||||
Console.WriteLine("One or more instances already exist, aborting!");
|
||||
return 3;
|
||||
}
|
||||
|
||||
Console.WriteLine("Creating instance...");
|
||||
instance = await serverClient.Instances.CreateOrAttach(new Instance
|
||||
{
|
||||
ConfigurationType = ConfigurationType.HostWrite,
|
||||
Name = "AutoInstance",
|
||||
Path = "/tgs4_instances/main"
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Onlining instance...");
|
||||
instance.Online = true;
|
||||
instance = await serverClient.Instances.Update(instance, default);
|
||||
|
||||
CreateInstanceClient();
|
||||
|
||||
Console.WriteLine("Starting repo clone...");
|
||||
var cloneJobTask = instanceClient.Repository.Clone(new Repository
|
||||
{
|
||||
Origin = repo
|
||||
}, default);
|
||||
|
||||
Console.WriteLine($"Starting BYOND install {byond}...");
|
||||
var byondInstallTask = instanceClient.Byond.SetActiveVersion(new Byond
|
||||
{
|
||||
Version = byond
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Setting DD Settings to Ultrasafe|Startup Timeout=120|AutoStart=true|HeartbeatSeconds=120...");
|
||||
var ddUpdateTask = instanceClient.DreamDaemon.Update(new DreamDaemon
|
||||
{
|
||||
AutoStart = true,
|
||||
SecurityLevel = DreamDaemonSecurity.Ultrasafe,
|
||||
HeartbeatSeconds = 120,
|
||||
StartupTimeout = 120
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Setting API validation security level to trusted...");
|
||||
var dmUpdateTask = instanceClient.DreamMaker.Update(new DreamMaker
|
||||
{
|
||||
ApiValidationSecurityLevel = DreamDaemonSecurity.Trusted
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Uploading EventScripts/PreCompile.sh...");
|
||||
var configurationTask = instanceClient.Configuration.Write(new ConfigurationFile
|
||||
{
|
||||
Path = "/EventScripts/PreCompile.sh",
|
||||
Content = File.ReadAllBytes("PreCompile.sh")
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Creating GameStaticFiles/data...");
|
||||
var configTask2 = instanceClient.Configuration.CreateDirectory(new ConfigurationFile
|
||||
{
|
||||
IsDirectory = true,
|
||||
Path = "/GameStaticFiles/data"
|
||||
}, default);
|
||||
|
||||
Console.WriteLine("Waiting for previous requests...");
|
||||
|
||||
await Task.WhenAll(
|
||||
cloneJobTask,
|
||||
byondInstallTask,
|
||||
ddUpdateTask,
|
||||
dmUpdateTask,
|
||||
configurationTask,
|
||||
configTask2);
|
||||
|
||||
Console.WriteLine("Waiting for BYOND install...");
|
||||
|
||||
var installJob = await byondInstallTask;
|
||||
await WaitForJob(installJob.InstallJob, default);
|
||||
|
||||
Console.WriteLine("Waiting for Repo clone...");
|
||||
|
||||
var cloneJob = await cloneJobTask;
|
||||
await WaitForJob(cloneJob.ActiveJob, default);
|
||||
|
||||
await CreateAdminClient();
|
||||
|
||||
Console.WriteLine("Starting deployment...");
|
||||
var deployJobTask = instanceClient.DreamMaker.Compile(default);
|
||||
|
||||
Console.WriteLine("Enabling auto updates every hour...");
|
||||
instance.AutoUpdateInterval = 60;
|
||||
await serverClient.Instances.Update(instance, default);
|
||||
|
||||
Console.WriteLine("Waiting for deployment job...");
|
||||
var deployJob = await deployJobTask;
|
||||
await WaitForJob(deployJob, default);
|
||||
|
||||
await CreateAdminClient();
|
||||
|
||||
Console.WriteLine("Launching watchdog...");
|
||||
var launchJob = await instanceClient.DreamDaemon.Start(default);
|
||||
await WaitForJob(launchJob, default);
|
||||
|
||||
Console.WriteLine("Complete!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Tgstation.Server.Client" Version="6.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user