Skip to content

Commit ef9fac5

Browse files
authored
Merge pull request #5 from sanspace/feat/release-infra
work in progress for private release
2 parents 85af3b2 + 0c2b03e commit ef9fac5

9 files changed

Lines changed: 50 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local/
1010

1111
# Terraform state and providers
1212
/.terraform/
13+
.terraform/
1314

1415
# Ignore all content inside environments directories...
1516
**/environments/*

deploy.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@
1515

1616
set -e
1717

18+
# --- Argument Parsing ---
19+
TARGET_VERSION="latest"
20+
while [[ "$#" -gt 0 ]]; do
21+
case $1 in
22+
-v|--version) TARGET_VERSION="$2"; shift ;;
23+
*) warn "Unknown parameter: $1"; echo "Usage: ./deploy.sh [--version v1.2.0]"; exit 1 ;;
24+
esac
25+
shift
26+
done
27+
28+
info "Target Release Version: ${C_YELLOW}${TARGET_VERSION}${C_RESET}"
29+
1830
# --- Configuration ---
19-
REQUIRED_TERRAFORM_VERSION="1.15.1"
31+
REQUIRED_TERRAFORM_VERSION="1.15.5"
2032
UPSTREAM_REPO_URL="https://github.com/GoogleCloudPlatform/gcc-creative-studio"
2133
TEMPLATE_ENV_DIR="environments/example"
2234
DEFAULT_ENV_NAME="dev"
@@ -312,6 +324,13 @@ configure_environment() {
312324
info "Configuring terraform.tfvars..."
313325
sed -i.bak "s|^[#[:space:]]*project_id[[:space:]]*=.*|project_id = \"$GCP_PROJECT_ID\"|g" "$TFVARS_FILE_PATH"
314326
sed -i.bak "s|^[#[:space:]]*environment[[:space:]]*=.*|environment = \"$ENV_NAME\"|g" "$TFVARS_FILE_PATH"
327+
328+
# Ensure the target version is passed to Terraform
329+
if grep -q "app_version" "$TFVARS_FILE_PATH"; then
330+
sed -i.bak "s|^[#[:space:]]*app_version[[:space:]]*=.*|app_version = \"$TARGET_VERSION\"|g" "$TFVARS_FILE_PATH" && rm -f "${TFVARS_FILE_PATH}.bak"
331+
else
332+
echo -e "\napp_version = \"$TARGET_VERSION\"" >> "$TFVARS_FILE_PATH"
333+
fi
315334

316335
prompt_and_update_tfvar "Region to deploy resources into" "us-central1" "region" "DEPLOY_REGION"
317336
prompt_and_update_tfvar "Resource naming prefix" "cs" "resource_prefix" "RES_PREFIX"

infrastructure/app.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ module "compute" {
1616
region = var.region
1717
resource_prefix = var.resource_prefix
1818
environment = var.environment
19+
20+
# The deployment script dynamically sets this value (e.g., "latest" or "v1.2.0")
21+
app_version = var.app_version
1922

2023
# Direct VPC routing configurations
2124
vpc_subnet_name = module.network.cloud_run_subnet_name
2225
database_ip = module.database.private_ip_address
23-
image_url = "${module.artifact.repository_url}/${var.backend_image_name}:${var.backend_image_tag}"
26+
27+
# Dynamically construct the image URL using the injected app_version
28+
image_url = "${module.artifact.repository_url}/${var.backend_image_name}:${var.app_version}"
2429

2530
# References the list keys to configure secret environment block mappings
26-
secret_ids = var.application_secrets
27-
}
31+
secret_ids = var.application_secrets
32+
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# infra/modules/artifact-registry/main.tf
22

3-
resource "google_artifact_registry_repository" "ghcr_proxy" {
3+
resource "google_artifact_registry_repository" "cstudio_repo" {
44
location = var.region
55
repository_id = "${var.resource_prefix}-${var.environment}-${var.repository_id}"
6-
description = "Regional proxy for GHCR with vulnerability scanning"
6+
description = "Local private registry for Creative Studio with vulnerability scanning"
77
format = "DOCKER"
88

9-
# Remote Repository Mode
10-
mode = "REMOTE_REPOSITORY"
11-
12-
remote_repository_config {
13-
description = "Proxy for GitHub Container Registry"
14-
docker_repository {
15-
custom_repository {
16-
uri = var.remote_uri
17-
}
18-
}
19-
}
20-
219
# Explicitly enable vulnerability scanning
2210
# Note: This requires 'containerscanning.googleapis.com' to be enabled in the project
2311
# Ensure the mirror scans every image it caches
@@ -35,7 +23,7 @@ resource "google_artifact_registry_repository" "ghcr_proxy" {
3523
}
3624

3725
labels = merge(var.labels, {
38-
component = "security-mirror"
26+
component = "artifact-registry"
3927
region = var.region
4028
})
4129
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
output "repository_id" {
22
description = "The ID of the Artifact Registry repository."
3-
value = google_artifact_registry_repository.ghcr_proxy.repository_id
3+
value = google_artifact_registry_repository.cstudio_repo.repository_id
44
}
55

66
output "repository_name" {
77
description = "The fully qualified name of the repository."
8-
value = google_artifact_registry_repository.ghcr_proxy.name
8+
value = google_artifact_registry_repository.cstudio_repo.name
99
}
1010

11+
1112
output "repository_url" {
12-
description = "The URL of the repository (without image name)."
13-
value = "${var.region}-docker.pkg.dev/${var.project_id}/${google_artifact_registry_repository.ghcr_proxy.repository_id}"
13+
description = "The fully qualified URL to the local Docker repository."
14+
# Format: us-central1-docker.pkg.dev/project-id/cs-dev-repo
15+
value = "${google_artifact_registry_repository.cstudio_repo.location}-docker.pkg.dev/${google_artifact_registry_repository.cstudio_repo.project}/${google_artifact_registry_repository.cstudio_repo.repository_id}"
1416
}

infrastructure/modules/compute/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ locals {
4242

4343
resource "google_cloud_run_v2_service" "backend" {
4444
name = var.service_name
45-
location = var.gcp_region
45+
location = var.region
4646
custom_audiences = var.custom_audiences
4747
deletion_protection = false
4848

infrastructure/modules/compute/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,9 @@ variable "run_sa_project_roles" {
138138
"roles/secretmanager.secretAccessor",
139139
]
140140
}
141+
142+
variable "app_version" {
143+
type = string
144+
description = "version of the creative studio app we're deploying"
145+
default = "latest"
146+
}

infrastructure/variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ variable "labels" {
8282
default = {}
8383
}
8484

85-
85+
variable "app_version" {
86+
type = string
87+
description = "version of the creative studio app we're deploying"
88+
default = "latest"
89+
}

0 commit comments

Comments
 (0)