Skip to content

Commit

Permalink
feat: reduce image size from 1GB to 29MB (#94)
Browse files Browse the repository at this point in the history
* feat: reduce image size from 1GB to 29MB

Signed-off-by: Narhari Motivaras <[email protected]>

* pinned alpine image version

Signed-off-by: Narhari Motivaras <[email protected]>

---------

Signed-off-by: Narhari Motivaras <[email protected]>
  • Loading branch information
narharim authored Jan 20, 2024
1 parent 132869d commit 6fec9fc
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions gin-mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
# Use an official Golang runtime as a parent image
FROM golang:1.20-bookworm
# === Build Stage ===
FROM golang:1.20-bookworm AS build-stage

# Set the working directory inside the container
# Set the working directory
WORKDIR /app

# Copy the local package files to the container's workspace
COPY . .
# Copy the Go module files and download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Build the Go application
RUN go build -o main .

# Expose port 8080
# Copy the contents of the current directory into the build container
COPY *.go ./

# Build the binary
RUN CGO_ENABLED=0 go build -o /main

# === Runtime Stage ===
FROM alpine:3.19

# Add groups and user to run the app and install dumb-init package
RUN addgroup -S keploy \
&& adduser -S keploy -G keploy -h /home/keploy \
&& mkdir -p /home/keploy/app \
&& chown -R keploy:keploy /home/keploy/app \
&& apk add --no-cache dumb-init \
&& rm -rf /var/cache/apk/*

# Change working directory
WORKDIR /home/keploy/app

# Copy the binary from build-stage and paste it in app directory
COPY --from=build-stage --chown=keploy:keploy /main /home/keploy/app/main

# Set the entrypoint
ENTRYPOINT ["dumb-init"]

# Set user
USER keploy

# Expose the port
EXPOSE 8080

# Command to run the Go application
CMD ["./main"]
# Run the binary
CMD ["./main"]

0 comments on commit 6fec9fc

Please sign in to comment.