-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (33 loc) · 1.12 KB
/
Dockerfile
File metadata and controls
44 lines (33 loc) · 1.12 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
# --- Build Stage ---
# Use a specific Go version for reproducible builds
FROM golang:1.25-alpine AS builder
# Set the working directory
WORKDIR /workspace
# Copy the entire workspace (required for go.work to function)
COPY go.work go.work
COPY go.work.sum go.work.sum
COPY shared/ shared/
COPY account/ account/
COPY fraud/ fraud/
COPY notification/ notification/
COPY payment/ payment/
COPY reporting/ reporting/
# Accept build argument for which service to build
ARG SERVICE
# Build the application, creating a static binary
WORKDIR /workspace/${SERVICE}
# CGO_ENABLED=0 is important for creating a static binary that can run in a minimal image like alpine
RUN CGO_ENABLED=0 go build -o /app/main ./cmd
# --- Final Stage ---
# Use a minimal, non-root image for the final stage
FROM alpine:latest
# It's good practice to run as a non-root user for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
WORKDIR /home/appuser/app
# Copy only the compiled executable from the builder stage
COPY --from=builder /app/main .
# Expose the port the application runs on
EXPOSE 8080
# Run the executable
CMD ["./main"]