diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e75e20a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,54 @@ +# Binaries +tclp +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool +*.out + +# Dependency directories +vendor/ + +# Go workspace file +go.work + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Git +.git/ +.gitignore + +# Docker +Dockerfile* +.dockerignore + +# Documentation +README.md +*.md + +# Logs +*.log + +# Temporary files +tmp/ +temp/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..60a0292 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +# Build stage +FROM golang:1.24.1-alpine AS builder + +# Install build dependencies +RUN apk add --no-cache git ca-certificates tzdata + +# Set working directory +WORKDIR /app + +# Copy go mod files first for better caching +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy source code +COPY . . + +# Build the application +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tclp ./cmd + +# Runtime stage +FROM alpine:3.19 + +# Install runtime dependencies +RUN apk --no-cache add ca-certificates tzdata + +# Create non-root user +RUN addgroup -g 1001 -S appgroup && \ + adduser -u 1001 -S appuser -G appgroup + +# Set working directory +WORKDIR /app + +# Copy binary from builder stage +COPY --from=builder /app/tclp . + +# Create directories for configuration and certificates +RUN mkdir -p /app/config /app/certs && \ + chown -R appuser:appgroup /app + +# Switch to non-root user +USER appuser + +# Expose the default gRPC port +EXPOSE 9000 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD nc -z localhost 9000 || exit 1 + +# Default command +ENTRYPOINT ["./tclp"] +CMD ["--config", "/app/config/config.yaml"]