From 671da4fe78f727b373e915dfc7a1067bf1b5c1ed Mon Sep 17 00:00:00 2001 From: ykadowak Date: Mon, 5 Jun 2023 05:27:14 +0000 Subject: [PATCH 1/8] install tools --- Makefile.d/tools.mk | 2 +- dockers/dev/Dockerfile | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile.d/tools.mk b/Makefile.d/tools.mk index ed71eaf1a1..fde43ebf64 100644 --- a/Makefile.d/tools.mk +++ b/Makefile.d/tools.mk @@ -49,7 +49,7 @@ $(GOPATH)/bin/golines: .PHONY: prettier/install prettier/install: $(BINDIR)/prettier $(BINDIR)/prettier: - type prettier || npm install -g prettier + type prettier || sudo npm install -g prettier .PHONY: reviewdog/install ## install reviewdog diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index bd761f5c5b..f8daa2659e 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -43,12 +43,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +USER vscode WORKDIR ${GOPATH}/src/github.com/vdaas/vald - COPY Makefile . COPY Makefile.d Makefile.d COPY versions versions +USER root RUN make ngt/install \ && make helm/install \ && make helm-docs/install \ @@ -65,6 +66,14 @@ RUN chown -R vscode:vscode "${GOPATH}" \ # mkdir for agent configuration install && mkdir -p /etc/server +USER vscode +RUN make proto/deps \ + && make golines/install \ + && make gofumpt/install \ + && make strictgoimports/install \ + && make goimports/install \ + && make prettier/install + # k9s installs the binary to the current user which is root for devcontainer # so change the current user to vscode to user afterwards USER vscode From 6e5cdc4a4270f9625465fed32bc0aa47c2a05417 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 05:19:28 +0000 Subject: [PATCH 2/8] Add sudo when removing /go/pkg because it's required some cases --- Makefile.d/dependencies.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.d/dependencies.mk b/Makefile.d/dependencies.mk index c9fc96612d..f191685ca3 100644 --- a/Makefile.d/dependencies.mk +++ b/Makefile.d/dependencies.mk @@ -44,16 +44,16 @@ go/download: .PHONY: go/deps ## install Go package dependencies go/deps: + sudo rm -rf /go/pkg rm -rf $(ROOTDIR)/vendor \ - /go/pkg \ $(GOCACHE) \ $(ROOTDIR)/go.sum \ $(ROOTDIR)/go.mod cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod GOPRIVATE=$(GOPRIVATE) go mod tidy go clean -cache -modcache -testcache -i -r + sudo rm -rf /go/pkg rm -rf $(ROOTDIR)/vendor \ - /go/pkg \ $(GOCACHE) \ $(ROOTDIR)/go.sum \ $(ROOTDIR)/go.mod From 98a93e38589eef6e7c94675a019ca165681990d2 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 05:53:08 +0000 Subject: [PATCH 3/8] refactor --- Makefile.d/tools.mk | 2 +- dockers/dev/Dockerfile | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Makefile.d/tools.mk b/Makefile.d/tools.mk index fde43ebf64..ed71eaf1a1 100644 --- a/Makefile.d/tools.mk +++ b/Makefile.d/tools.mk @@ -49,7 +49,7 @@ $(GOPATH)/bin/golines: .PHONY: prettier/install prettier/install: $(BINDIR)/prettier $(BINDIR)/prettier: - type prettier || sudo npm install -g prettier + type prettier || npm install -g prettier .PHONY: reviewdog/install ## install reviewdog diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index f8daa2659e..7554ba5013 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -43,13 +43,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -USER vscode WORKDIR ${GOPATH}/src/github.com/vdaas/vald COPY Makefile . COPY Makefile.d Makefile.d COPY versions versions -USER root RUN make ngt/install \ && make helm/install \ && make helm-docs/install \ @@ -59,24 +57,24 @@ RUN make ngt/install \ && make reviewdog/install \ && make protobuf/install \ && make kubectl/install \ - && make k3d/install + && make k3d/install \ + && make prettier/install # change GOPATH owner to vscode to run commands as user vscode without root permission RUN chown -R vscode:vscode "${GOPATH}" \ # mkdir for agent configuration install && mkdir -p /etc/server +# Commands below are executed as user vscode USER vscode RUN make proto/deps \ && make golines/install \ && make gofumpt/install \ && make strictgoimports/install \ - && make goimports/install \ - && make prettier/install + && make goimports/install # k9s installs the binary to the current user which is root for devcontainer # so change the current user to vscode to user afterwards -USER vscode SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN curl -sS https://webinstall.dev/k9s | bash From eef677ff1039d7267bda8583aa7e92e99ca8c0ab Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 06:21:32 +0000 Subject: [PATCH 4/8] install buf --- dockers/dev/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 7554ba5013..cd8ddf2e6d 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -58,7 +58,8 @@ RUN make ngt/install \ && make protobuf/install \ && make kubectl/install \ && make k3d/install \ - && make prettier/install + && make prettier/install \ + && make buf/install # change GOPATH owner to vscode to run commands as user vscode without root permission RUN chown -R vscode:vscode "${GOPATH}" \ From d469b4c65600a56cef6f1919ac077037a6be736c Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 08:17:48 +0000 Subject: [PATCH 5/8] login as root for simplicity --- .devcontainer/devcontainer.json | 3 ++- Makefile.d/dependencies.mk | 4 ++-- dockers/dev/Dockerfile | 17 +++-------------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e63343f2e8..7a864fc303 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,7 +10,8 @@ "moby": "true" } }, + "remoteUser": "root", "postCreateCommand": "go version", - "postAttachCommand": "sudo ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml", + "postAttachCommand": "mkdir -p /etc/server && ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml", "appPort": "3000:3000" } diff --git a/Makefile.d/dependencies.mk b/Makefile.d/dependencies.mk index f191685ca3..c9fc96612d 100644 --- a/Makefile.d/dependencies.mk +++ b/Makefile.d/dependencies.mk @@ -44,16 +44,16 @@ go/download: .PHONY: go/deps ## install Go package dependencies go/deps: - sudo rm -rf /go/pkg rm -rf $(ROOTDIR)/vendor \ + /go/pkg \ $(GOCACHE) \ $(ROOTDIR)/go.sum \ $(ROOTDIR)/go.mod cp $(ROOTDIR)/hack/go.mod.default $(ROOTDIR)/go.mod GOPRIVATE=$(GOPRIVATE) go mod tidy go clean -cache -modcache -testcache -i -r - sudo rm -rf /go/pkg rm -rf $(ROOTDIR)/vendor \ + /go/pkg \ $(GOCACHE) \ $(ROOTDIR)/go.sum \ $(ROOTDIR)/go.mod diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index cd8ddf2e6d..3e8bda8951 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -47,6 +47,9 @@ WORKDIR ${GOPATH}/src/github.com/vdaas/vald COPY Makefile . COPY Makefile.d Makefile.d COPY versions versions +COPY hack/go.mod.default hack/go.mod.default + +RUN make deps RUN make ngt/install \ && make helm/install \ @@ -58,22 +61,8 @@ RUN make ngt/install \ && make protobuf/install \ && make kubectl/install \ && make k3d/install \ - && make prettier/install \ && make buf/install -# change GOPATH owner to vscode to run commands as user vscode without root permission -RUN chown -R vscode:vscode "${GOPATH}" \ - # mkdir for agent configuration install - && mkdir -p /etc/server - -# Commands below are executed as user vscode -USER vscode -RUN make proto/deps \ - && make golines/install \ - && make gofumpt/install \ - && make strictgoimports/install \ - && make goimports/install - # k9s installs the binary to the current user which is root for devcontainer # so change the current user to vscode to user afterwards SHELL ["/bin/bash", "-o", "pipefail", "-c"] From 4e7232343bc26eb2687d77fea7d610889afb22b5 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 08:28:51 +0000 Subject: [PATCH 6/8] refactor dockerfile --- dockers/dev/Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 3e8bda8951..33c3635983 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -49,9 +49,8 @@ COPY Makefile.d Makefile.d COPY versions versions COPY hack/go.mod.default hack/go.mod.default -RUN make deps - -RUN make ngt/install \ +RUN make deps \ + && make ngt/install \ && make helm/install \ && make helm-docs/install \ && make valdcli/install \ @@ -63,8 +62,6 @@ RUN make ngt/install \ && make k3d/install \ && make buf/install -# k9s installs the binary to the current user which is root for devcontainer -# so change the current user to vscode to user afterwards SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN curl -sS https://webinstall.dev/k9s | bash From 012325aa8392984dc62e35bbe8efee176545bda0 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Fri, 30 Jun 2023 08:50:25 +0000 Subject: [PATCH 7/8] refactor --- Makefile.d/tools.mk | 12 ++++++++++++ dockers/dev/Dockerfile | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile.d/tools.mk b/Makefile.d/tools.mk index ed71eaf1a1..bebd846f3b 100644 --- a/Makefile.d/tools.mk +++ b/Makefile.d/tools.mk @@ -92,3 +92,15 @@ $(BINDIR)/buf: "https://github.com/bufbuild/buf/releases/download/$(BUF_VERSION)/buf-$(shell uname -s)-$(shell uname -m)" \ -o "${BINDIR}/buf" && \ chmod +x "${BINDIR}/buf" + +.PHONY: k9s/install +k9s/install: $(GOPATH)/bin/k9s + +$(GOPATH)/bin/k9s: + $(call go-install, github.com/derailed/k9s) + +.PHONY: stern/install +stern/install: $(GOPATH)/bin/stern + +$(GOPATH)/bin/stern: + $(call go-install, github.com/stern/stern) diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 33c3635983..1828de9d21 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -60,9 +60,6 @@ RUN make deps \ && make protobuf/install \ && make kubectl/install \ && make k3d/install \ - && make buf/install - -SHELL ["/bin/bash", "-o", "pipefail", "-c"] -RUN curl -sS https://webinstall.dev/k9s | bash - -RUN go install github.com/stern/stern@latest + && make buf/install \ + && make k9s/install \ + && make stern/install From 3aca0cad2e59f713e14ef22b85e765f89e18450d Mon Sep 17 00:00:00 2001 From: ykadowak Date: Mon, 3 Jul 2023 05:08:14 +0000 Subject: [PATCH 8/8] Separate layers to optimize build time when adding new tools --- dockers/dev/Dockerfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dockers/dev/Dockerfile b/dockers/dev/Dockerfile index 1828de9d21..2ee838e6d3 100644 --- a/dockers/dev/Dockerfile +++ b/dockers/dev/Dockerfile @@ -49,6 +49,7 @@ COPY Makefile.d Makefile.d COPY versions versions COPY hack/go.mod.default hack/go.mod.default +# basic deps RUN make deps \ && make ngt/install \ && make helm/install \ @@ -58,8 +59,9 @@ RUN make deps \ && make golangci-lint/install \ && make reviewdog/install \ && make protobuf/install \ - && make kubectl/install \ - && make k3d/install \ + && make kubectl/install + +# additional deps +RUN make k3d/install \ && make buf/install \ - && make k9s/install \ - && make stern/install + && make k9s/install