2024-09-13 22:18:42 +00:00
|
|
|
# Use a multi-stage build to create a minimal Docker image
|
|
|
|
|
|
|
|
# Stage 1: Build the Go application
|
|
|
|
FROM golang:1.23-alpine as builder
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy go.mod and go.sum files if you have them
|
2024-09-13 22:29:16 +00:00
|
|
|
COPY go.mod ./
|
2024-09-13 22:18:42 +00:00
|
|
|
|
|
|
|
# Download all dependencies
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
# Copy the source code into the container
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# Build the Go application
|
|
|
|
RUN go build -o confetti-api main.go
|
|
|
|
|
|
|
|
# Stage 2: Create a minimal image with the application binary
|
|
|
|
FROM alpine:latest
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
WORKDIR /root/
|
|
|
|
|
|
|
|
# Copy the binary from the builder stage
|
|
|
|
COPY --from=builder /app/confetti-api .
|
|
|
|
|
|
|
|
# Expose port 8080 for the application
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
# Command to run the application
|
|
|
|
CMD ["./confetti-api"]
|