first commit
This commit is contained in:
61
Dockerfile
Normal file
61
Dockerfile
Normal file
@@ -0,0 +1,61 @@
|
||||
# Build stage
|
||||
FROM golang:1.25.7-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Build-time args (passed from docker-compose build)
|
||||
ARG DB_URL
|
||||
ARG REDIS_URL
|
||||
ARG REDIS_HOST
|
||||
ARG REDIS_PORT
|
||||
ARG EMAIL_HOST
|
||||
ARG EMAIL_PORT
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Copy go mod and sum files
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download all dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source code
|
||||
COPY . .
|
||||
|
||||
# Build the application
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
|
||||
|
||||
# Final stage
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install necessary runtime dependencies
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
# Set runtime ENV from build args (1:1 usage)
|
||||
ENV DB_URL=${DB_URL}
|
||||
ENV REDIS_URL=${REDIS_URL}
|
||||
ENV REDIS_HOST=${REDIS_HOST}
|
||||
ENV REDIS_PORT=${REDIS_PORT}
|
||||
ENV EMAIL_HOST=${EMAIL_HOST}
|
||||
ENV EMAIL_PORT=${EMAIL_PORT}
|
||||
|
||||
# Copy the binary from builder
|
||||
COPY --from=builder /app/main .
|
||||
|
||||
|
||||
|
||||
# Copy docs and views for static serving if not mounted
|
||||
COPY docs ./docs
|
||||
COPY views ./views
|
||||
|
||||
# Create uploads directory
|
||||
RUN mkdir -p uploads
|
||||
|
||||
# Expose the port
|
||||
EXPOSE 8080
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./main"]
|
||||
Reference in New Issue
Block a user