Skip to content

Commit 962201e

Browse files
sbalabanov-zzsbalabanov
authored andcommitted
refactor(test): content-hash image tags and testonly docker context filegroups
Summary: Follow-ups to #439, adopting the stronger ideas from the concurrent implementation in #438. Intent: - #439 seeds the compose image-tag prefix from TEST_TARGET, which is identical across worktrees: two worktrees at different revisions running the same target against one Docker daemon can interleave builds and start a container from the other worktree's image. Derive the tag from the declared input contents instead, so a collision is impossible by construction. - The cross-compiled service binaries and Dockerfiles were exported as public, non-testonly targets and enumerated file-by-file in every test's data list. Encapsulate them so they cannot leak into production targets. Changes: - Image-tag prefix is now a hash of the declared inputs (compose file + staged build-context files, hashed in deterministic order): identical inputs reuse the docker build cache, different revisions never collide on a tag. - Each service bundles its docker build-context inputs (Dockerfile, configs, cross-compiled linux binary) into a testonly docker_test_context filegroup visible only to //test/...; the go_cross_binary targets are now private and the per-file Dockerfile/queues.yaml exports are gone. - Build-context staging streams the copy and preserves the source file mode instead of loading whole binaries into memory and stamping everything 0755. Test Plan: - Ran //test/integration/submitqueue/gateway, //test/e2e/submitqueue, and //test/integration/extension/counter/mysql locally against a real Docker daemon (staged-context, multi-service, and no-build-context paths) and verified via `docker images` that image tags carry the content-hash prefix, with distinct prefixes per distinct input set. --- <sub>Generated by the 🪄 [pr-create](https://sg.uberinternal.com/code.uber.internal/uber-code/devexp-agent-marketplace/-/blob/claude-code/plugins/dev/uber-dev/skills/pr-create/SKILL.md) skill in devexp-agent-marketplace</sub> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 6c828b8 commit 962201e

11 files changed

