Skip to content

Commit 8240953

Browse files
committed
test: make Docker suites hermetic
1 parent a6d7a40 commit 8240953

33 files changed

Lines changed: 311 additions & 205 deletions

File tree

BUILD.bazel

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,4 @@ load("@gazelle//:def.bzl", "gazelle")
2626
# native.java_proto_library).
2727
# gazelle:proto disable_global
2828

29-
# Export marker files for test data dependencies (used by FindRepoRoot in tests)
30-
exports_files(
31-
[
32-
"MODULE.bazel",
33-
"go.mod",
34-
],
35-
visibility = ["//visibility:public"],
36-
)
37-
3829
gazelle(name = "gazelle")

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ GOIMPORTS_VERSION ?= v0.33.0
3838
# contracts); all generated stubs land in the same protopb/ dir.
3939
PROTO_PACKAGES = api/base/change api/base/mergestrategy api/base/messagequeue api/runway/messagequeue api/runway api/submitqueue/gateway api/submitqueue/orchestrator api/stovepipe stovepipe/core/messagequeue
4040

41-
# Set REPO_ROOT for docker-compose
42-
export REPO_ROOT := $(shell pwd)
41+
# Local Compose builds use the repository checkout as their build context.
42+
export SQ_DOCKER_BUILD_CONTEXT := $(shell pwd)
4343

4444
# Fails if git working tree is dirty. Usage: $(call assert_clean,fix command)
4545
define assert_clean
@@ -132,7 +132,7 @@ clean-proto: ## Clean generated proto files
132132
deps: tidy-go ## Download and tidy Go dependencies
133133
@echo "Dependencies installed!"
134134

135-
e2e-test: build-all-linux ## Run end-to-end tests (hermetic, auto-builds binaries; runs in parallel)
135+
e2e-test: ## Run end-to-end tests (Bazel builds declared Docker inputs; runs in parallel)
136136
@echo "Running end-to-end tests (parallel)..."
137137
@$(BAZEL) test //test/e2e/... --test_output=errors
138138

@@ -147,7 +147,7 @@ gazelle: ## Update BUILD.bazel files
147147
@echo "Running Gazelle to update BUILD files..."
148148
@$(BAZEL) run //:gazelle
149149

150-
integration-test: build-all-linux ## Run all integration tests (auto-builds binaries; runs in parallel)
150+
integration-test: ## Run all integration tests (Bazel builds declared Docker inputs; runs in parallel)
151151
@echo "Running all integration tests (parallel)..."
152152
@$(BAZEL) test //test/integration/... --test_output=errors
153153

@@ -159,11 +159,11 @@ integration-test-extensions: ## Run extension integration tests (runs in paralle
159159
@echo "Running extension integration tests (parallel)..."
160160
@$(BAZEL) test //test/integration/submitqueue/extension/... //test/integration/extension/... --test_output=errors
161161

162-
integration-test-submitqueue-gateway: build-submitqueue-gateway-linux ## Run Gateway integration tests (auto-builds binary)
162+
integration-test-submitqueue-gateway: ## Run Gateway integration tests (Bazel builds declared Docker inputs)
163163
@echo "Running Gateway integration tests..."
164164
@$(BAZEL) test //test/integration/submitqueue/gateway:go_default_test --test_output=streamed
165165

166-
integration-test-submitqueue-orchestrator: build-submitqueue-orchestrator-linux ## Run Orchestrator integration tests (auto-builds binary)
166+
integration-test-submitqueue-orchestrator: ## Run Orchestrator integration tests (Bazel builds declared Docker inputs)
167167
@echo "Running Orchestrator integration tests..."
168168
@$(BAZEL) test //test/integration/submitqueue/orchestrator:go_default_test --test_output=streamed
169169

doc/howto/TESTING.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ make e2e-test
6262

