public async Task <GameServerDeployment> CreateDeploymentAsync( string projectId, string deploymentId) { // Create the client. GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync(); GameServerDeployment deployment = new GameServerDeployment() { GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId) }; CreateGameServerDeploymentRequest request = new CreateGameServerDeploymentRequest { DeploymentId = deploymentId, ParentAsLocationName = LocationName.FromProjectLocation(projectId, "global"), GameServerDeployment = deployment }; // Make the request. Operation <GameServerDeployment, OperationMetadata> response = await client.CreateGameServerDeploymentAsync(request); // Poll until the returned long-running operation is complete. Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result. return(completedResponse.Result); }
/// <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; } }