From 861d35f5a3ad58998de3fe0d3159119e6decc033 Mon Sep 17 00:00:00 2001 From: varungupta Date: Tue, 17 Sep 2024 13:19:46 -0700 Subject: [PATCH] address code review comments --- Dockerfile | 12 ++++++++++-- Dockerfile.gateway | 34 +--------------------------------- Dockerfile.users | 34 +--------------------------------- docs/development/app/README.md | 2 +- 4 files changed, 13 insertions(+), 69 deletions(-) diff --git a/Dockerfile b/Dockerfile index 133730c7..9e65f3c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,11 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY cmd/controllers/main.go cmd/main.go +COPY cmd/ cmd/ COPY api/ api/ COPY pkg/controller/ pkg/controller/ +COPY pkg/users/ pkg/users/ +COPY pkg/plugins/ pkg/plugins/ COPY pkg/utils/ pkg/utils/ COPY pkg/cache/ pkg/cache/ COPY pkg/client/ pkg/client/ @@ -24,13 +26,19 @@ COPY pkg/client/ pkg/client/ # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/controllers/main.go + +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o users cmd/users/main.go + +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o plugins cmd/plugins/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details FROM gcr.io/distroless/static:nonroot WORKDIR / COPY --from=builder /workspace/manager . +COPY --from=builder /workspace/users . +COPY --from=builder /workspace/plugins . USER 65532:65532 ENTRYPOINT ["/manager"] diff --git a/Dockerfile.gateway b/Dockerfile.gateway index a97e778c..cfd193ac 100644 --- a/Dockerfile.gateway +++ b/Dockerfile.gateway @@ -1,36 +1,4 @@ ## Multistage build -FROM golang:1.22 as builder -ARG TARGETOS -ARG TARGETARCH - -WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -# Copy the go source -COPY cmd/plugins/main.go cmd/main.go -COPY api/ api/ -COPY pkg/plugins/ pkg/plugins/ -COPY pkg/utils/ pkg/utils/ -COPY pkg/cache/ pkg/cache/ -COPY pkg/client/ pkg/client/ - -# Build -# the GOARCH has not a default value to allow the binary be built according to the host where the command -# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO -# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, -# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o plugins cmd/main.go - -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot -WORKDIR / -COPY --from=builder /workspace/plugins . -USER 65532:65532 +FROM aibrix/controller-manager:nightly ENTRYPOINT ["/plugins"] \ No newline at end of file diff --git a/Dockerfile.users b/Dockerfile.users index 8996face..c041684b 100644 --- a/Dockerfile.users +++ b/Dockerfile.users @@ -1,36 +1,4 @@ ## Multistage build -FROM golang:1.22 as builder -ARG TARGETOS -ARG TARGETARCH - -WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -# Copy the go source -COPY cmd/users/main.go cmd/main.go -COPY api/ api/ -COPY pkg/users/ pkg/users/ -COPY pkg/utils/ pkg/utils/ -COPY pkg/cache/ pkg/cache/ -COPY pkg/client/ pkg/client/ - -# Build -# the GOARCH has not a default value to allow the binary be built according to the host where the command -# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO -# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, -# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o users cmd/main.go - -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot -WORKDIR / -COPY --from=builder /workspace/users . -USER 65532:65532 +FROM aibrix/controller-manager:nightly ENTRYPOINT ["/users"] \ No newline at end of file diff --git a/docs/development/app/README.md b/docs/development/app/README.md index ff103712..950dcdae 100644 --- a/docs/development/app/README.md +++ b/docs/development/app/README.md @@ -46,7 +46,7 @@ OR - if only want to test gateway plugins -docker build -t aibrix/plugins:v0.1.0 -f gateway.Dockerfile . +docker build -t aibrix/plugins:v0.1.0 -f Dockerfile.gateway . kind load docker-image aibrix/plugins:v0.1.0 kubectl -n aibrix-system apply -f docs/development/app/redis.yaml