/// <summary> /// Starts a rollout /// </summary> /// <param name="projectId">Your Google Cloud Project Id</param> /// <param name="regionId">Region in which the cluster will be created</param> /// <param name="deploymentId">Deployment Id</param> /// <returns>Rollout name</returns> public string StartRollout( string projectId = "YOUR-PROJECT-ID", string regionId = "us-central1-f", string deploymentId = "YOUR-DEPLOYMENT-ID", string templateId = "YOUR-GAME-SERVER-TEMPLATE-ID") { // Initialize the client var client = GameServerDeploymentsServiceClient.Create(); // Construct the request string deploymentName = $"projects/{projectId}/locations/{regionId}/gameServerDeployments/{deploymentId}"; // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/ var container = new JObject(); container.Add("name", "default"); container.Add("image", "gcr.io/agones-images/default:1.0"); var containers = new JArray(); containers.Add(container); var spec = new JObject(); spec.Add("containers", containers); var template = new JObject(); template.Add("spec", spec); var port = new JObject(); port.Add("name", "default"); var ports = new JArray(); ports.Add(port); var specObject = new JObject(); specObject.Add("ports", ports); specObject.Add("template", template); var gameServerTemplate = new GameServerTemplate { TemplateId = templateId, Spec = specObject.ToString(), }; var startRolloutRequest = new StartRolloutRequest { Name = deploymentName, NewGameServerTemplate = gameServerTemplate }; // Call the API try { var result = client.StartRollout(startRolloutRequest); // Inspect the result return($"Deployment rollout started for {deploymentId}. Operation Id: {result.Name}"); } catch (Exception e) { Console.WriteLine($"StartRollout error:"); Console.WriteLine($"{e.Message}"); throw; } }
/// <summary> /// Creates a new game deployment /// </summary> /// <param name="projectId">Your Google Cloud Project Id</param> /// <param name="deploymentId">Deployment Id</param> public string CreateDeployment( string projectId = "YOUR-PROJECT-ID", string deploymentId = "YOUR-DEPLOYMENT-ID") { // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/ var container = new JObject(); container.Add("name", "default"); container.Add("image", "gcr.io/agones-images/default:1.0"); var containers = new JArray(); containers.Add(container); var spec = new JObject(); spec.Add("containers", containers); var template = new JObject(); template.Add("spec", spec); var port = new JObject(); port.Add("name", "default"); var ports = new JArray(); ports.Add(port); var specObject = new JObject(); specObject.Add("ports", ports); specObject.Add("template", template); // Initialize the client var client = GameServerDeploymentsServiceClient.Create(); // Construct the request string parent = $"projects/{projectId}/locations/global"; string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}"; var gameServerTemplate = new GameServerTemplate { Spec = specObject.ToString(), TemplateId = "default" }; var gameServerDeployment = new GameServerDeployment { Name = deploymentName, NewGameServerTemplate = gameServerTemplate, }; var request = new CreateGameServerDeploymentRequest { Parent = parent, DeploymentId = deploymentId, GameServerDeployment = gameServerDeployment, }; // Call the API try { var created = client.CreateGameServerDeployment(request); // Inspect the result return($"Game server deployment created for {deploymentId}. OperationId: {created.Name}"); } catch (Exception e) { Console.WriteLine($"CreateGameServerDeployment error:"); Console.WriteLine($"{e.Message}"); throw; } }