-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.migrate
More file actions
41 lines (29 loc) · 1006 Bytes
/
Dockerfile.migrate
File metadata and controls
41 lines (29 loc) · 1006 Bytes
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
# --- 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 migration tool, creating a static binary
RUN CGO_ENABLED=0 GOOS=linux go build -o /migrate ./migrate.go
# --- Final Stage ---
# Use a minimal, non-root image for the final container
FROM alpine:3.18
# Install CA certificates for HTTPS connections
RUN apk add --no-cache ca-certificates tzdata
# Create a non-root user to run the application
RUN adduser -D -H -h /app appuser
# Copy the built binary from the builder stage
COPY --from=builder /migrate /app/migrate
# Set the working directory
WORKDIR /app
# Switch to non-root user for security
USER appuser
# Run the migration
ENTRYPOINT ["/app/migrate"]