Skip to content

Commit 66dab27

Browse files
committed
Support conformance env lifecycle in GCP CI Cloud Build
1 parent b990ff2 commit 66dab27

File tree

1 file changed

+32
-4
lines changed
  • deployment/modules/gcp/cloudbuild

1 file changed

+32
-4
lines changed

deployment/modules/gcp/cloudbuild/main.tf

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ resource "google_project_service" "cloudbuild_api" {
3131
disable_on_destroy = false
3232
}
3333

34+
## Service usage API is required for roles/serviceusage.serviceUsageViewer.
3435
resource "google_project_service" "serviceusage_api" {
3536
service = "serviceusage.googleapis.com"
3637
disable_on_destroy = false
@@ -93,6 +94,7 @@ resource "google_cloudbuild_trigger" "build_trigger" {
9394
"-f", "./cmd/gcp/ci/Dockerfile",
9495
"."
9596
]
97+
wait_for = ["docker_build_sctfe_gcp"]
9698
}
9799

98100
## Push the conformance Docker container image to Artifact Registry.
@@ -104,7 +106,7 @@ resource "google_cloudbuild_trigger" "build_trigger" {
104106
"--all-tags",
105107
local.conformance_gcp_docker_image
106108
]
107-
wait_for = ["docker_build_conformance_gcp"]
109+
wait_for = ["preclean_env", "docker_build_conformance_gcp"]
108110
}
109111

110112
## Apply the deployment/live/gcp/ci terragrunt config.
@@ -134,20 +136,46 @@ resource "google_cloudbuild_trigger" "build_trigger" {
134136
id = "bearer_token"
135137
name = "gcr.io/cloud-builders/gcloud"
136138
script = <<EOT
137-
curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/${local.cloudbuild_service_account}/identity?audience=$(cat /workspace/conformance_url)" > /workspace/cb_identity
139+
curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/${local.cloudbuild_service_account}/identity?audience=$(cat /workspace/conformance_url)" > /workspace/cb_identity
138140
EOT
139141
wait_for = ["terraform_apply_conformance_ci"]
140142
}
141143

144+
## Generate the test certificate for submission.
145+
## TODO: Remove this with CT Hammer when it is ready.
146+
step {
147+
id = "gen_test_cert"
148+
name = "gcr.io/cloud-builders/gcloud"
149+
script = <<EOT
150+
mkdir -p /tmp/httpschain
151+
openssl genrsa -out /tmp/httpschain/cert.key 2048
152+
openssl req -new -key /tmp/httpschain/cert.key -out /tmp/httpschain/cert.csr -config=testdata/fake-ca.cfg
153+
openssl x509 -req -days 3650 -in /tmp/httpschain/cert.csr -CAkey testdata/fake-ca.privkey.pem -CA testdata/fake-ca.cert -passin pass:"gently" -outform pem -out /tmp/httpschain/chain.pem -provider legacy -provider default
154+
cat testdata/fake-ca.cert >> /tmp/httpschain/chain.pem
155+
EOT
156+
wait_for = ["terraform_apply_conformance_ci"]
157+
}
158+
159+
## Prepare the add-chain request body
160+
## TODO: Remove this with CT Hammer when it is ready.
161+
step {
162+
id = "prepare_add_chain_request_body"
163+
name = "ghcr.io/jqlang/jq"
164+
script = <<EOT
165+
cat /tmp/httpschain/chain.pem | jq --raw-input --slurp --compact-output 'split("\n-----END CERTIFICATE-----\n") | map(select(length > 0) | sub("^-----BEGIN CERTIFICATE-----\n"; "") | sub("\n-----END CERTIFICATE-----$"; "")) | { "chain": . }' > /tmp/httpschain/chain.json
166+
EOT
167+
wait_for = ["gen_test_cert"]
168+
}
169+
142170
## Test against the conformance server.
143171
## TODO: Replace this with CT Hammer when it is ready.
144172
step {
145173
id = "curl_test"
146174
name = "curlimages/curl"
147175
script = <<EOT
148-
curl -iX POST $(cat /workspace/conformance_url)/ci-${var.project_id}/ct/v1/add-pre-chain -H "Authorization: Bearer $(cat /workspace/cb_identity)"
176+
curl -i -X POST --data @/tmp/httpschain/chain.json -H "Content-Type: application/json" -H "Authorization: Bearer $(cat /workspace/cb_identity)" $(cat /workspace/conformance_url)/ci-${var.project_id}/ct/v1/add-pre-chain
149177
EOT
150-
wait_for = ["bearer_token"]
178+
wait_for = ["bearer_token", "prepare_add_chain_request_body"]
151179
}
152180

153181
## Destroy the deployment/live/gcp/ci terragrunt config.

0 commit comments

Comments
 (0)