diff --git a/Assets/Mirror/Hosting/Edgegap/Dependencies.meta b/Assets/Mirror/Hosting/Edgegap/Dependencies.meta index 1a9b91853..dfdcb461e 100644 --- a/Assets/Mirror/Hosting/Edgegap/Dependencies.meta +++ b/Assets/Mirror/Hosting/Edgegap/Dependencies.meta @@ -1,3 +1,8 @@ fileFormatVersion: 2 guid: 14024ce6d2e64d5ba58ab20409ac648f -timeCreated: 1701785018 \ No newline at end of file +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile b/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile new file mode 100644 index 000000000..3d9e3d02d --- /dev/null +++ b/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +COPY Builds/EdgegapServer /root/build/ + +WORKDIR /root/ + +RUN chmod +x /root/build/ServerBuild + +RUN apt-get update && \ + apt-get install -y ca-certificates && \ + apt-get clean && \ + update-ca-certificates + +ENTRYPOINT [ "/root/build/ServerBuild", "-batchmode", "-nographics"] diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile.meta b/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile.meta new file mode 100644 index 000000000..17273d76b --- /dev/null +++ b/Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 74f140c827788b64ebde10a2197d3c0b +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapBuildUtils.cs b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapBuildUtils.cs index 777e833be..e5e9e9aa5 100755 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapBuildUtils.cs +++ b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapBuildUtils.cs @@ -43,11 +43,11 @@ public static BuildReport BuildServer() return BuildPipeline.BuildPlayer(options); } - public static async Task DockerSetupAndInstallationCheck() + public static async Task DockerSetupAndInstallationCheck(string path) { - if (!File.Exists("Dockerfile")) + if (!File.Exists(path)) { - File.WriteAllText("Dockerfile", dockerFileText); + throw new Exception("Dockerfile not found, please notify plugin maintainer about this issue."); } string output = null; @@ -77,7 +77,7 @@ static async Task RunCommand_DockerVersion(Action outputReciever = null, } // MIRROR CHANGE - public static async Task RunCommand_DockerBuild(string registry, string imageRepo, string tag, Action onStatusUpdate) + public static async Task RunCommand_DockerBuild(string dockerfilePath, string registry, string imageRepo, string tag, string projectPath, Action onStatusUpdate) { string realErrorMessage = null; @@ -89,11 +89,11 @@ public static async Task RunCommand_DockerBuild(string registry, string imageRep string buildCommand = IsArmCPU() ? "buildx build --platform linux/amd64" : "build"; #if UNITY_EDITOR_WIN - await RunCommand("docker.exe", $"{buildCommand} -t {registry}/{imageRepo}:{tag} .", onStatusUpdate, + await RunCommand("docker.exe", $"{buildCommand} -f \"{dockerfilePath}\" -t \"{registry}/{imageRepo}:{tag}\" \"{projectPath}\"", onStatusUpdate, #elif UNITY_EDITOR_OSX - await RunCommand("/bin/bash", $"-c \"docker {buildCommand} -t {registry}/{imageRepo}:{tag} .\"", onStatusUpdate, + await RunCommand("/bin/bash", $"-c \"docker {buildCommand} -f {dockerfilePath} -t {registry}/{imageRepo}:{tag} {projectPath}\"", onStatusUpdate, #elif UNITY_EDITOR_LINUX - await RunCommand("/bin/bash", $"-c \"docker {buildCommand} -t {registry}/{imageRepo}:{tag} .\"", onStatusUpdate, + await RunCommand("/bin/bash", $"-c \"docker {buildCommand} -f {dockerfilePath} -t {registry}/{imageRepo}:{tag} {projectPath}\"", onStatusUpdate, #endif (msg) => { @@ -220,25 +220,6 @@ public static void UpdateEdgegapAppTag(string tag) // throw new NotImplementedException(); } - // -batchmode -nographics remains for Unity 2019/2020 support pre-dedicated server builds - static string dockerFileText = @"FROM ubuntu:bionic - -ARG DEBIAN_FRONTEND=noninteractive - -COPY Builds/EdgegapServer /root/build/ - -WORKDIR /root/ - -RUN chmod +x /root/build/ServerBuild - -RUN apt-get update && \ - apt-get install -y ca-certificates && \ - apt-get clean && \ - update-ca-certificates - -ENTRYPOINT [ ""/root/build/ServerBuild"", ""-batchmode"", ""-nographics""] -"; - /// Run a Docker cmd with streaming log response. TODO: Plugin to other Docker cmds /// Throws if logs contain "ERROR" /// diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs deleted file mode 100755 index 4c329b243..000000000 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs +++ /dev/null @@ -1,27 +0,0 @@ -#if UNITY_EDITOR -using UnityEditor; -using UnityEngine.UIElements; -using Edgegap; - -[CustomEditor(typeof(EdgegapToolScript))] -public class EdgegapPluginScriptEditor : Editor -{ - VisualElement _serverDataContainer; - - private void OnEnable() - { - _serverDataContainer = EdgegapServerDataManager.GetServerDataVisualTree(); - EdgegapServerDataManager.RegisterServerDataContainer(_serverDataContainer); - } - - private void OnDisable() - { - EdgegapServerDataManager.DeregisterServerDataContainer(_serverDataContainer); - } - - public override VisualElement CreateInspectorGUI() - { - return _serverDataContainer; - } -} -#endif \ No newline at end of file diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs.meta b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs.meta deleted file mode 100755 index 60f708f6b..000000000 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapScriptEditor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c4c676ae6dcca0e458c6a8f06571f8fc -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapServerDataManager.cs b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapServerDataManager.cs index b4dc287dd..ffadc91f1 100755 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapServerDataManager.cs +++ b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapServerDataManager.cs @@ -4,6 +4,7 @@ using UnityEditor; using UnityEngine; using UnityEngine.UIElements; +using System.IO; namespace Edgegap { @@ -88,10 +89,15 @@ public static class EdgegapServerDataManager public static Status GetServerStatus() => _serverData; +#if UNITY_EDITOR + internal static string StylesheetPath => + Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets($"t:Script {nameof(EdgegapServerDataManager)}")[0])); +#endif + static EdgegapServerDataManager() { #if UNITY_EDITOR - _serverDataStylesheet = AssetDatabase.LoadAssetAtPath("Assets/Edgegap/Editor/EdgegapServerData.uss"); + _serverDataStylesheet = AssetDatabase.LoadAssetAtPath($"{StylesheetPath}{Path.DirectorySeparatorChar}EdgegapServerData.uss"); #endif } public static void RegisterServerDataContainer(VisualElement serverDataContainer) diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs deleted file mode 100755 index 870190d23..000000000 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine; -using Edgegap; -using IO.Swagger.Model; - -/// -/// This script acts as an interface to display and use the necessary variables from the Edgegap tool. -/// The server info can be accessed from the tool window, as well as through the public script property. -/// -public class EdgegapToolScript : MonoBehaviour -{ - public Status ServerStatus => EdgegapServerDataManager.GetServerStatus(); -} diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs.meta b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs.meta deleted file mode 100755 index d584893d2..000000000 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapToolScript.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5963202433da25448a22def99f5a598b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapWindow.cs b/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapWindow.cs deleted file mode 100755 index c85723347..000000000 --- a/Assets/Mirror/Hosting/Edgegap/Editor/EdgegapWindow.cs +++ /dev/null @@ -1,988 +0,0 @@ -// MIRROR CHANGE: disable this completely. otherwise InitUIElements can still throw NRE. -/* -#if UNITY_EDITOR -using UnityEditor; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEditor.UIElements; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Collections.Generic; -using Newtonsoft.Json; -using System.Net; -using System.Text; -using System; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using IO.Swagger.Model; -using UnityEditor.Build.Reporting; -using Application = UnityEngine.Application; - -namespace Edgegap -{ - public class EdgegapWindow : EditorWindow - { - // MIRROR CHANGE: create HTTPClient in-place to avoid InvalidOperationExceptions when reusing - // static readonly HttpClient _httpClient = new HttpClient(); - // END MIRROR CHANGE - - const string EditorDataSerializationName = "EdgegapSerializationData"; - const int ServerStatusCronjobIntervalMs = 10000; // Interval at which the server status is updated - - // MIRROR CHANGE - // get the path of this .cs file so we don't need to hardcode paths to - // the .uxml and .uss files: - // https://forum.unity.com/threads/too-many-hard-coded-paths-in-the-templates-and-documentation.728138/ - // this way users can move this folder without breaking UIToolkit paths. - internal string StylesheetPath => - Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this))); - // END MIRROR CHANGE - - readonly System.Timers.Timer _updateServerStatusCronjob = new System.Timers.Timer(ServerStatusCronjobIntervalMs); - - [SerializeField] string _userExternalIp; - [SerializeField] string _apiKey; - [SerializeField] ApiEnvironment _apiEnvironment; - [SerializeField] string _appName; - [SerializeField] string _appVersionName; - [SerializeField] string _deploymentRequestId; - - [SerializeField] string _containerRegistry; - [SerializeField] string _containerImageRepo; - [SerializeField] string _containerImageTag; - [SerializeField] bool _autoIncrementTag = true; - - - VisualTreeAsset _visualTree; - bool _shouldUpdateServerStatus = false; - - // Interactable elements - EnumField _apiEnvironmentSelect; - TextField _apiKeyInput; - TextField _appNameInput; - TextField _appVersionNameInput; - TextField _containerRegistryInput; - TextField _containerImageRepoInput; - TextField _containerImageTagInput; - Toggle _autoIncrementTagInput; - Button _connectionButton; - Button _serverActionButton; - Button _documentationBtn; - Button _buildAndPushServerBtn; - - // Readonly elements - Label _connectionStatusLabel; - VisualElement _serverDataContainer; - - // server data manager - StyleSheet _serverDataStylesheet; - List _serverDataContainers = new List(); - - [Obsolete("See EdgegapWindowV2.ShowEdgegapToolWindow()")] - // [MenuItem("Edgegap/Server Management")] - public static void ShowEdgegapToolWindow() - { - EdgegapWindow window = GetWindow(); - window.titleContent = new GUIContent("Edgegap Hosting"); // MIRROR CHANGE - } - - protected void OnEnable() - { - // Set root VisualElement and style - // BEGIN MIRROR CHANGE - _visualTree = AssetDatabase.LoadAssetAtPath($"{StylesheetPath}/EdgegapWindow.uxml"); - StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath($"{StylesheetPath}/EdgegapWindow.uss"); - _serverDataStylesheet = AssetDatabase.LoadAssetAtPath($"{StylesheetPath}/EdgegapServerData.uss"); - // END MIRROR CHANGE - rootVisualElement.styleSheets.Add(styleSheet); - - LoadToolData(); - - if (string.IsNullOrWhiteSpace(_userExternalIp)) - { - _userExternalIp = GetExternalIpAddress(); - } - } - - protected void Update() - { - if (_shouldUpdateServerStatus) - { - _shouldUpdateServerStatus = false; - UpdateServerStatus(); - } - } - - public void CreateGUI() - { - rootVisualElement.Clear(); - _visualTree.CloneTree(rootVisualElement); - - InitUIElements(); - SyncFormWithObject(); - - bool hasActiveDeployment = !string.IsNullOrEmpty(_deploymentRequestId); - - if (hasActiveDeployment) - { - RestoreActiveDeployment(); - } - else - { - DisconnectCallback(); - } - } - - protected void OnDestroy() - { - bool deploymentActive = !string.IsNullOrEmpty(_deploymentRequestId); - - if (deploymentActive) - { - EditorUtility.DisplayDialog( - "Warning", - $"You have an active deployment ({_deploymentRequestId}) that won't be stopped automatically.", - "Ok" - ); - } - } - - protected void OnDisable() - { - SyncObjectWithForm(); - SaveToolData(); - DeregisterServerDataContainer(_serverDataContainer); - } - - /// - /// Binds the form inputs to the associated variables and initializes the inputs as required. - /// Requires the VisualElements to be loaded before this call. Otherwise, the elements cannot be found. - /// - void InitUIElements() - { - _apiEnvironmentSelect = rootVisualElement.Q("environmentSelect"); - _apiKeyInput = rootVisualElement.Q("apiKey"); - _appNameInput = rootVisualElement.Q("appName"); - _appVersionNameInput = rootVisualElement.Q("appVersionName"); - - _containerRegistryInput = rootVisualElement.Q("containerRegistry"); - _containerImageRepoInput = rootVisualElement.Q("containerImageRepo"); - _containerImageTagInput = rootVisualElement.Q("tag"); - _autoIncrementTagInput = rootVisualElement.Q("autoIncrementTag"); - - _connectionButton = rootVisualElement.Q