-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (43 loc) · 1.63 KB
/
Dockerfile
File metadata and controls
60 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# --- Build Stage ---
# Use the official Go image as a builder
FROM golang:1.24-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Install build tools and dependencies
RUN apk add --no-cache gcc musl-dev
# Copy go.mod and go.sum files to download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the application, creating a static binary
RUN CGO_ENABLED=0 GOOS=linux go build -o /ms-ticketing ./main.go
# --- Final Stage ---
# Use a minimal, non-root image for the final container
FROM alpine:3.18
# Install CA certificates, curl for health checks, and Redis CLI for debugging
RUN apk add --no-cache ca-certificates tzdata redis curl
# Create a non-root user to run the application
RUN adduser -D -H -h /app appuser
# Create directories for the application
RUN mkdir -p /app/logs /app/migrations && chown -R appuser:appuser /app
# Copy the built binary from the builder stage
COPY --from=builder /ms-ticketing /app/ms-ticketing
# Copy migration files to the container
COPY migrations/ /app/migrations/
# Set the working directory
WORKDIR /app
# Set environment variables for migrations
ENV AUTO_MIGRATE=true
ENV MIGRATIONS_DIR=/app/migrations
ENV SEED_DATA=false
# Switch to non-root user for security
USER appuser
# Expose the application port
EXPOSE 8084
# Add the health check instruction for port 8084
# NOTE: Update '/health' to your Go application's actual health endpoint.
HEALTHCHECK --interval=30s --timeout=10s --retries=5 \
CMD curl -f http://localhost:8084/api/order/health || exit 1
# Set the command to run the application
CMD ["/app/ms-ticketing"]