Lines changed: 127 additions & 64 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ deps = [
309309

310310
**Integration tests** use Docker Compose via `testutil.ComposeStack`:
311311
- Package naming: folder name as package (NOT `*_test` suffix)
312-
- Bazel: add `tags = ["integration", "requires-network"]` and `data = [...]` for every input the test reads (compose file, schema dirs, Dockerfiles, Bazel-built `*_linux` service binaries). Tests are hermetic: never resolve the repo root — resolve inputs from runfiles via `testutil.Runfile` and stage docker build contexts with `testutil.WithBuildContext`.
312+
- Bazel: add `tags = ["integration", "requires-network"]` and `data = [...]` for every input the test reads (compose file, schema dirs, and each service's `docker_test_context` filegroup bundling its Dockerfile, configs, and Bazel-built `*_linux` binary). Tests are hermetic: never resolve the repo root — resolve inputs from runfiles via `testutil.Runfile` and stage docker build contexts with `testutil.WithBuildContext`.
313313
- Use `testutil.NewComposeStack()` with meaningful context (e.g., `"ext-storage-mysql"`)
314314

315315
See [doc/howto/TESTING.md](doc/howto/TESTING.md) for full testing guide.

service/runway/server/BUILD.bazel

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
22

33
exports_files(
4-
[
5-
"Dockerfile",
6-
"docker-compose.yml",
7-
],
4+
["docker-compose.yml"],
85
visibility = ["//visibility:public"],
96
)
107

@@ -48,5 +45,17 @@ go_cross_binary(
4845
name = "runway_linux",
4946
platform = "@rules_go//go/toolchain:linux_amd64",
5047
target = ":runway",
51-
visibility = ["//visibility:public"],
48+
)
49+
50+
# Everything a Docker-based test needs to build the runway image from a staged
51+
# build context (see testutil.WithBuildContext). Test-only so the
52+
# cross-compiled binary cannot leak into production targets.
53+
filegroup(
54+
name = "docker_test_context",
55+
testonly = True,
56+
srcs = [
57+
"Dockerfile",
58+
":runway_linux",
59+
],
60+
visibility = ["//test:__subpackages__"],
5261
)

service/stovepipe/server/BUILD.bazel

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
22

3-
exports_files(
4-
["Dockerfile"],
5-
visibility = ["//visibility:public"],
6-
)
7-
83
go_library(
94
name = "go_default_library",
105
srcs = ["main.go"],
@@ -53,5 +48,17 @@ go_cross_binary(
5348
name = "stovepipe_linux",
5449
platform = "@rules_go//go/toolchain:linux_amd64",
5550
target = ":stovepipe",
56-
visibility = ["//visibility:public"],
51+
)
52+
53+
# Everything a Docker-based test needs to build the stovepipe image from a
54+
# staged build context (see testutil.WithBuildContext). Test-only so the
55+
# cross-compiled binary cannot leak into production targets.
56+
filegroup(
57+
name = "docker_test_context",
58+
testonly = True,
59+
srcs = [
60+
"Dockerfile",
61+
":stovepipe_linux",
62+
],
63+
visibility = ["//test:__subpackages__"],
5764
)

service/submitqueue/gateway/server/BUILD.bazel

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library", "go_test")
22

33
exports_files(
4-
[
5-
"Dockerfile",
6-
"docker-compose.yml",
7-
"queues.yaml",
8-
],
4+
["docker-compose.yml"],
95
visibility = ["//visibility:public"],
106
)
117

@@ -52,7 +48,20 @@ go_cross_binary(
5248
name = "gateway_linux",
5349
platform = "@rules_go//go/toolchain:linux_amd64",
5450
target = ":gateway",
55-
visibility = ["//visibility:public"],
51+
)
52+
53+
# Everything a Docker-based test needs to build the gateway image from a staged
54+
# build context (see testutil.WithBuildContext). Test-only so the
55+
# cross-compiled binary cannot leak into production targets.
56+
filegroup(
57+
name = "docker_test_context",
58+
testonly = True,
59+
srcs = [
60+
"Dockerfile",
61+
"queues.yaml",
62+
":gateway_linux",
63+
],
64+
visibility = ["//test:__subpackages__"],
5665
)
5766

5867
go_test(

service/submitqueue/orchestrator/server/BUILD.bazel

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
22

33
exports_files(
4-
[
5-
"Dockerfile",
6-
"docker-compose.yml",
7-
],
4+
["docker-compose.yml"],
85
visibility = ["//visibility:public"],
96
)
107

@@ -82,5 +79,17 @@ go_cross_binary(
8279
name = "orchestrator_linux",
8380
platform = "@rules_go//go/toolchain:linux_amd64",
8481
target = ":orchestrator",
85-
visibility = ["//visibility:public"],
82+
)
83+
84+
# Everything a Docker-based test needs to build the orchestrator image from a
85+
# staged build context (see testutil.WithBuildContext). Test-only so the
86+
# cross-compiled binary cannot leak into production targets.
87+
filegroup(
88+
name = "docker_test_context",
89+
testonly = True,
90+
srcs = [
91+
"Dockerfile",
92+
":orchestrator_linux",
93+
],
94+
visibility = ["//test:__subpackages__"],
8695
)

test/e2e/stovepipe/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ go_test(
99
data = [
1010
"//platform/extension/messagequeue/mysql/schema",
1111
"//service/stovepipe:docker-compose.yml",
12-
"//service/stovepipe/server:Dockerfile",
13-
"//service/stovepipe/server:stovepipe_linux",
12+
"//service/stovepipe/server:docker_test_context",
1413
"//stovepipe/extension/storage/mysql/schema",
1514
],
1615
tags = [

test/e2e/submitqueue/BUILD.bazel

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ go_test(
99
data = [
1010
"//platform/extension/counter/mysql/schema",
1111
"//platform/extension/messagequeue/mysql/schema",
12-
"//service/runway/server:Dockerfile",
13-
"//service/runway/server:runway_linux",
12+
"//service/runway/server:docker_test_context",
1413
"//service/submitqueue:docker-compose.yml",
15-
"//service/submitqueue/gateway/server:Dockerfile",
16-
"//service/submitqueue/gateway/server:gateway_linux",
17-
"//service/submitqueue/gateway/server:queues.yaml",
18-
"//service/submitqueue/orchestrator/server:Dockerfile",
19-
"//service/submitqueue/orchestrator/server:orchestrator_linux",
14+
"//service/submitqueue/gateway/server:docker_test_context",
15+
"//service/submitqueue/orchestrator/server:docker_test_context",
2016
"//submitqueue/extension/storage/mysql/schema",
2117
],
2218
tags = [

test/integration/stovepipe/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ go_test(
66
data = [
77
"//platform/extension/messagequeue/mysql/schema",
88
"//service/stovepipe:docker-compose.yml",
9-
"//service/stovepipe/server:Dockerfile",
10-
"//service/stovepipe/server:stovepipe_linux",
9+
"//service/stovepipe/server:docker_test_context",
1110
"//stovepipe/extension/storage/mysql/schema",
1211
],
1312
tags = [

test/integration/submitqueue/gateway/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ go_test(
66
data = [
77
"//platform/extension/counter/mysql/schema",
88
"//platform/extension/messagequeue/mysql/schema",
9-
"//service/submitqueue/gateway/server:Dockerfile",
109
"//service/submitqueue/gateway/server:docker-compose.yml",
11-
"//service/submitqueue/gateway/server:gateway_linux",
12-
"//service/submitqueue/gateway/server:queues.yaml",
10+
"//service/submitqueue/gateway/server:docker_test_context",
1311
"//submitqueue/extension/storage/mysql/schema",
1412
],
1513
tags = [

test/integration/submitqueue/orchestrator/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ go_test(
66
data = [
77
"//platform/extension/counter/mysql/schema",
88
"//platform/extension/messagequeue/mysql/schema",
9-
"//service/submitqueue/orchestrator/server:Dockerfile",
109
"//service/submitqueue/orchestrator/server:docker-compose.yml",
11-
"//service/submitqueue/orchestrator/server:orchestrator_linux",
10+
"//service/submitqueue/orchestrator/server:docker_test_context",
1211
"//submitqueue/extension/storage/mysql/schema",
1312
],
1413
tags = [

0 commit comments

Comments
 (0)