44 lines
815 B
Docker
44 lines
815 B
Docker
# Build stage
|
|
FROM golang:1.24-alpine AS builder
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy go.mod and go.sum files
|
|
COPY go.mod go.sum ./
|
|
|
|
# Download dependencies
|
|
RUN go mod download
|
|
|
|
# Copy the source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o member-console .
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
# Create a non-root user and group
|
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Copy the binary from the builder stage
|
|
COPY --from=builder /app/member-console .
|
|
|
|
# Set environment variables
|
|
ENV PORT=8080 \
|
|
ENV=production
|
|
|
|
# Expose the port the app runs on
|
|
EXPOSE 8080
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Command to run the application
|
|
ENTRYPOINT ["/app/member-console"]
|
|
CMD ["start"]
|