Skip to content

Commit

Permalink
Adjust docker compose for interactive console (#4096)
Browse files Browse the repository at this point in the history
* Adjust docker compose for interactive console

Made adjustments to setup to allow for interactive console to work by default

use `docker container attach --sig-proxy=false ace-server`

or

`docker attach --sig-proxy=false ace-server`

to access ace console in docker

* Update docker-compose.yml

* Update docker-compose.arm64

* Update Dockerfile

* Update Dockerfile.arm64

* Update docker.env

* Update Program_Setup.cs
  • Loading branch information
LtRipley36706 authored Feb 1, 2024
1 parent ee0f118 commit 7ad9775
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ENTRYPOINT ["dotnet", "ACE.Server.dll"]

# ports and volumes
EXPOSE 9000-9001/udp
VOLUME /ace/Config /ace/Content /ace/Dats /ace/Logs
VOLUME /ace/Config /ace/Content /ace/Dats /ace/Logs /ace/Mods

# health check
HEALTHCHECK --start-period=5m --interval=1m --timeout=3s \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ENTRYPOINT ["dotnet", "./ACE.Server.dll"]

# ports and volumes
EXPOSE 9000-9001/udp
VOLUME /ace/Config /ace/Content /ace/Dats /ace/Logs
VOLUME /ace/Config /ace/Content /ace/Dats /ace/Logs /ace/Mods

# health check
HEALTHCHECK --start-period=5m --interval=1m --timeout=3s \
Expand Down
175 changes: 138 additions & 37 deletions Source/ACE.Server/Program_Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,17 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();
Console.WriteLine();

var variable = string.Empty;
var nonInteractiveSetup = Convert.ToBoolean(Environment.GetEnvironmentVariable("ACE_NONINTERACTIVE_SETUP"));

Console.Write($"Enter the name for your World (default: \"{config.Server.WorldName}\"): ");
var variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_WORLD_NAME");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_WORLD_NAME");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.Server.WorldName = variable.Trim();
Console.WriteLine();
Expand All @@ -61,13 +69,25 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();
Console.WriteLine();
Console.Write($"Enter the Host address for your World (default: \"{config.Server.Network.Host}\"): ");
variable = Console.ReadLine();
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = "0.0.0.0";
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.Server.Network.Host = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the Port for your World (default: \"{config.Server.Network.Port}\"): ");
variable = Console.ReadLine();
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = "9000";
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.Server.Network.Port = Convert.ToUInt32(variable.Trim());
Console.WriteLine();
Expand All @@ -76,8 +96,13 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();

Console.Write($"Enter the directory location for your DAT files (default: \"{config.Server.DatFilesDirectory}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_DAT_FILES_DIRECTORY");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_DAT_FILES_DIRECTORY");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
{
var path = Path.GetFullPath(variable.Trim());
Expand All @@ -99,31 +124,51 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();

Console.Write($"Enter the database name for your authentication database (default: \"{config.MySql.Authentication.Database}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_NAME");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_NAME");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Authentication.Database = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the database name for your shard database (default: \"{config.MySql.Shard.Database}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_NAME");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_NAME");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Shard.Database = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the database name for your world database (default: \"{config.MySql.World.Database}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_NAME");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_NAME");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.World.Database = variable.Trim();
Console.WriteLine();

Console.WriteLine();
Console.WriteLine();
Console.Write("Typically, all three databases will be on the same SQL server, is this how you want to proceed? (Y/n) ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = "n";
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = "n";
Console.WriteLine($"{variable}");
}
if (!variable.Equals("n", StringComparison.OrdinalIgnoreCase) && !variable.Equals("no", StringComparison.OrdinalIgnoreCase))
{
Console.Write($"Enter the Host address for your SQL server (default: \"{config.MySql.World.Host}\"): ");
Expand All @@ -149,43 +194,73 @@ private static void DoOutOfBoxSetup(string configFile)
else
{
Console.Write($"Enter the Host address for your authentication database (default: \"{config.MySql.Authentication.Host}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_HOST");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_HOST");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Authentication.Host = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the Port for your authentication database (default: \"{config.MySql.Authentication.Port}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_PORT");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_AUTH_DATABASE_PORT");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Authentication.Port = Convert.ToUInt32(variable.Trim());
Console.WriteLine();

Console.Write($"Enter the Host address for your shard database (default: \"{config.MySql.Shard.Host}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_HOST");
if (!IsRunningInContainer)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_HOST");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Shard.Host = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the Port for your shard database (default: \"{config.MySql.Shard.Port}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_PORT");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_SHARD_DATABASE_PORT");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.Shard.Port = Convert.ToUInt32(variable.Trim());
Console.WriteLine();

Console.Write($"Enter the Host address for your world database (default: \"{config.MySql.World.Host}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_HOST");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_HOST");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.World.Host = variable.Trim();
Console.WriteLine();

