maps-service/Containerfile

37 lines
807 B
Plaintext
Raw Normal View History

2024-12-12 20:15:56 +00:00
# Stage 1: Build
2024-12-12 21:12:21 +00:00
FROM docker.io/golang:1.23 AS builder
2024-12-12 20:15:56 +00:00
# Set the working directory in the container
WORKDIR /app
# Copy go.mod and go.sum files
COPY go.mod go.sum ./
# Download dependencies
2024-12-12 21:12:21 +00:00
RUN --mount=type=secret,id=netrc,dst=/root/.netrc go mod download
2024-12-12 20:15:56 +00:00
# Copy the entire project
COPY . .
# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o service ./cmd/maps-service/service.go
# Stage 2: Run
2024-12-11 01:03:18 +00:00
FROM alpine
2024-12-12 20:15:56 +00:00
# Set up a non-root user for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# Set the working directory in the container
WORKDIR /home/appuser
# Copy the built application from the builder stage
COPY --from=builder /app/service .
# Expose application port (adjust if needed)
EXPOSE 8081
# Command to run the application
CMD ["./service"]