6363
# Build
6464
make build # Build all targets
65-
make build-all-linux # Build Linux binaries for Docker
65+
make build-all-linux # Build Linux binaries for manual Compose workflows
6666
```
6767

6868
### Testing Levels
@@ -88,10 +88,13 @@ make build-all-linux # Build Linux binaries for Docker
8888

8989
Tests use **docker-compose** via `ComposeStack` to spin up containers automatically:
9090

91-
1. `NewComposeStack()` registers cleanup (stop log tailing, tear down containers)
92-
2. `Up()` starts containers, waits for healthchecks (`--wait`), and auto-tails container logs to stderr
93-
3. Tests run against those containers with **real-time log output**
94-
4. On cleanup, containers are torn down automatically (set `SKIP_CLEANUP=true` to keep them for inspection)
91+
1. Each `go_test` declares its Compose file, schemas, Dockerfiles, configuration, and cross-compiled Linux service binaries in Bazel `data`.
92+
2. `NewComposeStack()` resolves only those Bazel runfiles and stages the declared Docker build-context files in a temporary directory.
93+
3. `Up()` starts containers, waits for healthchecks (`--wait`), and auto-tails container logs to stderr.
94+
4. Tests run against those containers with **real-time log output**.
95+
5. On cleanup, containers are torn down automatically (set `SKIP_CLEANUP=true` to keep them for inspection).
96+
97+
Automated Docker tests do not discover or mount the repository checkout. A test that adds a build-context input must add it to its Bazel `data` dependencies and its `ComposeConfig.DockerBuildContext` mapping.
9598

9699
---
97100

service/runway/server/BUILD.bazel

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
load("@rules_go//go:def.bzl", "go_binary", "go_library")
1+
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
2+
3+
filegroup(
4+
name = "docker_test_context",
5+
testonly = True,
6+
srcs = [
7+
"Dockerfile",
8+
":runway_linux_amd64",
9+
],
10+
visibility = ["//test:__subpackages__"],
11+
)
212

313
go_library(
414
name = "go_default_library",
@@ -32,3 +42,9 @@ go_binary(
3242
embed = [":go_default_library"],
3343
visibility = ["//visibility:public"],
3444
)
45+
46+
go_cross_binary(
47+
name = "runway_linux_amd64",
48+
platform = "@rules_go//go/toolchain:linux_amd64",
49+
target = ":runway",
50+
)

service/runway/server/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
runway-service:
3838
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-runway-service:latest
3939
build:
40-
context: ${REPO_ROOT}
40+
context: ${SQ_DOCKER_BUILD_CONTEXT}
4141
dockerfile: service/runway/server/Dockerfile
4242
ports:
4343
- "8080" # Random ephemeral port to avoid conflicts

service/stovepipe/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ services:
5959
stovepipe-service:
6060
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-stovepipe-service:latest
6161
build:
62-
context: ${REPO_ROOT}
62+
context: ${SQ_DOCKER_BUILD_CONTEXT}
6363
dockerfile: service/stovepipe/server/Dockerfile
6464
ports:
6565
- "8080" # Random ephemeral port to avoid conflicts

service/stovepipe/server/BUILD.bazel

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
load("@rules_go//go:def.bzl", "go_binary", "go_library")
1+
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")
2+
3+
filegroup(
4+
name = "docker_test_context",
5+
testonly = True,
6+
srcs = [
7+
"Dockerfile",
8+
":stovepipe_linux_amd64",
9+
],
10+
visibility = ["//test:__subpackages__"],
11+
)
212

313
go_library(
414
name = "go_default_library",
@@ -40,3 +50,9 @@ go_binary(
4050
embed = [":go_default_library"],
4151
visibility = ["//visibility:public"],
4252
)
53+
54+
go_cross_binary(
55+
name = "stovepipe_linux_amd64",
56+
platform = "@rules_go//go/toolchain:linux_amd64",
57+
target = ":stovepipe",
58+
)

service/submitqueue/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ services:
5252
gateway-service:
5353
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-gateway-service:latest
5454
build:
55-
context: ${REPO_ROOT}
55+
context: ${SQ_DOCKER_BUILD_CONTEXT}
5656
dockerfile: service/submitqueue/gateway/server/Dockerfile
5757
ports:
5858
- "8080" # Random ephemeral port to avoid conflicts
@@ -75,7 +75,7 @@ services:
7575
orchestrator-service:
7676
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-orchestrator-service:latest
7777
build:
78-
context: ${REPO_ROOT}
78+
context: ${SQ_DOCKER_BUILD_CONTEXT}
7979
dockerfile: service/submitqueue/orchestrator/server/Dockerfile
8080
ports:
8181
- "8080" # Random ephemeral port to avoid conflicts
@@ -100,7 +100,7 @@ services:
100100
runway-service:
101101
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-runway-service:latest
102102
build:
103-
context: ${REPO_ROOT}
103+
context: ${SQ_DOCKER_BUILD_CONTEXT}
104104
dockerfile: service/runway/server/Dockerfile
105105
ports:
106106
- "8080" # Random ephemeral port to avoid conflicts

service/submitqueue/gateway/server/BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
1+
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library", "go_test")
22

33
exports_files(
44
["docker-compose.yml"],
55
visibility = ["//visibility:public"],
66
)
77

8+
filegroup(
9+
name = "docker_test_context",
10+
testonly = True,
11+
srcs = [
12+
"Dockerfile",
13+
"queues.yaml",
14+
":gateway_linux_amd64",
15+
],
16+
visibility = ["//test:__subpackages__"],
17+
)
18+
819
go_library(
920
name = "gateway_lib",
1021
srcs = ["main.go"],
@@ -41,6 +52,12 @@ go_binary(
4152
visibility = ["//visibility:public"],
4253
)
4354

55+
go_cross_binary(
56+
name = "gateway_linux_amd64",
57+
platform = "@rules_go//go/toolchain:linux_amd64",
58+
target = ":gateway",
59+
)
60+
4461
go_test(
4562
name = "go_default_test",
4663
srcs = ["main_test.go"],

service/submitqueue/gateway/server/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ services:
5252
gateway-service:
5353
image: ${SQ_DOCKER_IMAGE_PREFIX:-submitqueue}-gateway-service:latest
5454
build:
55-
context: ${REPO_ROOT}
55+
context: ${SQ_DOCKER_BUILD_CONTEXT}
5656
dockerfile: service/submitqueue/gateway/server/Dockerfile
5757
ports:
5858
- "8080" # Random ephemeral port to avoid conflicts

0 commit comments

Comments
 (0)