Skip to content

Commit 54e2b8f

Browse files
janiszclaude
andcommitted
feat: Use go mod cache for proto files instead of manual repo clone
Replace manual proto file copying from ../stackrox repository with automated approach using Go mod cache, following the stackrox repository pattern. Changes: - Update setup-proto-files.sh to use `go list -f '{{.Dir}}' -m` for module discovery - Get proto files from github.com/stackrox/rox module - Get scanner protos from github.com/stackrox/scanner module - Add Makefile targets: proto-setup, proto-generate, proto-clean, proto-check - Simplify GitHub Actions workflow (removed external repo checkout) - Update documentation to reflect new approach - Add proto-version.sh script for version tracking Benefits: - No external repository dependencies - Works automatically in CI/CD environments - Version-locked to go.mod for reproducibility - Handles read-only mod cache files with chmod Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 52cd331 commit 54e2b8f

6 files changed

Lines changed: 72 additions & 43 deletions

File tree

.github/workflows/wiremock-test.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,8 @@ jobs:
4242
- name: Download Go dependencies
4343
run: go mod download
4444

45-
- name: Checkout StackRox proto files
46-
uses: actions/checkout@v4
47-
with:
48-
repository: stackrox/stackrox
49-
path: stackrox-repo
50-
sparse-checkout: |
51-
proto
52-
third_party/googleapis
53-
qa-tests-backend/src/main/proto/scanner
54-
55-
- name: Copy proto files
56-
run: |
57-
mkdir -p wiremock/proto/stackrox wiremock/proto/googleapis
58-
cp -r stackrox-repo/proto/* wiremock/proto/stackrox/
59-
cp -r stackrox-repo/third_party/googleapis/* wiremock/proto/googleapis/
60-
mkdir -p wiremock/proto/stackrox/scanner/api/v1
61-
cp stackrox-repo/qa-tests-backend/src/main/proto/scanner/api/v1/*.proto wiremock/proto/stackrox/scanner/api/v1/ || true
45+
- name: Setup proto files from go mod cache
46+
run: ./scripts/setup-proto-files.sh
6247

6348
- name: Run smoke test
6449
run: ./scripts/smoke-test-wiremock.sh

Makefile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,33 @@ lint: ## Run golangci-lint
8383
go install -v "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6"
8484
golangci-lint run
8585

86+
.PHONY: proto-setup
87+
proto-setup: ## Setup proto files from go mod cache
88+
@./scripts/setup-proto-files.sh
89+
90+
.PHONY: proto-generate
91+
proto-generate: ## Generate proto descriptors for WireMock
92+
@./scripts/generate-proto-descriptors.sh
93+
94+
.PHONY: proto-clean
95+
proto-clean: ## Clean generated proto files
96+
@rm -rf wiremock/proto/ wiremock/grpc/
97+
98+
.PHONY: proto-check
99+
proto-check: ## Verify proto setup is correct
100+
@if [ ! -f wiremock/proto/descriptors/stackrox.pb ]; then \
101+
echo "❌ Proto descriptors not found"; \
102+
echo "Run: make proto-generate"; \
103+
exit 1; \
104+
fi
105+
@echo "✓ Proto descriptors present"
106+
86107
.PHONY: mock-download
87108
mock-download: ## Download WireMock JARs
88109
@./scripts/download-wiremock.sh
89110

90111
.PHONY: mock-start
91-
mock-start: ## Start WireMock mock Central locally
112+
mock-start: proto-check ## Start WireMock mock Central locally
92113
@./scripts/start-mock-central.sh
93114

94115
.PHONY: mock-stop

scripts/generate-proto-descriptors.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ GRPC_DIR="wiremock/grpc"
88

99
mkdir -p "$DESCRIPTOR_DIR" "$GRPC_DIR"
1010

11+
# Ensure proto files are present
1112
if [ ! -d "$ROX_PROTO_PATH" ]; then
12-
echo "Error: Proto files not found at $ROX_PROTO_PATH"
13-
echo "Run: ./scripts/setup-proto-files.sh"
14-
exit 1
13+
echo "Proto files not found. Running setup..."
14+
./scripts/setup-proto-files.sh
1515
fi
1616

1717
if ! command -v protoc &> /dev/null; then

scripts/proto-version.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# Display the version of stackrox modules being used for protos
3+
4+
set -e
5+
6+
ROX_VERSION=$(go list -f '{{.Version}}' -m github.com/stackrox/rox)
7+
ROX_DIR=$(go list -f '{{.Dir}}' -m github.com/stackrox/rox)
8+
echo "StackRox proto files from github.com/stackrox/rox@$ROX_VERSION"
9+
echo " Location: $ROX_DIR"
10+
11+
SCANNER_VERSION=$(go list -f '{{.Version}}' -m github.com/stackrox/scanner)
12+
SCANNER_DIR=$(go list -f '{{.Dir}}' -m github.com/stackrox/scanner)
13+
echo ""
14+
echo "Scanner proto files from github.com/stackrox/scanner@$SCANNER_VERSION"
15+
echo " Location: $SCANNER_DIR"

scripts/setup-proto-files.sh

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
#!/bin/bash
22
set -e
33

4-
STACKROX_REPO=""
5-
6-
if [ -d "../stackrox" ]; then
7-
STACKROX_REPO="../stackrox"
8-
elif [ -d "../../stackrox" ]; then
9-
STACKROX_REPO="../../stackrox"
10-
elif [ -n "$STACKROX_REPO_PATH" ]; then
11-
STACKROX_REPO="$STACKROX_REPO_PATH"
12-
fi
4+
echo "Setting up proto files from go modules..."
5+
6+
# Ensure go modules are downloaded
7+
go mod download
138

14-
if [ -z "$STACKROX_REPO" ] || [ ! -d "$STACKROX_REPO" ]; then
15-
echo "Error: StackRox repository not found"
16-
echo "Set STACKROX_REPO_PATH or clone to ../stackrox"
9+
# Discover rox module location using go list
10+
ROX_DIR=$(go list -f '{{.Dir}}' -m github.com/stackrox/rox)
11+
12+
if [ -z "$ROX_DIR" ]; then
13+
echo "Error: github.com/stackrox/rox module not found"
14+
echo "Run: go mod download"
1715
exit 1
1816
fi
1917

20-
echo "Copying proto files from $STACKROX_REPO..."
18+
echo "Using proto files from: $ROX_DIR"
2119

20+
# Create target directories
2221
mkdir -p wiremock/proto/stackrox wiremock/proto/googleapis
2322

24-
cp -r "$STACKROX_REPO/proto/"* wiremock/proto/stackrox/
25-
cp -r "$STACKROX_REPO/third_party/googleapis/"* wiremock/proto/googleapis/
23+
# Copy proto files from rox module
24+
# Note: Files from go mod cache are read-only, so we copy and chmod
25+
cp -r "$ROX_DIR/proto/"* wiremock/proto/stackrox/
26+
cp -r "$ROX_DIR/third_party/googleapis/"* wiremock/proto/googleapis/
2627

27-
mkdir -p wiremock/proto/stackrox/scanner/api/v1
28-
if [ -d "$STACKROX_REPO/qa-tests-backend/src/main/proto/scanner/api/v1" ]; then
29-
cp "$STACKROX_REPO/qa-tests-backend/src/main/proto/scanner/api/v1/"*.proto wiremock/proto/stackrox/scanner/api/v1/
28+
# Copy scanner protos from scanner module (following stackrox pattern)
29+
SCANNER_DIR=$(go list -f '{{.Dir}}' -m github.com/stackrox/scanner)
30+
if [ -n "$SCANNER_DIR" ] && [ -d "$SCANNER_DIR/proto/scanner" ]; then
31+
echo "Using scanner proto files from: $SCANNER_DIR"
32+
cp -r "$SCANNER_DIR/proto/scanner" wiremock/proto/stackrox/
3033
fi
3134

32-
echo "✓ Proto files copied"
35+
# Make files writable (go mod cache files are read-only)
36+
chmod -R u+w wiremock/proto/
37+
38+
echo "✓ Proto files copied from go mod cache"
3339
echo "Next: ./scripts/generate-proto-descriptors.sh"

wiremock/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ This downloads:
3838
- `wiremock-standalone.jar` (~17MB)
3939
- `wiremock-grpc-extension.jar` (~24MB)
4040

41-
### 2. Copy Proto Files
41+
### 2. Setup Proto Files
4242

43-
Copy proto files from the stackrox repository:
43+
Proto files are automatically obtained from the `github.com/stackrox/rox` Go module dependency:
4444

4545
```bash
46+
make proto-setup
47+
# or directly:
4648
./scripts/setup-proto-files.sh
4749
```
4850

49-
This requires the stackrox repo cloned as a sibling directory or set via `STACKROX_REPO_PATH`.
51+
This downloads the module (if needed) and copies proto files from the Go mod cache to `wiremock/proto/`.
5052

5153
### 3. Generate Proto Descriptors
5254

0 commit comments

Comments
 (0)