Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
varungupta authored and varungupta committed Sep 17, 2024
1 parent d12e1df commit 861d35f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 69 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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"]
34 changes: 1 addition & 33 deletions Dockerfile.gateway
Original file line number Diff line number Diff line change
@@ -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"]
34 changes: 1 addition & 33 deletions Dockerfile.users
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion docs/development/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 861d35f

Please sign in to comment.