Skip to content

Commit 6b1dc0d

Browse files
committed
terraform test: Build mz-debug in the background
Saves ~7 min. We need to wait for terraform anyway
1 parent 07807f2 commit 6b1dc0d

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

ci/plugins/mzcompose/hooks/pre-exit

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,6 @@ if [ -n "${CI_COVERAGE_ENABLED:-}" ] && [ -z "${BUILDKITE_MZCOMPOSE_PLUGIN_SKIP_
134134
fi
135135
fi
136136

137-
if [[ "$BUILDKITE_LABEL" =~ Terraform\ .* ]]; then
138-
ci_unimportant_heading "terraform: Destroying leftover state in case job was cancelled or timed out..."
139-
bin/ci-builder run stable terraform -chdir=test/terraform/aws-temporary destroy || true
140-
bin/ci-builder run stable terraform -chdir=test/terraform/gcp-temporary destroy || true
141-
PATH="$PWD/test/terraform/azure-temporary/venv/bin:$PATH" VIRTUAL_ENV="$PWD/test/terraform/azure-temporary/venv" bin/ci-builder run stable terraform -chdir=test/terraform/azure-temporary destroy || true
142-
fi
143-
rm -rf ~/.kube # Remove potential state from E2E Terraform tests
144-
145137
ci_unimportant_heading ":docker: Cleaning up after mzcompose"
146138

147139
# docker-compose kill may fail attempting to kill containers
@@ -158,10 +150,10 @@ docker ps --all --quiet | xargs --no-run-if-empty docker rm --force --volumes
158150

159151
if [[ "$BUILDKITE_LABEL" =~ Terraform\ .* ]]; then
160152
ci_unimportant_heading "terraform: Destroying leftover state in case job was cancelled or timed out..."
161-
bin/ci-builder run stable terraform -chdir=test/terraform/aws-temporary destroy || true
162-
bin/ci-builder run stable terraform -chdir=test/terraform/aws-upgrade destroy || true
163-
bin/ci-builder run stable terraform -chdir=test/terraform/gcp-temporary destroy || true
164-
bin/ci-builder run stable terraform -chdir=test/terraform/azure-temporary destroy || true
153+
bin/ci-builder run stable terraform -chdir=test/terraform/aws-temporary destroy -auto-approve || true
154+
bin/ci-builder run stable terraform -chdir=test/terraform/aws-upgrade destroy -auto-approve || true
155+
bin/ci-builder run stable terraform -chdir=test/terraform/gcp-temporary destroy -auto-approve || true
156+
bin/ci-builder run stable terraform -chdir=test/terraform/azure-temporary destroy -auto-approve || true
165157
fi
166158
rm -rf ~/.kube # Remove potential state from E2E Terraform tests
167159

test/terraform/mzcompose.py

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import signal
1717
import subprocess
18+
import threading
1819
import time
1920
from collections.abc import Sequence
2021
from pathlib import Path
@@ -140,24 +141,44 @@ def get_tag(tag: str | None) -> str:
140141
return tag or f"v{ci_util.get_mz_version()}--pr.g{git.rev_parse('HEAD')}"
141142

142143

143-
def mz_debug(env: dict[str, str] | None = None) -> None:
144+
def build_mz_debug_async(env: dict[str, str] | None = None) -> None:
145+
def run():
146+
spawn.capture(
147+
[
148+
"cargo",
149+
"build",
150+
"--bin",
151+
"mz-debug",
152+
],
153+
cwd=MZ_ROOT,
154+
env=env,
155+
)
156+
157+
threading.Thread(target=run, daemon=True).start()
158+
159+
160+
def run_mz_debug(env: dict[str, str] | None = None) -> None:
144161
print("-- Running mz-debug")
145-
run_ignore_error(
146-
[
147-
"cargo",
148-
"run",
149-
"--bin",
150-
"mz-debug",
151-
"--",
152-
"self-managed",
153-
"--k8s-namespace",
154-
"materialize-environment",
155-
"--k8s-namespace",
156-
"materialize",
157-
],
158-
cwd=MZ_ROOT,
159-
env=env,
160-
)
162+
try:
163+
# mz-debug (and its compilation) is rather noisy, so ignore the output
164+
spawn.capture(
165+
[
166+
"cargo",
167+
"run",
168+
"--bin",
169+
"mz-debug",
170+
"--",
171+
"self-managed",
172+
"--k8s-namespace",
173+
"materialize-environment",
174+
"--k8s-namespace",
175+
"materialize",
176+
],
177+
cwd=MZ_ROOT,
178+
env=env,
179+
)
180+
except:
181+
pass
161182

162183

163184
class AWS:
@@ -667,6 +688,7 @@ def workflow_aws_temporary(c: Composition, parser: WorkflowArgumentParser) -> No
667688
path = MZ_ROOT / "test" / "terraform" / "aws-temporary"
668689
aws = AWS(path)
669690
try:
691+
build_mz_debug_async()
670692
aws.setup("aws-test", args.setup, tag)
671693
print("--- Running tests")
672694
with c.override(testdrive(no_reset=False)):
@@ -696,7 +718,7 @@ def workflow_aws_temporary(c: Composition, parser: WorkflowArgumentParser) -> No
696718
finally:
697719
aws.cleanup()
698720

699-
mz_debug()
721+
run_mz_debug()
700722

701723
if args.cleanup:
702724
aws.destroy()
@@ -736,6 +758,7 @@ def workflow_aws_upgrade(c: Composition, parser: WorkflowArgumentParser) -> None
736758
path = MZ_ROOT / "test" / "terraform" / "aws-upgrade"
737759
aws = AWS(path)
738760
try:
761+
build_mz_debug_async()
739762
aws.setup("aws-upgrade", args.setup, previous_tag)
740763
aws.upgrade(tag)
741764
# Try waiting a bit, otherwise connection error, should be handled better
@@ -769,7 +792,7 @@ def workflow_aws_upgrade(c: Composition, parser: WorkflowArgumentParser) -> None
769792
finally:
770793
aws.cleanup()
771794

772-
mz_debug()
795+
run_mz_debug()
773796

774797
if args.cleanup:
775798
aws.destroy()
@@ -943,6 +966,7 @@ def workflow_gcp_temporary(c: Composition, parser: WorkflowArgumentParser) -> No
943966
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = str(gcloud_creds_path)
944967

945968
try:
969+
build_mz_debug_async()
946970
spawn.runv(["gcloud", "config", "set", "project", "materialize-ci"])
947971

948972
spawn.runv(
@@ -1338,7 +1362,7 @@ def workflow_gcp_temporary(c: Composition, parser: WorkflowArgumentParser) -> No
13381362
if balancerd_port_forward_process:
13391363
os.killpg(os.getpgid(balancerd_port_forward_process.pid), signal.SIGTERM)
13401364

1341-
mz_debug()
1365+
run_mz_debug()
13421366

13431367
if args.cleanup:
13441368
print("--- Cleaning up")
@@ -1414,6 +1438,7 @@ def workflow_azure_temporary(c: Composition, parser: WorkflowArgumentParser) ->
14141438
)
14151439

14161440
try:
1441+
build_mz_debug_async()
14171442
if os.getenv("CI"):
14181443
username = os.getenv("AZURE_SERVICE_ACCOUNT_USERNAME")
14191444
password = os.getenv("AZURE_SERVICE_ACCOUNT_PASSWORD")
@@ -1837,7 +1862,7 @@ def workflow_azure_temporary(c: Composition, parser: WorkflowArgumentParser) ->
18371862
if balancerd_port_forward_process:
18381863
os.killpg(os.getpgid(balancerd_port_forward_process.pid), signal.SIGTERM)
18391864

1840-
mz_debug(env=venv_env)
1865+
run_mz_debug(env=venv_env)
18411866

18421867
if args.cleanup:
18431868
print("--- Cleaning up")

0 commit comments

Comments
 (0)