From a712701ec977d19a2520204d32debd73de1a2c7e Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Mon, 26 Aug 2024 17:53:55 +0000 Subject: [PATCH] chore: get deploys working (#48) --- Assets/Examples/LobbiesServers/Scripts/UI.cs | 14 +++++--- .../Native/librivet_toolchain_ffi.dylib | 4 +-- .../librivet_toolchain_ffi_macos_arm64.dylib | 4 +-- Assets/Rivet/Editor/PluginSettings.cs | 35 ++++++++++++++++++- Assets/Rivet/Editor/Task.cs | 3 +- .../Editor/UI/Screens/LoginController.cs | 11 ------ .../Rivet/Editor/UI/Screens/MainController.cs | 10 +++--- .../Rivet/Editor/UI/Tabs/DeployController.cs | 9 ++--- .../Editor/UI/TaskPopup/TaskPopupWindow.cs | 4 +-- Dockerfile | 5 ++- backend.json | 13 +++++-- 11 files changed, 74 insertions(+), 38 deletions(-) diff --git a/Assets/Examples/LobbiesServers/Scripts/UI.cs b/Assets/Examples/LobbiesServers/Scripts/UI.cs index 0992ddf..0a12120 100644 --- a/Assets/Examples/LobbiesServers/Scripts/UI.cs +++ b/Assets/Examples/LobbiesServers/Scripts/UI.cs @@ -33,11 +33,15 @@ private BackendClient TEMPBackendClient() return new BackendClient(config.BackendEndpoint); } + private string TEMPRegion() + { + return "atl"; + } + private string TEMPGameVersion() { - // var config = new Configuration(); - // return config.GameVersion; - return "default"; + var config = new Configuration(); + return config.GameVersion; } private void Start() @@ -69,14 +73,14 @@ public async void OnClick_Find() var response = await TEMPBackendClient().Lobbies.FindOrCreate(new Backend.Model.Lobbies.FindOrCreateRequest( varVersion: TEMPGameVersion(), - regions: new List { "local" }, + regions: new List { TEMPRegion() }, tags: new Dictionary { // ["gameMode"] = gameMode, }, players: new List { new() }, createConfig: new Backend.Model.Lobbies.FindOrCreateRequestCreateConfig( - region: "local", + region: TEMPRegion(), tags: new Dictionary { }, maxPlayers: 32, maxPlayersDirect: 32 diff --git a/Assets/Rivet/Editor/Native/librivet_toolchain_ffi.dylib b/Assets/Rivet/Editor/Native/librivet_toolchain_ffi.dylib index 57981e6..b393072 100755 --- a/Assets/Rivet/Editor/Native/librivet_toolchain_ffi.dylib +++ b/Assets/Rivet/Editor/Native/librivet_toolchain_ffi.dylib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a49fdb86f7fe904b24377dc97af07368aa11d822a8eb288049bd42f1d1ca55e -size 24526896 +oid sha256:0789eb2e1f75dba3b212b5cee1e4632a520bb0ea3500fd5d73120063d1055f00 +size 24814704 diff --git a/Assets/Rivet/Editor/Native/librivet_toolchain_ffi_macos_arm64.dylib b/Assets/Rivet/Editor/Native/librivet_toolchain_ffi_macos_arm64.dylib index 57dcff8..b393072 100755 --- a/Assets/Rivet/Editor/Native/librivet_toolchain_ffi_macos_arm64.dylib +++ b/Assets/Rivet/Editor/Native/librivet_toolchain_ffi_macos_arm64.dylib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63a9bbb69e641c52ffa9c30bb8e759791daba0baa1987718c3935e53fc3790e6 -size 8379161 +oid sha256:0789eb2e1f75dba3b212b5cee1e4632a520bb0ea3500fd5d73120063d1055f00 +size 24814704 diff --git a/Assets/Rivet/Editor/PluginSettings.cs b/Assets/Rivet/Editor/PluginSettings.cs index 02b4dc0..8dd82a2 100644 --- a/Assets/Rivet/Editor/PluginSettings.cs +++ b/Assets/Rivet/Editor/PluginSettings.cs @@ -3,6 +3,7 @@ using UnityEngine; using UnityEditor; using Rivet.Editor.UI; +using Rivet.UI.Screens; namespace Rivet.Editor { @@ -70,6 +71,38 @@ private static void SaveSettings() } // MARK: Settings + [SerializeField] + private EnvironmentType environmentType = EnvironmentType.Local; + + public static EnvironmentType EnvironmentType + { + get { return Settings != null ? Settings.environmentType : EnvironmentType.Local; } + set + { + if (Settings != null) + { + Settings.environmentType = value; + SaveSettings(); + } + } + } + + [SerializeField] + private string? remoteEnvironmentId; + + public static string? RemoteEnvironmentId + { + get { return Settings?.remoteEnvironmentId; } + set + { + if (Settings != null) + { + Settings.remoteEnvironmentId = value; + SaveSettings(); + } + } + } + [SerializeField] private bool enableDebugLogs = false; @@ -78,7 +111,7 @@ public static bool EnableDebugLogs get { return Settings != null && Settings.enableDebugLogs; } } - + // TODO: Remove this with cleaner impl [SerializeField] private int tempBackendLocalPort = 6420; diff --git a/Assets/Rivet/Editor/Task.cs b/Assets/Rivet/Editor/Task.cs index 0f515f4..5a151da 100644 --- a/Assets/Rivet/Editor/Task.cs +++ b/Assets/Rivet/Editor/Task.cs @@ -161,7 +161,8 @@ private Result RunTask(string name, JObject input, JObject runConfig) public static string GetRivetCLIPath() { // TODO: Update this path as needed - return "/Users/nathan/rivet/cli/target/debug/rivet-cli"; + // return "/Users/nathan/rivet/cli/target/debug/rivet-cli"; + return "/Users/nathan/rivet/cli/target/debug/rivet"; } // private static Result RunRivetCLI(params string[] args) diff --git a/Assets/Rivet/Editor/UI/Screens/LoginController.cs b/Assets/Rivet/Editor/UI/Screens/LoginController.cs index e739582..bb97f1f 100644 --- a/Assets/Rivet/Editor/UI/Screens/LoginController.cs +++ b/Assets/Rivet/Editor/UI/Screens/LoginController.cs @@ -55,10 +55,6 @@ private async Task CheckLoginState() { _pluginWindow.SetScreen(Editor.UI.Screen.Main); } - else - { - SetLoginButtonEnabled(true); - } break; } @@ -66,9 +62,6 @@ private async Task CheckLoginState() private async Task SignIn() { - // Disable the button sign in button - SetLoginButtonEnabled(false); - // Get link token var getLinkResult = await new RivetTask( "start_device_link", @@ -92,7 +85,6 @@ private async Task SignIn() break; case ResultErr err: - SetLoginButtonEnabled(true); return; default: throw new System.Exception("unreachable"); @@ -114,12 +106,9 @@ private async Task SignIn() _pluginWindow.SetScreen(Editor.UI.Screen.Main); break; case ResultErr err: - SetLoginButtonEnabled(true); return; } } - - void SetLoginButtonEnabled(bool enabled) => _root.Q(name: "SignIn").SetEnabled(enabled); } } \ No newline at end of file diff --git a/Assets/Rivet/Editor/UI/Screens/MainController.cs b/Assets/Rivet/Editor/UI/Screens/MainController.cs index e4f3221..4cffcf0 100644 --- a/Assets/Rivet/Editor/UI/Screens/MainController.cs +++ b/Assets/Rivet/Editor/UI/Screens/MainController.cs @@ -55,19 +55,17 @@ public class MainController private SettingsController _settingsController; // MARK: Environment - private EnvironmentType _environmentType = EnvironmentType.Local; public EnvironmentType EnvironmentType { - get { return _environmentType; } + get { return PluginSettings.EnvironmentType; } set { - _environmentType = value; + PluginSettings.EnvironmentType = value; SharedSettings.UpdateFromPlugin(); } } - private string? _remoteEnvironmentId; public string? RemoteEnvironmentId { - get { return _remoteEnvironmentId; } + get { return PluginSettings.RemoteEnvironmentId; } set { - _remoteEnvironmentId = value; + PluginSettings.RemoteEnvironmentId = value; SharedSettings.UpdateFromPlugin(); } } diff --git a/Assets/Rivet/Editor/UI/Tabs/DeployController.cs b/Assets/Rivet/Editor/UI/Tabs/DeployController.cs index 6dc8808..15d930e 100644 --- a/Assets/Rivet/Editor/UI/Tabs/DeployController.cs +++ b/Assets/Rivet/Editor/UI/Tabs/DeployController.cs @@ -113,7 +113,7 @@ private void OnBuildAndDeploy() // Run deploy with CLI using TaskPopupWindow var task = TaskPopupWindow.RunTask("Build & Deploy", "deploy", new JObject { - ["cwd"] = serverPath != null ? Path.GetDirectoryName(serverPath) : Builder.ProjectRoot(), + ["cwd"] = Builder.ProjectRoot(), ["environment_id"] = environmentId, ["game_server"] = deployGameServer, ["backend"] = deployBackend, @@ -124,10 +124,11 @@ private void OnBuildAndDeploy() { if (output is ResultOk ok) { - var version = ok.Data["version"]?.ToString(); - if (!string.IsNullOrEmpty(version)) + var gameServerObj = ok.Data["game_server"]; + if (gameServerObj != null && gameServerObj.Type == JTokenType.Object) { - RivetPlugin.Singleton.GameVersion = ok.Data["version"].ToString(); + var version = gameServerObj["version_name"]?.ToString(); + RivetPlugin.Singleton.GameVersion = version; SharedSettings.UpdateFromPlugin(); Debug.Log($"New game version: {RivetPlugin.Singleton.GameVersion}"); } diff --git a/Assets/Rivet/Editor/UI/TaskPopup/TaskPopupWindow.cs b/Assets/Rivet/Editor/UI/TaskPopup/TaskPopupWindow.cs index be54909..126b3ab 100644 --- a/Assets/Rivet/Editor/UI/TaskPopup/TaskPopupWindow.cs +++ b/Assets/Rivet/Editor/UI/TaskPopup/TaskPopupWindow.cs @@ -119,7 +119,7 @@ private async void InitializeAndStartTask() try { var output = await _task.RunAsync(); - OnTaskCompleted(output); + EditorApplication.delayCall += () => OnTaskCompleted(output); } catch (Exception ex) { @@ -136,7 +136,6 @@ private void UpdateUI() private void OnTaskCompleted(Result output) { - OnTaskOutput.Invoke(output); switch (output) { case ResultOk ok: @@ -146,6 +145,7 @@ private void OnTaskCompleted(Result output) AddLogLine(err.Message, LogType.STDERR); break; } + OnTaskOutput.Invoke(output); UpdateUI(); } diff --git a/Dockerfile b/Dockerfile index 6e2bfb6..5a049e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,9 @@ WORKDIR /app ARG BUILD_PATH=./Builds/Release/DedicatedServer/Linux_x86_64/ ARG BINARY_NAME=DedicatedServer +# Pass BINARY_NAME to env so we can use it in the entrypoint +ENV BINARY_NAME=${BINARY_NAME} + # Install necessary libraries for Unity RUN apt-get update && apt-get install -y \ ca-certificates \ @@ -17,4 +20,4 @@ COPY ${BUILD_PATH} /app RUN ls /app && chmod +x /app/${BINARY_NAME} USER rivet -ENTRYPOINT ["/app/${BINARY_NAME}", "-server", "-batchmode", "-nographics"] +ENTRYPOINT "/app/${BINARY_NAME}" "-server" "-batchmode" "-nographics" diff --git a/backend.json b/backend.json index 10f53d3..1295359 100644 --- a/backend.json +++ b/backend.json @@ -1,4 +1,11 @@ { + "runtime": { + "cors": { + "origins": [ + "http://localhost:8080" + ] + } + }, "registries": { "default": { "local": { @@ -27,12 +34,12 @@ "ports": { "game": { "protocol": "udp", - "serverPort": 7777 + "internalPort": 7777 } }, "resources": { - "cpu": 1000, - "memory": 1000 + "cpu": 250, + "memory": 250 } } }