Skip to content

Commit e9ecb8c

Browse files
committed
build(docker): simplify local avalanchego handling in Dockerfile
- Move ./avalanchego to /third_party if present. - Always dropreplace first; conditionally add replace if go.mod exists. - Run go mod tidy after edits.
1 parent 5a5b126 commit e9ecb8c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ RUN go mod download
1616
# Copy the code into the container
1717
COPY . .
1818

19-
# If a local avalanchego module is present, move it out of the module tree and
20-
# point the replace directive at it to avoid flattening into this module's packages.
21-
RUN if [ -f ./avalanchego/go.mod ]; then \
22-
mkdir -p /third_party && \
23-
mv ./avalanchego /third_party/avalanchego && \
24-
go mod edit -replace github.com/ava-labs/avalanchego=./third_party/avalanchego && \
25-
go mod tidy; \
19+
# Ensure we never keep a stale local replace when no local module is present
20+
RUN go mod edit -dropreplace github.com/ava-labs/avalanchego || true
21+
22+
# If a local avalanchego source dir is present, move it outside the module tree.
23+
# Only add a replace if the moved directory is a standalone module with go.mod,
24+
# otherwise drop any existing replace so upstream is used.
25+
RUN if [ -d ./avalanchego ]; then \
26+
mkdir -p /third_party && mv ./avalanchego /third_party/avalanchego; \
27+
if [ -f /third_party/avalanchego/go.mod ]; then \
28+
go mod edit -replace github.com/ava-labs/avalanchego=/third_party/avalanchego; \
29+
go mod tidy; \
30+
fi; \
2631
fi
2732

2833
# Ensure pre-existing builds are not available for inclusion in the final image

0 commit comments

Comments
 (0)