# Stage 1: Build esbuild from source
FROM golang:tip-alpine3.23 AS builder
# Install build tools
RUN apk add --no-cache make bash curl nodejs npm
WORKDIR /src
# Copy Go module files first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source
COPY . .
# Build esbuild from source (CGO_ENABLED=0 is set in the Makefile)
RUN make esbuild
# Stage 2: Minimal runtime image
FROM alpine:3.23
# Ensure TLS certs are available (for any network access the binary might need)
RUN apk add --no-cache ca-certificates
# Create a non-root user to run the binary safely
RUN adduser -D esbuild
# Copy the built binary from the builder stage
COPY --from=builder /src/esbuild /usr/local/bin/esbuild
# Set permissions and user
RUN chown esbuild:esbuild /usr/local/bin/esbuild
USER esbuild
WORKDIR /home/esbuild
# Default command: show help, but allow overrides on container run
ENTRYPOINT ["/usr/local/bin/esbuild"]
CMD ["--help"]