generated from keploy/template
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reduce image size from 1GB to 29MB (#94)
* 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
Showing
1 changed file
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |