halfrost-leetcode-go
SUCCESS
3m 56s
History Source
SummaryIterations1Transcript5Dockerfile
Dockerfile26 lines · 618 chars
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"]