Console.Write($"Enter the Port for your world database (default: \"{config.MySql.World.Port}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_PORT");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("ACE_SQL_WORLD_DATABASE_PORT");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
config.MySql.World.Port = Convert.ToUInt32(variable.Trim());
Console.WriteLine();
Expand All @@ -194,13 +269,23 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();
Console.WriteLine();
Console.Write("Typically, all three databases will be on the using the same SQL server credentials, is this how you want to proceed? (Y/n) ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = "y";
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = "y";
Console.WriteLine($"{variable}");
}
if (!variable.Equals("n", StringComparison.OrdinalIgnoreCase) && !variable.Equals("no", StringComparison.OrdinalIgnoreCase))
{
Console.Write($"Enter the username for your SQL server (default: \"{config.MySql.World.Username}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("MYSQL_USER");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("MYSQL_USER");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
{
config.MySql.Authentication.Username = variable.Trim();
Expand All @@ -210,8 +295,13 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();

Console.Write($"Enter the password for your SQL server (default: \"{config.MySql.World.Password}\"): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Environment.GetEnvironmentVariable("MYSQL_PASSWORD");
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Environment.GetEnvironmentVariable("MYSQL_PASSWORD");
Console.WriteLine($"{variable}");
}
if (!string.IsNullOrWhiteSpace(variable))
{
config.MySql.Authentication.Password = variable.Trim();
Expand Down Expand Up @@ -268,10 +358,15 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();
Console.WriteLine();
Console.Write("Do you want to ACEmulator to attempt to initialize your SQL databases? This will erase any existing ACEmulator specific databases that may already exist on the server (Y/n): ");
variable = Console.ReadLine();
if (!nonInteractiveSetup)
variable = Console.ReadLine();
var sqlConnectInfo = $"server={config.MySql.World.Host};port={config.MySql.World.Port};user={config.MySql.World.Username};password={config.MySql.World.Password};{config.MySql.World.ConnectionOptions}";
var sqlConnect = new MySqlConnector.MySqlConnection(sqlConnectInfo);
if (IsRunningInContainer) variable = Convert.ToBoolean(Environment.GetEnvironmentVariable("ACE_SQL_INITIALIZE_DATABASES")) ? "y" : "n";
if (nonInteractiveSetup)
{
variable = Convert.ToBoolean(Environment.GetEnvironmentVariable("ACE_SQL_INITIALIZE_DATABASES")) ? "y" : "n";
Console.WriteLine($"{variable}");
}
if (!variable.Equals("n", StringComparison.OrdinalIgnoreCase) && !variable.Equals("no", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine();
Expand Down Expand Up @@ -299,8 +394,9 @@ private static void DoOutOfBoxSetup(string configFile)

if (IsRunningInContainer)
{
// if using our supplied docker compose file which includes mysql server, mysql is initialized with a test database called ace%, we will delete this database if it exists
Console.Write("Clearing out temporary ace% database .... ");
var sqlDBFile = "DROP DATABASE `ace%`;";
var sqlDBFile = "DROP DATABASE IF EXISTS `ace%`;";
var script = new MySqlConnector.MySqlCommand(sqlDBFile, sqlConnect);

Console.Write($"Importing into SQL server at {config.MySql.World.Host}:{config.MySql.World.Port} .... ");
Expand Down Expand Up @@ -365,8 +461,13 @@ private static void DoOutOfBoxSetup(string configFile)
Console.WriteLine();
Console.WriteLine();
Console.Write("Do you want to download the latest world database and import it? (Y/n): ");
variable = Console.ReadLine();
if (IsRunningInContainer) variable = Convert.ToBoolean(Environment.GetEnvironmentVariable("ACE_SQL_DOWNLOAD_LATEST_WORLD_RELEASE")) ? "y" : "n";
if (!nonInteractiveSetup)
variable = Console.ReadLine();
else
{
variable = Convert.ToBoolean(Environment.GetEnvironmentVariable("ACE_SQL_DOWNLOAD_LATEST_WORLD_RELEASE")) ? "y" : "n";
Console.WriteLine($"{variable}");
}
if (!variable.Equals("n", StringComparison.OrdinalIgnoreCase) && !variable.Equals("no", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine();
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ services:
- ./Content:/ace/Content
- ./Dats:/ace/Dats
- ./Logs:/ace/Logs
- ./Mods:/ace/Mods
ports:
- "9000-9001:9000-9001/udp"
stdin_open: true
#restart: unless-stopped
restart: on-failure
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ services:
- ./Content:/ace/Content
- ./Dats:/ace/Dats
- ./Logs:/ace/Logs
- ./Mods:/ace/Mods
ports:
- "9000-9001:9000-9001/udp"
stdin_open: true
#restart: unless-stopped
restart: on-failure

3 changes: 2 additions & 1 deletion docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ ACE_SQL_WORLD_DATABASE_PORT=3306
ACE_SQL_INITIALIZE_DATABASES=true
ACE_SQL_DOWNLOAD_LATEST_WORLD_RELEASE=true

ACE_NONINTERACTIVE_CONSOLE=true
#ACE_NONINTERACTIVE_CONSOLE=true
ACE_NONINTERACTIVE_SETUP=true

0 comments on commit 7ad9775

Please sign in to comment.