|
| 1 | +# Development Dockerfile with shell access |
| 2 | +# Uses Alpine instead of scratch for debugging |
| 3 | + |
| 4 | +# Build stage - same as production |
| 5 | +FROM golang:1.23-alpine AS builder |
| 6 | + |
| 7 | +# Install git and ca-certificates (needed for fetching dependencies and HTTPS) |
| 8 | +RUN apk add --no-cache git ca-certificates tzdata |
| 9 | + |
| 10 | +# Create a non-root user |
| 11 | +RUN adduser -D -u 1000 appuser |
| 12 | + |
| 13 | +# Set the working directory |
| 14 | +WORKDIR /app |
| 15 | + |
| 16 | +# Copy go mod files |
| 17 | +COPY go.mod go.sum ./ |
| 18 | + |
| 19 | +# Download dependencies |
| 20 | +RUN go mod download |
| 21 | + |
| 22 | +# Copy source code |
| 23 | +COPY . . |
| 24 | + |
| 25 | +# Build the application |
| 26 | +# Disable CGO for a fully static binary |
| 27 | +# Use linker flags to reduce binary size and embed version info |
| 28 | +ARG VERSION=dev |
| 29 | +ARG BUILD_TIME |
| 30 | +ARG GIT_COMMIT |
| 31 | +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ |
| 32 | + -ldflags="-s -w -X github.com/kjanat/articulate-parser/internal/version.Version=${VERSION} -X github.com/kjanat/articulate-parser/internal/version.BuildTime=${BUILD_TIME} -X github.com/kjanat/articulate-parser/internal/version.GitCommit=${GIT_COMMIT}" \ |
| 33 | + -o articulate-parser \ |
| 34 | + ./main.go |
| 35 | + |
| 36 | +# Development stage - uses Alpine for shell access |
| 37 | +FROM alpine:3.19 |
| 38 | + |
| 39 | +# Install minimal dependencies |
| 40 | +RUN apk add --no-cache ca-certificates tzdata |
| 41 | + |
| 42 | +# Copy the binary |
| 43 | +COPY --from=builder /app/articulate-parser /articulate-parser |
| 44 | + |
| 45 | +# Copy the non-root user configuration |
| 46 | +COPY --from=builder /etc/passwd /etc/passwd |
| 47 | + |
| 48 | +# Switch to non-root user |
| 49 | +USER appuser |
| 50 | + |
| 51 | +# Set the binary as entrypoint |
| 52 | +ENTRYPOINT ["/articulate-parser"] |
| 53 | + |
| 54 | +# Default command shows help |
| 55 | +CMD ["--help"] |
| 56 | + |
| 57 | +# Add labels for metadata |
| 58 | +LABEL org.opencontainers.image.title="Articulate Parser (Dev)" |
| 59 | +LABEL org.opencontainers.image.description="Development version of Articulate Parser with shell access" |
| 60 | +LABEL org.opencontainers.image.vendor="kjanat" |
| 61 | +LABEL org.opencontainers.image.licenses="MIT" |
| 62 | +LABEL org.opencontainers.image.source="https://github.com/kjanat/articulate-parser" |
| 63 | +LABEL org.opencontainers.image.documentation="https://github.com/kjanat/articulate-parser/blob/master/README.md" |
0 commit comments