add: build artifacts
This commit is contained in:
47
Dockerfile
Normal file
47
Dockerfile
Normal file
@@ -0,0 +1,47 @@
|
||||
# Multi-stage build to create a minimal Docker image
|
||||
FROM golang:1.25.6-alpine AS builder
|
||||
|
||||
# Install git for go mod download
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Set 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 binary
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o mcgod ./cmd/mcgod
|
||||
|
||||
# Final stage
|
||||
FROM alpine:latest
|
||||
|
||||
# Install ca-certificates for HTTPS requests
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
# Create non-root user
|
||||
RUN adduser -D -u 10001 mcgod
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /home/mcgod
|
||||
|
||||
# Copy the binary from builder stage
|
||||
COPY --from=builder /app/mcgod .
|
||||
|
||||
# Copy the environment file
|
||||
COPY --from=builder /app/.env ./.env
|
||||
|
||||
# Change ownership to non-root user
|
||||
RUN chown -R mcgod:mcgod /home/mcgod
|
||||
|
||||
# Switch to non-root user
|
||||
USER mcgod
|
||||
|
||||
# Command to run the application
|
||||
CMD ["./mcgod"]
|
||||
Reference in New Issue
Block a user