starter-kit/Dockerfile
ulflow_phattt2901 d4c11c12be <chore>: Update port 3000 & update makefile
Change port and update makefile for Windows
2025-05-21 15:12:24 +07:00

61 lines
1.3 KiB
Docker

# Dockerfile
# Production-ready multi-stage build for server deployment
# Build stage
FROM golang:1.23-alpine AS builder
# Install necessary build tools
RUN apk add --no-cache git make gcc libc-dev
# Set working directory
WORKDIR /build
# Copy go.mod and go.sum files
COPY go.mod go.sum* ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Create the configs directory in the build context
RUN mkdir -p /build/configs && \
cp -r configs/* /build/configs/ 2>/dev/null || :
# Build the application with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /build/bin/app ./cmd/app
# Final stage
FROM alpine:3.19
# Add necessary runtime packages
RUN apk add --no-cache ca-certificates tzdata
# Set timezone
ENV TZ=Asia/Ho_Chi_Minh
# Create non-root user
RUN adduser -D -g '' appuser
# Create app directories
RUN mkdir -p /app/config /app/logs /app/storage
WORKDIR /app
# Copy binary and configs
COPY --from=builder /build/bin/app /app/
COPY --from=builder /build/configs /app/configs
# Set ownership
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 3000
# Set environment variable for production
ENV APP_ENV=production
# Command to run the application
ENTRYPOINT ["./app"]