diff --git a/infra/app/.terraform.lock.hcl b/infra/app/.terraform.lock.hcl index c1ad399..b78f386 100644 --- a/infra/app/.terraform.lock.hcl +++ b/infra/app/.terraform.lock.hcl @@ -1,28 +1,6 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. -provider "registry.terraform.io/cyrilgdn/postgresql" { - version = "1.22.0" - constraints = "1.22.0" - hashes = [ - "h1:zQQKupK4vbHP90ESdqSdVVAXvI+cS2g9lE6DlUJ38+s=", - "zh:038df91e31bda2a9a1f33adc886bc2084793e151130e29909b92f18b91315724", - "zh:093328afc09cf13a5aed64daf9dc32d764e0a2b3c626c532e211fc22c08088f3", - "zh:108ae8321312085037b987bbe0a4a8e8aa34a763b5b73ad6d9a78d605fa8074d", - "zh:2ef4ae45a8df16ad3e3b2c8082a605354c5ca34015b1709123a911a98f93320d", - "zh:35e13819840c74d8c01fabbe124b44718364acea905066c68fd7ee7d3b4ffc09", - "zh:4eee265e184067d7574787cb682d7f5e339271adc91ec0026de1ab9700f24e39", - "zh:5defd2ac1825d25897125b21c929827dcd471cff7ba8e92c6ae006830bc7bb8c", - "zh:8ef0f114516bd83d87667472f90e609b2c033431d5c9d563db5ca2b87bad9726", - "zh:97ee6cf040e34f649ddc0554dca7db132f6bddae5defe133f21dffa01ece33fe", - "zh:982a831ee1346ae7790ddb6efa8f34297964d68f2910a1ce401505ea96c4bffa", - "zh:a8aefc6c22ff2ffff69d269ba180fdf021ba8510fa3a00683f356f3434657a4a", - "zh:b153499f77d00fae59c6f7d301fd6ffc3595143d540ed475ccf2747bcc1920ac", - "zh:b27e28690c8ca74b861f7ffccd98ada374c8a2cb0e200dbc028c679c009b5779", - "zh:d05579c9998a3efa36b3397a840676edfc8328a6075110d7365ac322f5ce268c", - ] -} - provider "registry.terraform.io/hashicorp/google" { version = "5.32.0" constraints = ">= 4.50.0, 5.32.0, < 6.0.0" @@ -82,3 +60,25 @@ provider "registry.terraform.io/hashicorp/random" { "zh:fbef0781cb64de76b1df1ca11078aecba7800d82fd4a956302734999cfd9a4af", ] } + +provider "registry.terraform.io/kreuzwerker/docker" { + version = "3.0.2" + constraints = "3.0.2" + hashes = [ + "h1:cT2ccWOtlfKYBUE60/v2/4Q6Stk1KYTNnhxSck+VPlU=", + "zh:15b0a2b2b563d8d40f62f83057d91acb02cd0096f207488d8b4298a59203d64f", + "zh:23d919de139f7cd5ebfd2ff1b94e6d9913f0977fcfc2ca02e1573be53e269f95", + "zh:38081b3fe317c7e9555b2aaad325ad3fa516a886d2dfa8605ae6a809c1072138", + "zh:4a9c5065b178082f79ad8160243369c185214d874ff5048556d48d3edd03c4da", + "zh:5438ef6afe057945f28bce43d76c4401254073de01a774760169ac1058830ac2", + "zh:60b7fadc287166e5c9873dfe53a7976d98244979e0ab66428ea0dea1ebf33e06", + "zh:61c5ec1cb94e4c4a4fb1e4a24576d5f39a955f09afb17dab982de62b70a9bdd1", + "zh:a38fe9016ace5f911ab00c88e64b156ebbbbfb72a51a44da3c13d442cd214710", + "zh:c2c4d2b1fd9ebb291c57f524b3bf9d0994ff3e815c0cd9c9bcb87166dc687005", + "zh:d567bb8ce483ab2cf0602e07eae57027a1a53994aba470fa76095912a505533d", + "zh:e83bf05ab6a19dd8c43547ce9a8a511f8c331a124d11ac64687c764ab9d5a792", + "zh:e90c934b5cd65516fbcc454c89a150bfa726e7cf1fe749790c7480bbeb19d387", + "zh:f05f167d2eaf913045d8e7b88c13757e3cf595dd5cd333057fdafc7c4b7fed62", + "zh:fcc9c1cea5ce85e8bcb593862e699a881bd36dffd29e2e367f82d15368659c3d", + ] +} diff --git a/infra/app/docker.tf b/infra/app/docker.tf new file mode 100644 index 0000000..8aa25fc --- /dev/null +++ b/infra/app/docker.tf @@ -0,0 +1,33 @@ +locals { + docker_hostname = "${var.region}-docker.pkg.dev" + image_root = "${local.docker_hostname}/${var.project}/${var.project}" +} + +provider "docker" { + registry_auth { + address = local.docker_hostname + } +} + + +resource "docker_image" "app" { + for_each = var.app_versions + name = "${local.image_root}/${each.key}" + + build { + # The application's directory. + context = "${path.cwd}/../../${each.key}" + tag = ["${local.image_root}/${each.key}:${each.value}"] + } + + triggers = { + # Trigger a build if this value has changed. + version_tag = each.value + } +} + +resource "docker_registry_image" "app" { + for_each = docker_image.app + name = tolist(docker_image.app[each.key].build)[0].tag[0] + keep_remotely = true +} diff --git a/infra/app/main.tf b/infra/app/main.tf index cccb65a..17f0ea7 100644 --- a/infra/app/main.tf +++ b/infra/app/main.tf @@ -1,5 +1,9 @@ terraform { required_providers { + docker = { + source = "kreuzwerker/docker" + version = "3.0.2" + } google = { source = "hashicorp/google" version = "5.32.0" @@ -15,7 +19,6 @@ terraform { } } - provider "google" { project = var.project region = var.region @@ -29,10 +32,7 @@ data "google_client_config" "current" { } locals { - image_base = "${var.region}-docker.pkg.dev/${var.project}/${var.project}/" - client_tag = var.app_versions["client"] - voting_tag = var.app_versions["votingapi"] - storageapi_tag = var.app_versions["storageapi"] + storageapi_image = tolist(docker_image.app["storageapi"].build)[0].tag[0] } ################################################################ @@ -59,7 +59,7 @@ resource "google_cloud_run_v2_service" "storageapi" { } containers { - image = "${local.image_base}storageapi:${local.storageapi_tag}" + image = local.storageapi_image ports { container_port = 8000 diff --git a/infra/app/variables.tf b/infra/app/variables.tf index d419ccc..b3b7357 100644 --- a/infra/app/variables.tf +++ b/infra/app/variables.tf @@ -4,7 +4,7 @@ variable "app_versions" { client : "0.1.0", votingapi : "0.1.1", painterapi : "0.1.0", - storageapi : "0.0.0kmddbtestmigrate3", + storageapi : "0.0.1", } }