Skip to content

Commit 030d7aa

Browse files
spaiterclaude
andcommitted
fix(docker): optimize production Docker builds by excluding tests
Changes: - Revert .dockerignore to exclude test files (reduces production image size) - Update Makefile test-xdp-docker to temporarily disable .dockerignore - This allows XDP tests to access test files while keeping production builds lean The Makefile now: 1. Renames .dockerignore to .dockerignore.tmp before XDP build 2. Builds the XDP test container with all files 3. Restores .dockerignore after build Production Docker builds (Dockerfile) now exclude ~100MB of test files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent aeab1c7 commit 030d7aa

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.dockerignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ result-*
1919
*.tar.gz
2020
*.zip
2121

22-
# Test files
23-
# Note: XDP integration tests (Dockerfile.xdp-test) need test/ and *_test.go files
24-
# Only exclude test artifacts and large test data
22+
# Test files (production builds don't need tests)
23+
*_test.go
24+
test/
2525
coverage.out
2626
coverage.html
27-
test/testdata/*.pcap.gz
2827

2928
# IDE
3029
.vscode

Dockerfile.xdp-test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dockerfile for running XDP integration tests
22
# Requires: --privileged --network host (for network interface access)
33
# Usage: docker build -f Dockerfile.xdp-test -t btblocker-xdp-test .
4-
# docker run --rm --privileged --network host -v ${PWD}:/src btblocker-xdp-test
4+
# docker run --rm --privileged --network host btblocker-xdp-test
55

66
FROM golang:1.25-bookworm
77

@@ -20,7 +20,7 @@ WORKDIR /src
2020
COPY go.mod go.sum ./
2121
RUN go mod download
2222

23-
# Copy source code including tests (.dockerignore now allows test files)
23+
# Copy source code (Makefile temporarily disables .dockerignore to include tests)
2424
COPY . .
2525

2626
# Build the project to ensure everything compiles

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ test:
2626
# Run XDP integration tests using Docker (requires privileged container)
2727
test-xdp-docker:
2828
@echo "Building XDP test container..."
29-
docker build -f Dockerfile.xdp-test -t btblocker-xdp-test .
29+
@# Temporarily disable .dockerignore to include test files
30+
@if [ -f .dockerignore ]; then mv .dockerignore .dockerignore.tmp; fi
31+
@docker build -f Dockerfile.xdp-test -t btblocker-xdp-test . || (mv .dockerignore.tmp .dockerignore 2>/dev/null; exit 1)
32+
@if [ -f .dockerignore.tmp ]; then mv .dockerignore.tmp .dockerignore; fi
3033
@echo "Running XDP integration tests (requires privileged mode)..."
3134
docker run --rm --privileged --network host btblocker-xdp-test
3235

0 commit comments

Comments
 (0)