Skip to content

Commit

Permalink
Fix LiquidBase Schema Migration. (#136)
Browse files Browse the repository at this point in the history
* Fix LiquidBase Schema Migration.

* Removes Cloud Run Jobs, as things are far simpler without them.
* No longer need to push an image, since it can be utilised within the
  Cloud Build pipeline.
* Fixes permission issues in created image for copied files that were
  not able to read, since owned by root.
* Fixed pathing issue with changelog/changelog.yaml
* Cleaned up some API and IAM permissions we no longer need.

Ran through all the steps in README.md except the gameserver one, and
everything is working.

* * Review updates.
  • Loading branch information
markmandel authored Mar 10, 2023
1 parent c49dcee commit 801f410
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
8 changes: 4 additions & 4 deletions infrastructure/files/spanner/liquibase.properties.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

changeLogFile: /liquibase/changelog.yaml
url: jdbc:cloudspanner:/projects/${project_id}/instances/${instance_id}/databases/${database_id}
logLevel: 0
liquibase.hub.mode=off
changelogFile:changelog/changelog.yaml
url:jdbc:cloudspanner:/projects/${project_id}/instances/${instance_id}/databases/${database_id}
logLevel:fine
liquibase.hub.mode:off
liquibase.includeSystemClasspath:true
1 change: 0 additions & 1 deletion infrastructure/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ resource "google_project_iam_member" "cloudbuild-sa-cloudbuild-roles" {
"roles/container.admin",
"roles/storage.admin",
"roles/iam.serviceAccountUser",
"roles/run.developer",
"roles/spanner.databaseUser",
"roles/gkehub.editor"
])
Expand Down
9 changes: 5 additions & 4 deletions infrastructure/schema/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# limitations under the License.

FROM liquibase/liquibase:4.17
COPY liquibase.properties /liquibase/liquibase.properties
COPY changelog.yaml /liquibase/changelog.yaml
COPY lib/liquibase-spanner-*.jar /liquibase/lib/.

CMD ["liquibase", "update", "--defaultsFile=/liquibase/liquibase.properties"]
COPY --chown=liquibase:liquibase liquibase.properties /liquibase/liquibase.properties
COPY --chown=liquibase:liquibase changelog.yaml /liquibase/changelog/changelog.yaml
COPY --chown=liquibase:liquibase lib/liquibase-spanner-*.jar /liquibase/lib/.

CMD ["liquibase", "--defaults-file", "/liquibase/liquibase.properties", "update"]
45 changes: 13 additions & 32 deletions infrastructure/schema/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,27 @@
serviceAccount: projects/${PROJECT_ID}/serviceAccounts/cloudbuild-cicd@${PROJECT_ID}.iam.gserviceaccount.com
steps:

#
# Building of schema image
#
#
# Building of schema image
#

- name: gcr.io/cloud-builders/docker
id: schema image build
args: ["build", ".", "-t", "${_SCHEMA_IMAGE}"]
args: [ "build", ".", "-t", "${_SCHEMA_IMAGE}" ]

- name: gcr.io/cloud-builders/docker
id: schema image push
args: ["push", "${_SCHEMA_IMAGE}"]

#
# Create schema job
#
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:slim"
id: schema migrate create
entrypoint: gcloud
args: ["beta", "run", "jobs", "create", "${_RUN_JOB}",
"--image", "${_SCHEMA_IMAGE}", "--region", "${_REGION}"]
#
# Running migration
#

#
# Running schema migration
#
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:slim"
- name: "${_SCHEMA_IMAGE}"
id: schema migrate execute
entrypoint: gcloud
args: ["beta", "run", "jobs", "execute", "${_RUN_JOB}",
"--region", "${_REGION}", "--wait"]

# artifacts:
# images:
# - ${_REGISTRY}/schema
dir: /liquibase
substitutions:
_SCHEMA_IMAGE: ${_REGISTRY}/schema:${BUILD_ID}
_RUN_JOB: migrate-database-${BUILD_ID}
_SCHEMA_IMAGE: ${_REGISTRY}/schema-migration:${BUILD_ID}
_REGISTRY: us-docker.pkg.dev/${PROJECT_ID}/global-game-images
_REGION: us-central1

artifacts:
images:
- ${_SCHEMA_IMAGE}
options:
dynamic_substitutions: true
machineType: E2_HIGHCPU_8
logging: CLOUD_LOGGING_ONLY
6 changes: 3 additions & 3 deletions infrastructure/spanner.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ resource "google_project_iam_member" "spanner-sa" {
resource "local_file" "liquibase-properties" {
content = templatefile(
"${path.module}/files/spanner/liquibase.properties.tpl", {
project_id = var.project
instance_id = google_spanner_instance.global-game-spanner.name
database_id = google_spanner_database.spanner-database.name
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.schema_directory}/liquibase.properties"
}
Expand Down
2 changes: 0 additions & 2 deletions infrastructure/terraform.tfvars.sample
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ gcp_project_services = [
"secretmanager.googleapis.com",
"servicenetworking.googleapis.com",
"servicecontrol.googleapis.com",
"run.googleapis.com",
"orgpolicy.googleapis.com",
"redis.googleapis.com",
"run.googleapis.com",
"iap.googleapis.com"
]

Expand Down
2 changes: 1 addition & 1 deletion platform/open-match/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ deploy:
- "./base"
buildArgs: ["--enable-helm"]
flags:
apply: ['--server-side'] # Avoid the "Too long: must have at most 262144 bytes" problem
apply: ['--server-side', '--force-conflicts'] # Avoid the "Too long: must have at most 262144 bytes" problem

0 comments on commit 801f410

Please sign in to comment.