Skip to content

Commit

Permalink
Move Profile Service to Cloud Deploy Parameters (#236)
Browse files Browse the repository at this point in the history
Starting the work to move our Service Cloud Deploy configuration away
from files generated from Terraform, to using Cloud Deploy Parameters!

So the Teraform now stores the required information on the Cloud Deploy
Pipeline that needs to be used in Parameters - and Cloud Deploy handles
the rest! It's pretty straight forward, and requires minimal code
changes.

Included some other minor tweaks:
* Switch to use a script step.
* Formatted the cloud build script
* Needed to upgrade the Google Cloud Terraform module

More services coming!

Work on #181
markmandel authored Feb 21, 2024
1 parent 024dc0d commit ec767d1
Showing 8 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion infrastructure/game-server.tf
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ resource "google_secret_manager_secret" "secret_github_packages" {
}

replication {
automatic = true
auto {}
}
}

2 changes: 1 addition & 1 deletion infrastructure/main.tf
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.56.0"
version = "5.16.0"
}
}

8 changes: 8 additions & 0 deletions infrastructure/pipelines.tf
Original file line number Diff line number Diff line change
@@ -48,6 +48,14 @@ resource "google_clouddeploy_delivery_pipeline" "services_pipeline" {
serial_pipeline {
stages {
target_id = google_clouddeploy_target.services_deploy_target.target_id
deploy_parameters {
values = {
project = var.project
spanner_service_email = google_service_account.spanner-sa.email
spanner_instance_id = google_spanner_instance.global-game-spanner.name
spanner_database_id = google_spanner_database.spanner-database.name
}
}
}
}
}
12 changes: 0 additions & 12 deletions infrastructure/spanner.tf
Original file line number Diff line number Diff line change
@@ -65,15 +65,3 @@ resource "local_file" "liquibase-properties" {
})
filename = "${path.module}/${var.schema_directory}/liquibase.properties"
}

# Make Config file for deploy with Cloud Deploy
resource "local_file" "services-profile-config" {
content = templatefile(
"${path.module}/files/services/profile-service-config.yaml.tpl", {
service_email = google_service_account.spanner-sa.email
project_id = var.project
instance_id = google_spanner_instance.global-game-spanner.name
database_id = google_spanner_database.spanner-database.name
})
filename = "${path.module}/${var.services_directory}/profile/spanner_config.yaml"
}
54 changes: 26 additions & 28 deletions services/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -15,57 +15,55 @@
serviceAccount: projects/${PROJECT_ID}/serviceAccounts/cloudbuild-cicd@${PROJECT_ID}.iam.gserviceaccount.com
steps:

#
# Building of images
#
#
# Building of images
#

- name: gcr.io/cloud-builders/docker
id: ping-discovery
args: ["build", ".", "-t", "${_PING_IMAGE}"]
args: [ "build", ".", "-t", "${_PING_IMAGE}" ]
dir: ping-discovery
waitFor: ['-']
waitFor: [ '-' ]
- name: gcr.io/cloud-builders/docker
id: profile
args: ["build", ".", "-t", "${_PROFILE_IMAGE}"]
args: [ "build", ".", "-t", "${_PROFILE_IMAGE}" ]
dir: profile
waitFor: ['-']
waitFor: [ '-' ]
- name: gcr.io/cloud-builders/docker
id: frontend
args: ["build", ".", "-t", "${_FRONTEND_IMAGE}"]
args: [ "build", ".", "-t", "${_FRONTEND_IMAGE}" ]
dir: frontend
waitFor: ['-']
waitFor: [ '-' ]
- name: gcr.io/cloud-builders/docker
id: open-match-director
args: ["build", ".", "-t", "${_OPEN_MATCH_DIRECTOR_IMAGE}"]
args: [ "build", ".", "-t", "${_OPEN_MATCH_DIRECTOR_IMAGE}" ]
dir: open-match/director
waitFor: ['-']
waitFor: [ '-' ]
- name: gcr.io/cloud-builders/docker
id: open-match-matchfunction
args: ["build", ".", "-t", "${_OPEN_MATCH_MATCHFUNCTION_IMAGE}"]
args: [ "build", ".", "-t", "${_OPEN_MATCH_MATCHFUNCTION_IMAGE}" ]
dir: open-match/matchfunction
waitFor: ['-']
waitFor: [ '-' ]
- name: gcr.io/cloud-builders/docker
id: open-match-fake-frontend
args: ["build", ".", "-t", "${_OPEN_MATCH_FAKE_FRONTEND_IMAGE}"]
args: [ "build", ".", "-t", "${_OPEN_MATCH_FAKE_FRONTEND_IMAGE}" ]
dir: open-match/fake-frontend
waitFor: ['-']
waitFor: [ '-' ]

