Skip to content

Commit

Permalink
feat: use multi-stage build docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
YBR Dev committed Oct 6, 2024
1 parent c7db7d9 commit 7269040
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
FROM golang:alpine
RUN apk update && apk add --no-cache git
# Stage 1: Build Stage
FROM golang:alpine AS builder
RUN apk add --no-cache git
WORKDIR /app

# Copy go.mod to cache dependencies
COPY go.mod ./
RUN go mod download

# Copy the rest of the source code
COPY . .
RUN go mod tidy

# Build the Go binary and name it 'binary'
RUN go build -o binary

# Stage 2: Minimal Runtime Stage
FROM alpine:latest
WORKDIR /app

# Copy the binary from the builder stage
COPY --from=builder /app/binary /app/binary

# Copy the SSL certificate and key files into the image
COPY server.crt server.key /app/

# Set a non-root user for security
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

# Expose port 443 for HTTPS
EXPOSE 443

# Set the entry point to run the 'binary' binary
ENTRYPOINT ["/app/binary"]

0 comments on commit 7269040

Please sign in to comment.