From b7cda1d2f18ce3de4cef3e0461fc1e5a8748d48b Mon Sep 17 00:00:00 2001
From: ssongliu <73214554+ssongliu@users.noreply.github.com>
Date: Wed, 14 Jun 2023 23:26:13 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=B9=E5=99=A8=E5=88=9B=E5=BB=BA?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=20CPU=20=E6=9D=83=E9=87=8D=E8=AE=BE=E7=BD=AE?=
=?UTF-8?q?=20(#1377)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/dto/container.go | 1 +
backend/app/service/container.go | 3 +++
frontend/src/lang/modules/en.ts | 3 +++
frontend/src/lang/modules/zh.ts | 2 ++
frontend/src/views/container/container/create/index.vue | 9 ++++++++-
5 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/backend/app/dto/container.go b/backend/app/dto/container.go
index cc970b98e..c37fb8275 100644
--- a/backend/app/dto/container.go
+++ b/backend/app/dto/container.go
@@ -36,6 +36,7 @@ type ContainerCreate struct {
PublishAllPorts bool `json:"publishAllPorts"`
ExposedPorts []PortHelper `json:"exposedPorts"`
Cmd []string `json:"cmd"`
+ CPUShares int64 `josn:"cpuShares"`
NanoCPUs int64 `json:"nanoCPUs"`
Memory int64 `json:"memory"`
AutoRemove bool `json:"autoRemove"`
diff --git a/backend/app/service/container.go b/backend/app/service/container.go
index f3df901c2..2f01d2b1e 100644
--- a/backend/app/service/container.go
+++ b/backend/app/service/container.go
@@ -247,6 +247,9 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerCreate) error {
if req.NanoCPUs != 0 {
hostConf.NanoCPUs = req.NanoCPUs * 1000000000
}
+ if req.CPUShares != 0 {
+ hostConf.CPUShares = req.CPUShares
+ }
if req.Memory != 0 {
hostConf.Memory = req.Memory
}
diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts
index 9ec1d7ce1..7409689b0 100644
--- a/frontend/src/lang/modules/en.ts
+++ b/frontend/src/lang/modules/en.ts
@@ -483,6 +483,9 @@ const message = {
cleanLog: 'Clean log',
newName: 'New name',
source: 'Resource rate',
+ cpuShare: 'CPU Share',
+ cpuShareHelper:
+ 'The default CPU share for a container is 1024, which can be increased to give the container more CPU time.',
user: 'User',
command: 'Command',
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index f1f71eca7..a26349acd 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -490,6 +490,8 @@ const message = {
cleanLog: '清空日志',
newName: '新名称',
source: '资源使用率',
+ cpuShare: 'CPU 权重',
+ cpuShareHelper: '容器默认份额为 1024 个 CPU,增大可使当前容器获得更多的 CPU 时间',
user: '用户',
command: '命令',
diff --git a/frontend/src/views/container/container/create/index.vue b/frontend/src/views/container/container/create/index.vue
index 7cbcbfdbf..69c8971ae 100644
--- a/frontend/src/views/container/container/create/index.vue
+++ b/frontend/src/views/container/container/create/index.vue
@@ -81,6 +81,10 @@
{{ $t('container.autoRemove') }}
+
+
+ {{ $t('container.cpuShareHelper') }}
+
@@ -202,7 +206,7 @@