mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-01-16 12:22:08 +01:00
Add Docker support and GitHub Container Registry CI workflow (#3)
* Add comprehensive Docker support with multi-stage builds * Set up GitHub Container Registry integration * Enhance CI/CD workflows with Docker build and push capabilities * Add --help and --version flags to main application * Update documentation with Docker usage examples * Implement security best practices for container deployment
This commit is contained in:
78
Dockerfile.dev
Normal file
78
Dockerfile.dev
Normal file
@ -0,0 +1,78 @@
|
||||
# Development Dockerfile with shell access
|
||||
# Uses Alpine instead of scratch for debugging
|
||||
|
||||
# Build stage - same as production
|
||||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
# Install git and ca-certificates (needed for fetching dependencies and HTTPS)
|
||||
RUN apk add --no-cache git ca-certificates tzdata file
|
||||
|
||||
# Create a non-root user
|
||||
RUN adduser -D -u 1000 appuser
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
# Disable CGO for a fully static binary
|
||||
# Use linker flags to reduce binary size and embed version info
|
||||
ARG VERSION=dev
|
||||
ARG BUILD_TIME
|
||||
ARG GIT_COMMIT
|
||||
# Docker buildx automatically provides these for multi-platform builds
|
||||
ARG BUILDPLATFORM
|
||||
ARG TARGETPLATFORM
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
|
||||
# Debug: Show build information
|
||||
RUN echo "Building for platform: $TARGETPLATFORM (OS: $TARGETOS, Arch: $TARGETARCH, Variant: $TARGETVARIANT)" \
|
||||
&& echo "Build platform: $BUILDPLATFORM" \
|
||||
&& echo "Go version: $(go version)"
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
|
||||
-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}" \
|
||||
-o articulate-parser \
|
||||
./main.go
|
||||
|
||||
# Verify the binary architecture
|
||||
RUN file /app/articulate-parser || echo "file command not available"
|
||||
|
||||
# Development stage - uses Alpine for shell access
|
||||
FROM alpine:3.21.3
|
||||
|
||||
# Install minimal dependencies
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
# Copy the binary
|
||||
COPY --from=builder /app/articulate-parser /articulate-parser
|
||||
|
||||
# Copy the non-root user configuration
|
||||
COPY --from=builder /etc/passwd /etc/passwd
|
||||
|
||||
# Switch to non-root user
|
||||
USER appuser
|
||||
|
||||
# Set the binary as entrypoint
|
||||
ENTRYPOINT ["/articulate-parser"]
|
||||
|
||||
# Default command shows help
|
||||
CMD ["--help"]
|
||||
|
||||
# Add labels for metadata
|
||||
LABEL org.opencontainers.image.title="Articulate Parser (Dev)"
|
||||
LABEL org.opencontainers.image.description="Development version of Articulate Parser with shell access"
|
||||
LABEL org.opencontainers.image.vendor="kjanat"
|
||||
LABEL org.opencontainers.image.licenses="MIT"
|
||||
LABEL org.opencontainers.image.source="https://github.com/kjanat/articulate-parser"
|
||||
LABEL org.opencontainers.image.documentation="https://github.com/kjanat/articulate-parser/blob/master/DOCKER.md"
|
||||
Reference in New Issue
Block a user