FROM golang:1.19-buster AS builder
WORKDIR /workspace
# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the code
COPY . .
# Build the ctl binary from the ctl directory
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -mod=mod -o /app/ctl ./ctl
FROM debian:bullseye-slim
WORKDIR /app
COPY --from=builder /app/ctl /usr/local/bin/ctl
# Create a non-root user for running the app
RUN useradd -r -u 1000 -d /home/ctl -s /bin/bash ctluser \
&& mkdir -p /home/ctl \
&& chown -R ctluser:ctluser /usr/local/bin/ctl
USER ctluser
CMD ["ctl"]
**/.git **/node_modules **/vendor *.log Dockerfile .dockerignore website/public website/static *.tmp *.bak *.tar *.tar.gz *.zip
- Exact error message and exit code - go: github.com/halfrost/LeetCode-Go/ctl/models@v0.0.0-20220910225043-e3bb5aff34d0 (replaced by ./ctl/models): reading ctl/models/go.mod: open /workspace/ctl/models/go.mod: no such file or directory - ERROR: failed to build: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1 - Failing command/step - [builder 4/6] RUN go mod download - Missing packages or files mentioned - Missing file: /workspace/ctl/models/go.mod - The module is declared as replaced by ./ctl/models, implying a local path that is not present in the build context at this step - Version mismatch / related version info - Base images used: golang:1.19-buster and Debian bullseye-slim - The error references a pseudo-version: v0.0.0-20220910225043-e3bb5aff34d0, replaced by ./ctl/models - No explicit version mismatch reported; the issue is the missing local path for the module replacement - Context note (implicit cause) - go.mod contains a replacement "replaced by ./ctl/models" but only go.mod/go.sum were copied before the failing step; the rest of the code (ctl/models) isn’t in the build context yet, so /workspace/ctl/models/go.mod cannot be found.
FROM golang:1.19-buster AS builder
WORKDIR /workspace
# Copy the entire repository to leverage local module replacements
COPY . .
# Resolve and download dependencies
RUN go mod download
# Build the ctl binary from the ctl directory
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -mod=mod -o /app/ctl ./ctl
FROM debian:bullseye-slim
WORKDIR /app
COPY --from=builder /app/ctl /usr/local/bin/ctl
# Create a non-root user for running the app
RUN useradd -r -u 1000 -d /home/ctl -s /bin/bash ctluser \
&& mkdir -p /home/ctl \
&& chown -R ctluser:ctluser /usr/local/bin/ctl
USER ctluser
CMD ["ctl"]
Smoke [PASS]: test -x /usr/local/bin/ctl Smoke [PASS]: command -v ctl