From e3a92bff29a3e82a12ef7d1da8ba4d800a50469b Mon Sep 17 00:00:00 2001 From: Dan Zaratsian Date: Tue, 7 Feb 2023 14:03:16 -0500 Subject: [PATCH] Initial code to deploy core open match (#31) * initial code to deploy core open match * Updated per suggestions and mapped to new folder structure * Updated README to include open match * Removed redundant namespace config --- README.md | 9 +++ .../deploy/open-match/base/kustomization.yaml | 16 ++++++ .../deploy/open-match/base/open-match.yaml | 4 ++ .../deploy/open-match/cloudbuild.yaml | 28 +++++++++ .../deploy/open-match/kustomization.yaml | 3 + .../deploy/open-match/skaffold.yaml | 9 +++ infrastructure/open-match-gke.tf | 42 ++++++++++++++ infrastructure/pipelines.tf | 57 +++++++++++++++++++ infrastructure/terraform.tfvars.sample | 8 +++ infrastructure/variables.tf | 10 ++++ 10 files changed, 186 insertions(+) create mode 100644 infrastructure/deploy/open-match/base/kustomization.yaml create mode 100644 infrastructure/deploy/open-match/base/open-match.yaml create mode 100644 infrastructure/deploy/open-match/cloudbuild.yaml create mode 100644 infrastructure/deploy/open-match/kustomization.yaml create mode 100644 infrastructure/deploy/open-match/skaffold.yaml create mode 100644 infrastructure/open-match-gke.tf diff --git a/README.md b/README.md index 3d29105..cc49040 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,15 @@ You can monitor the status of the deployment through the Cloud Logging URL retur nd as well as the Kubernetes Engine/Worloads panel in the GCP Console. Once the Worloads have been marked as O K, Agones should be avaialable. +#### Deploy Open Match to GKE Cluster + +Replace the` _RELEASE_NAME` substitution with a unique build name. Cloudbuild will deploy Open Match using Cloud Deploy. + +```shell +cd $GAME_DEMO_HOME/infrastructure/deploy/open-match +gcloud builds submit --config=cloudbuild.yaml --substitutions=_RELEASE_NAME=rel-1 +``` + ### Deploy Spanner Applications to GKE Cluster #### Initial Deploy diff --git a/infrastructure/deploy/open-match/base/kustomization.yaml b/infrastructure/deploy/open-match/base/kustomization.yaml new file mode 100644 index 0000000..9c04dd8 --- /dev/null +++ b/infrastructure/deploy/open-match/base/kustomization.yaml @@ -0,0 +1,16 @@ +# ./base/kustomization.yaml +helmCharts: +- name: open-match + repo: https://open-match.dev/chart/stable + version: 1.6.0 + releaseName: open-match + valuesInline: + open-match-override: + enabled: true + open-match-customize: + enabled: true + evaluator: + enabled: true + +resources: + - open-match.yaml diff --git a/infrastructure/deploy/open-match/base/open-match.yaml b/infrastructure/deploy/open-match/base/open-match.yaml new file mode 100644 index 0000000..0b48e9c --- /dev/null +++ b/infrastructure/deploy/open-match/base/open-match.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: open-match diff --git a/infrastructure/deploy/open-match/cloudbuild.yaml b/infrastructure/deploy/open-match/cloudbuild.yaml new file mode 100644 index 0000000..b7e3488 --- /dev/null +++ b/infrastructure/deploy/open-match/cloudbuild.yaml @@ -0,0 +1,28 @@ +# Copyright 2023 Google LLC All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +serviceAccount: projects/${PROJECT_ID}/serviceAccounts/cloudbuild-cicd@${PROJECT_ID}.iam.gserviceaccount.com +steps: + - name: gcr.io/google.com/cloudsdktool/cloud-sdk + entrypoint: gcloud + args: + [ + "deploy", "releases", "create", "${_RELEASE_NAME}", + "--delivery-pipeline", "global-game-open-match-deploy-pipeline", + "--region", "us-central1" + ] +substitutions: + _RELEASE_NAME: rel-0002 +options: + logging: CLOUD_LOGGING_ONLY diff --git a/infrastructure/deploy/open-match/kustomization.yaml b/infrastructure/deploy/open-match/kustomization.yaml new file mode 100644 index 0000000..3db2dab --- /dev/null +++ b/infrastructure/deploy/open-match/kustomization.yaml @@ -0,0 +1,3 @@ +# ./kustomization.yaml +resources: +- base diff --git a/infrastructure/deploy/open-match/skaffold.yaml b/infrastructure/deploy/open-match/skaffold.yaml new file mode 100644 index 0000000..e72282e --- /dev/null +++ b/infrastructure/deploy/open-match/skaffold.yaml @@ -0,0 +1,9 @@ +apiVersion: skaffold/v2beta29 +kind: Config +deploy: + kustomize: + paths: + - "." + buildArgs: ["--enable-helm"] + flags: + apply: ['--server-side'] diff --git a/infrastructure/open-match-gke.tf b/infrastructure/open-match-gke.tf new file mode 100644 index 0000000..4f67773 --- /dev/null +++ b/infrastructure/open-match-gke.tf @@ -0,0 +1,42 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +resource "google_container_cluster" "game-demo-open-match-gke" { + name = var.open-match_gke_config.cluster_name + location = var.open-match_gke_config.location + + network = google_compute_network.vpc.name + subnetwork = google_compute_subnetwork.subnet[var.open-match_gke_config.location].name + + # See issue: https://github.com/hashicorp/terraform-provider-google/issues/10782 + ip_allocation_policy {} + + # Enabling Autopilot for this cluster + enable_autopilot = true + + # Private IP Config + private_cluster_config { + enable_private_nodes = true + enable_private_endpoint = false + } + + depends_on = [google_compute_subnetwork.subnet, google_project_service.project] +} + +data "google_container_cluster" "game-demo-open-match-gke" { + name = var.open-match_gke_config.cluster_name + location = var.open-match_gke_config.location + + depends_on = [google_container_cluster.game-demo-open-match-gke] +} diff --git a/infrastructure/pipelines.tf b/infrastructure/pipelines.tf index 33bbaaf..054ce61 100644 --- a/infrastructure/pipelines.tf +++ b/infrastructure/pipelines.tf @@ -130,6 +130,63 @@ resource "google_clouddeploy_delivery_pipeline" "agones" { } } +##### Open Match Pipelines ##### + +resource "google_clouddeploy_target" "open-match-target" { + location = var.open-match_gke_config.location + name = "global-game-open-match-deploy-target" + + annotations = { + my_first_annotation = "open-match-annotation-1" + + my_second_annotation = "open-match-annotation-2" + } + + description = "Global Game: Open Match Deploy Target" + + gke { + cluster = data.google_container_cluster.game-demo-open-match-gke.id + } + + labels = { + my_first_label = "global-game-demo" + + my_second_label = "open-match" + } + + project = var.project + require_approval = false + + depends_on = [google_project_service.project] +} + +resource "google_clouddeploy_delivery_pipeline" "open-match" { + location = var.open-match_gke_config.location + name = "global-game-open-match-deploy-pipeline" + + annotations = { + my_first_annotation = "open-match-annotation-1" + + my_second_annotation = "open-match-annotation-2" + } + + description = "Global Game: Open Match Deploy Pipeline" + + labels = { + my_first_label = "global-game-demo" + + my_second_label = "open-match" + } + + project = var.project + + serial_pipeline { + stages { + target_id = google_clouddeploy_target.open-match-target.target_id + } + } +} + ##### Cloud Deploy IAM ##### resource "google_project_iam_member" "clouddeploy-container" { diff --git a/infrastructure/terraform.tfvars.sample b/infrastructure/terraform.tfvars.sample index d782ea3..0b0493e 100644 --- a/infrastructure/terraform.tfvars.sample +++ b/infrastructure/terraform.tfvars.sample @@ -84,6 +84,14 @@ spanner_gke_config = { } } +# Open Match GKE Config Values +open-match_gke_config = { + cluster_name = "global-game-gke-open-match" + location = "us-central1" + resource_labels = { + environment = "staging" + } +} # Agones Application Service Account Name app_service_account_config = { diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf index 89f3611..78a0740 100644 --- a/infrastructure/variables.tf +++ b/infrastructure/variables.tf @@ -67,6 +67,16 @@ variable "spanner_gke_config" { description = "Configuration specs for Spanner GKE Autopilot cluster" } +variable "open-match_gke_config" { + type = object({ + cluster_name = string + location = string + resource_labels = map(string) + }) + + description = "Configuration specs for Open Match GKE Autopilot cluster" +} + variable "app_service_account_config" { type = object({ name = string