From c7250311cfdc3062c73b5744240d5deb3ca53fbd Mon Sep 17 00:00:00 2001 From: Kris Crawford Date: Fri, 21 Jun 2024 17:38:01 -0400 Subject: [PATCH] Testing multi-stage build and single file docker image --- Dockerfile | 17 +++++++++-------- deployment.yaml | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 284341f..afb19f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ -# specify the base image to be used for the application -FROM golang:1.21.4-alpine +# Build stage +FROM golang:1.21.4-alpine AS builder -# create the working directory in the image WORKDIR /app -# copy Go modules and dependencies to image COPY go.mod ./ # download Go modules and dependencies @@ -13,11 +11,14 @@ RUN go mod download # copy all the Go files ending with .go extension COPY *.go ./ -# compile application -RUN go build -o /golang-http-header +RUN go build -o golang-http-header + +# Final stage +FROM scratch + +COPY --from=builder /app/golang-http-header / # network port at runtime EXPOSE 8000 -# execute when the container starts -CMD [ "/golang-http-header" ] \ No newline at end of file +CMD ["/golang-http-header"] \ No newline at end of file diff --git a/deployment.yaml b/deployment.yaml index e1bd342..9535a7c 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -22,7 +22,7 @@ spec: spec: containers: - name: http-header - image: git.kcrawford.net/kcrawford/golang-http-header:0.0.5 + image: git.kcrawford.net/kcrawford/golang-http-header:0.0.3 ports: - containerPort: 8000 -- 2.34.1