2024-10-07 15:28:16 +00:00
|
|
|
# Stage 1: Build the Go binary
|
|
|
|
FROM golang:1.17-alpine AS builder
|
2024-10-05 01:10:35 +00:00
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Install build tools and SQLite development libraries
|
|
|
|
RUN apk add --no-cache gcc musl-dev sqlite-dev
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
2024-10-05 01:10:35 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Copy the Go modules files and download dependencies
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
# Copy the rest of the application source code
|
2024-10-05 01:10:35 +00:00
|
|
|
COPY . .
|
|
|
|
|
|
|
|
# Build the Go application
|
2024-10-07 15:28:16 +00:00
|
|
|
RUN go build -o boxes-api
|
|
|
|
|
|
|
|
# Stage 2: Create a minimal image with the Go binary
|
|
|
|
FROM alpine:latest
|
|
|
|
|
|
|
|
# Install necessary runtime dependencies
|
|
|
|
RUN apk add --no-cache ca-certificates
|
|
|
|
|
|
|
|
# Set the working directory inside the container
|
|
|
|
WORKDIR /app
|
2024-10-05 01:10:35 +00:00
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Copy the binary from the builder stage
|
|
|
|
COPY --from=builder /app/boxes-api .
|
2024-10-05 01:10:35 +00:00
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Copy any other necessary files (e.g., configuration files)
|
|
|
|
# COPY --from=builder /app/config.yaml .
|
2024-10-05 01:10:35 +00:00
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Expose the port your app listens on
|
2024-10-05 01:10:35 +00:00
|
|
|
EXPOSE 8080
|
|
|
|
|
2024-10-07 15:28:16 +00:00
|
|
|
# Command to run the executable
|
|
|
|
CMD ["./boxes-api"]
|