#
# Deployment
#
#
# Deployment
#

- name: gcr.io/google.com/cloudsdktool/cloud-sdk
id: cloud-deploy-release
entrypoint: bash
args:
- "-c"
- |
gcloud deploy releases create deploy-$(date +'%Y%m%d%H%M%S') \
--annotations=cloud_build=https://console.cloud.google.com/cloud-build/builds/${BUILD_ID} \
--delivery-pipeline global-game-services \
--skaffold-file skaffold.yaml \
--images ping-discovery=${_PING_IMAGE},profile=${_PROFILE_IMAGE},frontend=${_FRONTEND_IMAGE},open-match-director=${_OPEN_MATCH_DIRECTOR_IMAGE},open-match-matchfunction=${_OPEN_MATCH_MATCHFUNCTION_IMAGE},open-match-fake-frontend=${_OPEN_MATCH_FAKE_FRONTEND_IMAGE} \
--region us-central1
script: |
gcloud deploy releases create deploy-$(date +'%Y%m%d%H%M%S') \
--annotations=cloud_build=https://console.cloud.google.com/cloud-build/builds/$BUILD_ID \
--delivery-pipeline global-game-services \
--skaffold-file skaffold.yaml \
--images ping-discovery=$_PING_IMAGE,profile=$_PROFILE_IMAGE,frontend=$_FRONTEND_IMAGE,open-match-director=$_OPEN_MATCH_DIRECTOR_IMAGE,open-match-matchfunction=$_OPEN_MATCH_MATCHFUNCTION_IMAGE,open-match-fake-frontend=$_OPEN_MATCH_FAKE_FRONTEND_IMAGE \
--region us-central1
automapSubstitutions: true

artifacts:
images:
1 change: 0 additions & 1 deletion services/profile/.gitignore
Original file line number Diff line number Diff line change
@@ -16,4 +16,3 @@ config.yml
test_data/***
vendor/***
bin/***
spanner_config.yaml
10 changes: 5 additions & 5 deletions .../services/profile-service-config.yaml.tpl → services/profile/spanner-config.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Google LLC All Rights Reserved.
# Copyright 2024 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.
@@ -17,7 +17,7 @@ kind: ServiceAccount
metadata:
name: profile
annotations:
iam.gke.io/gcp-service-account: ${service_email}
iam.gke.io/gcp-service-account: spanner-sa@project.iam.gserviceaccount.com # from-param: ${spanner_service_email}

---

@@ -26,6 +26,6 @@ kind: ConfigMap
metadata:
name: spanner-config
data:
SPANNER_PROJECT_ID: ${project_id}
SPANNER_INSTANCE_ID: ${instance_id}
SPANNER_DATABASE_ID: ${database_id}
SPANNER_PROJECT_ID: "project" # from-param: ${project}
SPANNER_INSTANCE_ID: "instance_id" # from-param: ${spanner_instance_id}
SPANNER_DATABASE_ID: "database_id" # from-param: ${spanner_database_id}
2 changes: 1 addition & 1 deletion services/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ manifests:
rawYaml:
- ping-discovery/service-account.yaml
- ping-discovery/deployment.yaml
- profile/spanner_config.yaml
- profile/spanner-config.yaml
- profile/deployment.yaml
- frontend/config.yaml
- frontend/deployment.yaml

0 comments on commit ec767d1

Please sign in to comment.