From ed0d31dc937cdd33ddaa83cffe5af677b59bb8d7 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Mon, 9 Apr 2018 16:47:20 +0800 Subject: [PATCH] Dockerfile: Use multiple stage builds (#23) * suggestion: Support multiple stage builds Signed-off-by: Ce Gao * docs: Add requiremnet for docker build Signed-off-by: Ce Gao * manifests: Remove the args and use entrypoint Signed-off-by: Ce Gao * Dockerfile: Replace shell format with exec format Signed-off-by: Ce Gao --- docs/developer-guide.md | 4 ++++ .../vizier/suggestion/grid/deployment.yaml | 2 -- .../suggestion/hyperband/deployment.yaml | 2 -- .../vizier/suggestion/random/deployment.yaml | 2 -- suggestion/grid/Dockerfile | 18 +++++++++--------- suggestion/hyperband/Dockerfile | 18 +++++++++--------- suggestion/random/Dockerfile | 18 +++++++++--------- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/docs/developer-guide.md b/docs/developer-guide.md index 37ba3b43ab4..9f5ec1f26a2 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -1,5 +1,9 @@ # Developer Guide +## Requirements + +- Docker (17.05 or later.) + ## Build from source code You can build all images from source. diff --git a/manifests/vizier/suggestion/grid/deployment.yaml b/manifests/vizier/suggestion/grid/deployment.yaml index 1da794595eb..707f170ddf9 100644 --- a/manifests/vizier/suggestion/grid/deployment.yaml +++ b/manifests/vizier/suggestion/grid/deployment.yaml @@ -18,8 +18,6 @@ spec: containers: - name: vizier-suggestion-grid image: katib/suggestion-grid - args: - - './grid' ports: - name: api containerPort: 6789 diff --git a/manifests/vizier/suggestion/hyperband/deployment.yaml b/manifests/vizier/suggestion/hyperband/deployment.yaml index e7029953cbc..9f8d742e586 100644 --- a/manifests/vizier/suggestion/hyperband/deployment.yaml +++ b/manifests/vizier/suggestion/hyperband/deployment.yaml @@ -18,8 +18,6 @@ spec: containers: - name: vizier-suggestion-hyperband image: katib/suggestion-hyperband - args: - - './hyperband' ports: - name: api containerPort: 6789 diff --git a/manifests/vizier/suggestion/random/deployment.yaml b/manifests/vizier/suggestion/random/deployment.yaml index d575b110771..544b2431598 100644 --- a/manifests/vizier/suggestion/random/deployment.yaml +++ b/manifests/vizier/suggestion/random/deployment.yaml @@ -18,8 +18,6 @@ spec: containers: - name: vizier-suggestion-random image: katib/suggestion-random - args: - - './random' ports: - name: api containerPort: 6789 diff --git a/suggestion/grid/Dockerfile b/suggestion/grid/Dockerfile index a7a9636eded..1fda4746aa7 100644 --- a/suggestion/grid/Dockerfile +++ b/suggestion/grid/Dockerfile @@ -1,10 +1,10 @@ -FROM golang -RUN : && \ - go get google.golang.org/grpc && \ - : -ADD api $GOPATH/src/github.com/kubeflow/hp-tuning/api -ADD db $GOPATH/src/github.com/kubeflow/hp-tuning/db -ADD manager $GOPATH/src/github.com/kubeflow/hp-tuning/manager -ADD suggestion $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion -WORKDIR $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion/grid +FROM golang:alpine AS build-env +# The GOPATH in the image is /go. +ADD . /go/src/github.com/kubeflow/hp-tuning +WORKDIR /go/src/github.com/kubeflow/hp-tuning/suggestion/grid RUN go build -o grid + +FROM alpine:3.7 +WORKDIR /app +COPY --from=build-env /go/src/github.com/kubeflow/hp-tuning/suggestion/grid /app/ +ENTRYPOINT ["./grid"] diff --git a/suggestion/hyperband/Dockerfile b/suggestion/hyperband/Dockerfile index c40860d3857..eee2de9a93c 100644 --- a/suggestion/hyperband/Dockerfile +++ b/suggestion/hyperband/Dockerfile @@ -1,10 +1,10 @@ -FROM golang -RUN : && \ - go get google.golang.org/grpc && \ - : -ADD api $GOPATH/src/github.com/kubeflow/hp-tuning/api -ADD db $GOPATH/src/github.com/kubeflow/hp-tuning/db -ADD manager $GOPATH/src/github.com/kubeflow/hp-tuning/manager -ADD suggestion $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion -WORKDIR $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion/hyperband +FROM golang:alpine AS build-env +# The GOPATH in the image is /go. +ADD . /go/src/github.com/kubeflow/hp-tuning +WORKDIR /go/src/github.com/kubeflow/hp-tuning/suggestion/hyperband RUN go build -o hyperband + +FROM alpine:3.7 +WORKDIR /app +COPY --from=build-env /go/src/github.com/kubeflow/hp-tuning/suggestion/hyperband /app/ +ENTRYPOINT ["./hyperband"] diff --git a/suggestion/random/Dockerfile b/suggestion/random/Dockerfile index 76d4625c9d2..3fc89518d75 100644 --- a/suggestion/random/Dockerfile +++ b/suggestion/random/Dockerfile @@ -1,10 +1,10 @@ -FROM golang -RUN : && \ - go get google.golang.org/grpc && \ - : -ADD api $GOPATH/src/github.com/kubeflow/hp-tuning/api -ADD db $GOPATH/src/github.com/kubeflow/hp-tuning/db -ADD manager $GOPATH/src/github.com/kubeflow/hp-tuning/manager -ADD suggestion $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion -WORKDIR $GOPATH/src/github.com/kubeflow/hp-tuning/suggestion/random +FROM golang:alpine AS build-env +# The GOPATH in the image is /go. +ADD . /go/src/github.com/kubeflow/hp-tuning +WORKDIR /go/src/github.com/kubeflow/hp-tuning/suggestion/random RUN go build -o random + +FROM alpine:3.7 +WORKDIR /app +COPY --from=build-env /go/src/github.com/kubeflow/hp-tuning/suggestion/random /app/ +ENTRYPOINT ["./random"]