From 362b6bb729b5f5bd92f86d8c6e40df42371d9c3c Mon Sep 17 00:00:00 2001 From: Aaron3S <34506289+Aaron3S@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:40:20 +0800 Subject: [PATCH] =?UTF-8?q?build(docker):=20=E5=A2=9E=E5=8A=A0docker?= =?UTF-8?q?=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 1 + Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ Makefile | 6 ++++-- cmd/server/main.go | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..cf709889 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..61b8017e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM node:14-alpine as stage-web-build + +LABEL stage=stage-web-build + +RUN apk add make + +WORKDIR /build/ekko/web + +COPY . . + +RUN make build_web + + +FROM golang:1.16 as stage-bin-build + +ENV GOPROXY="https://goproxy.cn,direct" + +LABEL stage=stage-bin-build + +WORKDIR /build/ekko/bin + +COPY --from=stage-web-build /build/ekko/web . + +ENV GO111MODULE=on + +RUN go mod download + +RUN make build_all + +FROM alpine:3.14 + +WORKDIR / + +COPY --from=stage-bin-build /build/ekko/dist/usr /usr + +EXPOSE 2019 + +USER root + +CMD ["ekko-server"] diff --git a/Makefile b/Makefile index d1a0e6e4..510a91f6 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ GOARCH=$(shell go env GOARCH) GOOS=$(shell go env GOOS ) BASEPATH := $(shell pwd) -BUILDDIR=$(BASEPATH)/dist/bin +BUILDDIR=$(BASEPATH)/dist/usr/local/bin EKKODIR=$(BASEPATH)/web/ekko DASHBOARDDIR=$(BASEPATH)/web/dashboard TERMINALDIR=$(BASEPATH)/web/terminal @@ -13,7 +13,7 @@ TERMINALDIR=$(BASEPATH)/web/terminal MAIN= $(BASEPATH)/cmd/server/main.go -APP_NAME=ekko +APP_NAME=ekko-server GOPROXY="https://goproxy.cn,direct" @@ -28,3 +28,5 @@ build_web: build_web_ekko build_web_dashboard build_web_terminal build_bin: GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -trimpath -ldflags "-s -w" -o $(BUILDDIR)/$(GOOS)/$(GOARCH)/$(APP_NAME) $(MAIN) + +build_all: build_web build_bin diff --git a/cmd/server/main.go b/cmd/server/main.go index 708d9853..e292d7cf 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -29,7 +29,7 @@ func init() { } var RootCmd = &cobra.Command{ - Use: "ekko", + Use: "ekko-server", Short: "A dashboard for kubernetes", RunE: func(cmd *cobra.Command, args []string) error { server.EmbedWebDashboard = embedWebDashboard