# syntax=docker/dockerfile:1 # Stage 1: build the Go CLI from source FROM golang:tip-alpine3.23 AS builder WORKDIR /src # Cache module downloads first COPY go.mod go.sum ./ RUN go mod download # Copy the rest of the source code COPY . . # Build the leetcode-go binary from the ctl package RUN CGO_ENABLED=0 go build -mod=mod -o leetcode-go ./ctl # Stage 2: minimal runtime image FROM alpine:3.23 # Install certificates for TLS if needed by cobra/http clients RUN apk --no-cache add ca-certificates WORKDIR /app # Copy the binary from builder COPY --from=builder /src/leetcode-go ./leetcode-go # Default command ENTRYPOINT ["./leetcode-go"] CMD ["help"]
Dockerfile .dockerignore **/*.md **/*.yaml **/*.yml **/*.toml **/*.go.map **/*.log **/*.tmp **/testdata/** **/website/public/** **/website/static/** .git node_modules vendor */vendor *.exe *.dll *.so **/*.test.go **/*.test
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# --------------------------------------------
# LeetCode-Go CLI build container
# --------------------------------------------
# Stage 1: Builder
FROM golang:1.19-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git
# Set working directory for module-aware build
WORKDIR /build
# Cache module downloads
COPY go.mod go.sum ./
RUN go mod download
# Copy all sources
COPY . .
# Build the leetcode-go CLI from the ctl package
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -mod=mod -o leetcode-go ./ctl
# Stage 2: Runtime image
FROM alpine:3.20
# Install CA certs for TLS if needed
RUN apk add --no-cache ca-certificates
WORKDIR /root
# Copy the built binary from the builder
COPY --from=builder /build/leetcode-go /usr/local/bin/leetcode-go
RUN chmod +x /usr/local/bin/leetcode-go
ENTRYPOINT ["leetcode-go"]
**/*.md **/testdata/** **/.git **/.github vendor node_modules *.log *.tmp .DS_Store website/public website/content website/static website/themes /tmp *.out *.exe
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Build a production-ready binary for LeetCode-Go (cli) using a multi-stage build # Stage 1: builder with full Go toolchain FROM golang:tip-alpine3.23 AS builder # Install git for module fetching if needed RUN apk add --no-cache git WORKDIR /build # Pre-copy go.mod files to leverage layer caching COPY go.mod go.sum ./ RUN go mod download # Copy the full source tree COPY . . # Disable CGO for portability ENV CGO_ENABLED=0 # Build the leetcode-go binary from the ctl package RUN go build -mod=mod -o leetcode-go ./ctl # Stage 2: runtime image FROM alpine:3.23 # Install CA certificates for https requests RUN apk add --no-cache ca-certificates WORKDIR /root # Copy the built binary from the builder COPY --from=builder /build/leetcode-go /root/leetcode-go # Ensure the binary is executable RUN chmod +x /root/leetcode-go ENTRYPOINT ["./leetcode-go"]
# Ignore common and large files .git .gitignore node_modules vendor website/public website/static .DS_Store *.log *.tmp *.bak # Docker-related Dockerfile .dockerignore