From 6326c4db48a7c9e3445cf78a5f7086c7719f3ecf Mon Sep 17 00:00:00 2001 From: Sedky Date: Wed, 1 Jul 2020 15:24:45 -0400 Subject: [PATCH 1/4] create new dockerfile, 53mb large, tested with helm chart --- docker/controller/Dockerfile | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/docker/controller/Dockerfile b/docker/controller/Dockerfile index 8e0f669..15775ce 100644 --- a/docker/controller/Dockerfile +++ b/docker/controller/Dockerfile @@ -1,8 +1,35 @@ -FROM centos +# Start from the latest golang base image +FROM golang:latest as builder + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy go mod and sum files +COPY go.mod go.sum ./ + +# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed +RUN go mod download + +# Copy the source from the current directory to the Working Directory inside the container +COPY . . + +# Build the Go app +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tyk-k8s . -RUN mkdir -p /opt/tyk-k8s -COPY files/build/tyk-k8s /opt/tyk-k8s/tyk-k8s +######## Start a new stage from scratch ####### +FROM alpine:latest + +RUN apk --no-cache add ca-certificates + +RUN mkdir -p /opt/tyk-k8s WORKDIR /opt/tyk-k8s -CMD ["/opt/goproxy/tyk-k8s", "start"] \ No newline at end of file +# Copy the Pre-built binary file from the previous stage +COPY --from=builder /app/tyk-k8s /opt/tyk-k8s/tyk-k8s + +# Expose port 8080 to the outside world +EXPOSE 8080 + +# Command to run the executable +CMD ["./tyk-k8s", "start"] \ No newline at end of file From edd2be8a211eab4324757cb1d5d5594ec2fb78b5 Mon Sep 17 00:00:00 2001 From: Sedky Date: Wed, 1 Jul 2020 15:30:42 -0400 Subject: [PATCH 2/4] don't need to expose port --- docker/controller/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker/controller/Dockerfile b/docker/controller/Dockerfile index 15775ce..51144eb 100644 --- a/docker/controller/Dockerfile +++ b/docker/controller/Dockerfile @@ -28,8 +28,5 @@ WORKDIR /opt/tyk-k8s # Copy the Pre-built binary file from the previous stage COPY --from=builder /app/tyk-k8s /opt/tyk-k8s/tyk-k8s -# Expose port 8080 to the outside world -EXPOSE 8080 - # Command to run the executable CMD ["./tyk-k8s", "start"] \ No newline at end of file From fee19a61b86ed3345ee44841857c58064ad1fd08 Mon Sep 17 00:00:00 2001 From: Sedky Date: Thu, 2 Jul 2020 09:37:32 -0400 Subject: [PATCH 3/4] switch and pin images for Dockerfile --- docker/controller/Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docker/controller/Dockerfile b/docker/controller/Dockerfile index 51144eb..965e233 100644 --- a/docker/controller/Dockerfile +++ b/docker/controller/Dockerfile @@ -1,5 +1,5 @@ # Start from the latest golang base image -FROM golang:latest as builder +FROM golang:1.13 as builder # Set the Current Working Directory inside the container WORKDIR /app @@ -18,9 +18,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tyk-k8s . ######## Start a new stage from scratch ####### -FROM alpine:latest - -RUN apk --no-cache add ca-certificates +FROM debian:buster-slim RUN mkdir -p /opt/tyk-k8s WORKDIR /opt/tyk-k8s @@ -28,5 +26,6 @@ WORKDIR /opt/tyk-k8s # Copy the Pre-built binary file from the previous stage COPY --from=builder /app/tyk-k8s /opt/tyk-k8s/tyk-k8s -# Command to run the executable -CMD ["./tyk-k8s", "start"] \ No newline at end of file +ENTRYPOINT ["./tyk-k8s"] + +CMD ["start"] \ No newline at end of file From 743ec3ad6972c1087c5fe14fe92f08a78aa60abb Mon Sep 17 00:00:00 2001 From: Sedky Date: Thu, 2 Jul 2020 13:26:36 -0400 Subject: [PATCH 4/4] uncomplexify the build command --- docker/controller/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/controller/Dockerfile b/docker/controller/Dockerfile index 965e233..36af0c5 100644 --- a/docker/controller/Dockerfile +++ b/docker/controller/Dockerfile @@ -14,7 +14,7 @@ RUN go mod download COPY . . # Build the Go app -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o tyk-k8s . +RUN CGO_ENABLED=0 go build -o tyk-k8s . ######## Start a new stage from scratch #######