From 50074d88892d3785a994b61e61f2b442801e0c7b Mon Sep 17 00:00:00 2001 From: awol2005ex Date: Thu, 31 Oct 2024 10:54:19 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E6=9B=BE=E5=8A=9F=E8=83=BD:=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=89=93=E5=BC=80pod=E7=9A=84=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E6=88=96=E8=80=85=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 16 +++-- .../workloads/batch-terminal/index.vue | 59 +++++++++++++++++++ .../src/business/workloads/pods/index.vue | 54 +++++++++++++++++ .../src/business/workloads/terminal/index.vue | 18 +++++- .../src/router/modules/batch-terminal.js | 16 +++++ web/terminal/package.json | 2 +- .../src/app/terminal/terminal.component.ts | 3 +- 7 files changed, 158 insertions(+), 10 deletions(-) create mode 100644 web/dashboard/src/business/workloads/batch-terminal/index.vue create mode 100644 web/dashboard/src/router/modules/batch-terminal.js diff --git a/Dockerfile b/Dockerfile index 32d95ab4..32836b65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# syntax = docker/dockerfile:experimental FROM node:18.10.0-alpine as stage-web-build RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN apk add --no-cache make @@ -12,11 +13,13 @@ WORKDIR /build/kubepi/web COPY . . -RUN make build_web +RUN --mount=type=cache,target=/build/kubepi/web/dashboard/node_modules,id=my_web_dashboard_module,sharing=locked --mount=type=cache,target=/build/kubepi/web/kubepi/node_modules,id=my_web_kubepi_module,sharing=locked --mount=type=cache,target=/build/kubepi/web/terminal/node_modules,id=my_web_terminal_module,sharing=locked make build_web RUN rm -fr web -FROM golang:1.22 as stage-bin-build +FROM golang:1.23.2-alpine3.20 as stage-bin-build +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories +RUN apk add --no-cache make ENV GOPROXY="https://goproxy.cn,direct" @@ -30,12 +33,12 @@ WORKDIR /build/kubepi/bin COPY --from=stage-web-build /build/kubepi/web . -RUN go mod download +RUN --mount=type=cache,target=/root/go,id=my_app_go_module,sharing=locked go mod download -RUN make build_gotty -RUN make build_bin +RUN --mount=type=cache,target=/root/go,id=my_app_go_module,sharing=locked make build_gotty +RUN --mount=type=cache,target=/root/go,id=my_app_go_module,sharing=locked make build_bin -FROM alpine:3.16 +FROM alpine:3.20 WORKDIR / @@ -57,6 +60,7 @@ RUN ARCH=$(uname -m) \ && tar zxvf fzf.tar.gz \ && rm -rf fzf.tar.gz \ && chmod -R 755 fzf \ + && sed -i 's/https\:\/\/github.com/https\:\/\/gh.llkk.cc\/https\:\/\/github.com/g' fzf/install \ && yes | fzf/install \ && ln -s fzf/bin/fzf /usr/local/bin/fzf \ && cd /tmp/ \ diff --git a/web/dashboard/src/business/workloads/batch-terminal/index.vue b/web/dashboard/src/business/workloads/batch-terminal/index.vue new file mode 100644 index 00000000..35bf3195 --- /dev/null +++ b/web/dashboard/src/business/workloads/batch-terminal/index.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/web/dashboard/src/business/workloads/pods/index.vue b/web/dashboard/src/business/workloads/pods/index.vue index 7784fe0b..687eba9c 100644 --- a/web/dashboard/src/business/workloads/pods/index.vue +++ b/web/dashboard/src/business/workloads/pods/index.vue @@ -22,6 +22,16 @@ @click="exportToXlsx()" icon="el-icon-download"> {{ $t("commons.button.export") }} + + + {{ $t("commons.button.terminal") }} + + + + {{ $t("commons.button.logs") }} + @@ -541,6 +551,50 @@ export default { //改变选项"是否全文搜索" OnIsFullTextSearchChange(val){ this.isFullTextSearch=val + }, + //批量打开终端 + batchTerminal(){ + if (this.selects.length > 0) { + + let routeUrl = this.$router.resolve({ + path: "/batch-terminal", + query: { + cluster: this.clusterName, + terminals: JSON.stringify( this.selects.map((item) => { + return { + cluster: this.clusterName, + namespace: item.metadata.namespace, + pod: item.metadata.name, + container: item.containers[0], + type: "terminal" + } + }) ) + } + }) + window.open(routeUrl.href, "_blank") + } + }, + //批量打开日志 + batchLogs(){ + if (this.selects.length > 0) { + + let routeUrl = this.$router.resolve({ + path: "/batch-terminal", + query: { + cluster: this.clusterName, + terminals: JSON.stringify( this.selects.map((item) => { + return { + cluster: this.clusterName, + namespace: item.metadata.namespace, + pod: item.metadata.name, + container: item.containers[0], + type: "log" + } + }) ) + } + }) + window.open(routeUrl.href, "_blank") + } } }, mounted () { diff --git a/web/dashboard/src/business/workloads/terminal/index.vue b/web/dashboard/src/business/workloads/terminal/index.vue index 85fd4751..7270dee9 100644 --- a/web/dashboard/src/business/workloads/terminal/index.vue +++ b/web/dashboard/src/business/workloads/terminal/index.vue @@ -43,7 +43,7 @@
- +
@@ -99,6 +99,7 @@ import { isLogin } from "@/api/auth" export default { name: "Terminal", components: { KoFormItem }, + props: ["params"], data() { return { height: "", @@ -248,14 +249,27 @@ export default { }) }, 5000) }, + reloadIframe(){ + this.$refs.myIframe.contentWindow.location.reload(true) + } }, created() { - this.terminal = { + if(!this.params) { + this.terminal = { cluster: this.$route.query.cluster, namespace: this.$route.query.namespace, pod: this.$route.query.pod, container: this.$route.query.container, type: this.$route.query.type, + } + }else{ + this.terminal = { + cluster: this.params.cluster, + namespace: this.params.namespace, + pod: this.params.pod, + container: this.params.container, + type: this.params.type, + } } this.terminal.url = this.getTerminalUrl() this.loadContainters() diff --git a/web/dashboard/src/router/modules/batch-terminal.js b/web/dashboard/src/router/modules/batch-terminal.js new file mode 100644 index 00000000..81ba20d6 --- /dev/null +++ b/web/dashboard/src/router/modules/batch-terminal.js @@ -0,0 +1,16 @@ +import batchterminals from "@/business/workloads/batch-terminal" + +const Terminal = { + path: "/batch-terminal?:terminals", + hidden: true, + component: batchterminals, + name: "BatchTerminal", + children: [ + { + path: "/batch-terminal", + component: () => import("@/business/workloads/batch-terminal"), + }, + ] +} + +export default Terminal diff --git a/web/terminal/package.json b/web/terminal/package.json index 1f4382bf..efd6ce5f 100644 --- a/web/terminal/package.json +++ b/web/terminal/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "ng serve --proxy-config proxy.config.json", + "start": "ng serve --proxy-config proxy.config.json --host 0.0.0.0", "build": "ng build --configuration production --aot", "watch": "ng build --watch --configuration development", "test": "ng test" diff --git a/web/terminal/src/app/terminal/terminal.component.ts b/web/terminal/src/app/terminal/terminal.component.ts index 2665e755..cc640744 100644 --- a/web/terminal/src/app/terminal/terminal.component.ts +++ b/web/terminal/src/app/terminal/terminal.component.ts @@ -117,13 +117,14 @@ export class TerminalComponent implements AfterViewInit { fontFamily: 'Consolas, "Courier New", monospace', bellStyle: 'sound', cursorBlink: true, - }); + }); const fitAddon = new FitAddon(); this.term.loadAddon(fitAddon); this.term.open(this.anchorRef.nativeElement); this.debouncedFit_ = debounce(() => { fitAddon.fit() this.cdr_.markForCheck(); + this.onTerminalResize(); }, 100) this.debouncedFit_(); window.addEventListener('resize', () => this.debouncedFit_()) From 6b844ee0c7af40a7f2b263f13a6b7fbfda664b2f Mon Sep 17 00:00:00 2001 From: awol2005ex Date: Sat, 9 Nov 2024 10:49:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD:=20nod?= =?UTF-8?q?e=E7=9A=84pod=E5=88=97=E8=A1=A8=E4=B8=AD=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=89=93=E5=BC=80pod=E7=9A=84=E7=BB=88=E7=AB=AF=E6=88=96?= =?UTF-8?q?=E8=80=85=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/detail/detail-node-pods.vue | 65 ++++++++++++++++++- .../src/components/layout/sidebar/Logo.vue | 2 +- .../src/components/layout/sidebar/Logo.vue | 4 +- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/web/dashboard/src/components/detail/detail-node-pods.vue b/web/dashboard/src/components/detail/detail-node-pods.vue index 5c213baa..d89a9c87 100644 --- a/web/dashboard/src/components/detail/detail-node-pods.vue +++ b/web/dashboard/src/components/detail/detail-node-pods.vue @@ -1,6 +1,18 @@