mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-01-13 10:34:08 +08:00
feat: Image build supports setting build parameters (#10960)
Refs #10898
This commit is contained in:
parent
512ff23f19
commit
388458f759
15 changed files with 32 additions and 10 deletions
|
|
@ -28,6 +28,7 @@ type ImageBuild struct {
|
|||
Name string `json:"name" validate:"required"`
|
||||
Dockerfile string `json:"dockerfile" validate:"required"`
|
||||
Tags []string `json:"tags"`
|
||||
Args []string `json:"args"`
|
||||
}
|
||||
|
||||
type ImagePull struct {
|
||||
|
|
|
|||
|
|
@ -1256,6 +1256,16 @@ func stringsToMap(list []string) map[string]string {
|
|||
}
|
||||
return labelMap
|
||||
}
|
||||
func stringsToMap2(list []string) map[string]*string {
|
||||
var labelMap = make(map[string]*string)
|
||||
for _, label := range list {
|
||||
if strings.Contains(label, "=") {
|
||||
sps := strings.SplitN(label, "=", 2)
|
||||
labelMap[sps[0]] = &sps[1]
|
||||
}
|
||||
}
|
||||
return labelMap
|
||||
}
|
||||
|
||||
func calculateCPUPercentUnix(stats *container.StatsResponse) float64 {
|
||||
cpuPercent := 0.0
|
||||
|
|
|
|||
|
|
@ -228,6 +228,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) error {
|
|||
Tags: []string{req.Name},
|
||||
Remove: true,
|
||||
Labels: stringsToMap(req.Tags),
|
||||
BuildArgs: stringsToMap2(req.Args),
|
||||
}
|
||||
taskItem, err := task.NewTaskWithOps(req.Name, task.TaskBuild, task.TaskScopeImage, req.TaskID, 1)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ export namespace Container {
|
|||
name: string;
|
||||
dockerfile: string;
|
||||
tags: Array<string>;
|
||||
args: Array<string>;
|
||||
}
|
||||
export interface ImagePull {
|
||||
taskID: string;
|
||||
|
|
|
|||
|
|
@ -925,7 +925,7 @@ const message = {
|
|||
pull: 'Pull',
|
||||
path: 'Path',
|
||||
importImage: 'Import',
|
||||
build: 'Build',
|
||||
buildArgs: 'Build Arguments',
|
||||
imageBuild: 'Build',
|
||||
pathSelect: 'Path',
|
||||
label: 'Label',
|
||||
|
|
|
|||
|
|
@ -930,7 +930,7 @@ const message = {
|
|||
pull: 'Descargar',
|
||||
path: 'Ruta',
|
||||
importImage: 'Importar',
|
||||
build: 'Construir',
|
||||
buildArgs: 'Argumentos de Construcción',
|
||||
imageBuild: 'Construir',
|
||||
pathSelect: 'Ruta',
|
||||
label: 'Etiqueta',
|
||||
|
|
|
|||
|
|
@ -902,7 +902,7 @@ const message = {
|
|||
pull: '引く',
|
||||
path: 'パス',
|
||||
importImage: '輸入',
|
||||
build: '建てる',
|
||||
buildArgs: 'ビルド引数',
|
||||
imageBuild: '建てる',
|
||||
pathSelect: 'パス',
|
||||
label: 'ラベル',
|
||||
|
|
|
|||
|
|
@ -893,7 +893,7 @@ const message = {
|
|||
pull: '풀',
|
||||
path: '경로',
|
||||
importImage: '가져오기',
|
||||
build: '빌드',
|
||||
buildArgs: '빌드 인수',
|
||||
imageBuild: '이미지 빌드',
|
||||
pathSelect: '경로',
|
||||
label: '레이블',
|
||||
|
|
|
|||
|
|
@ -918,7 +918,7 @@ const message = {
|
|||
pull: 'Tarik',
|
||||
path: 'Laluan',
|
||||
importImage: 'Import',
|
||||
build: 'Bina',
|
||||
buildArgs: 'Argumen Binaan',
|
||||
imageBuild: 'Bina',
|
||||
pathSelect: 'Laluan',
|
||||
label: 'Label',
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ const message = {
|
|||
pull: 'Puxar',
|
||||
path: 'Caminho',
|
||||
importImage: 'Importar',
|
||||
build: 'Construir',
|
||||
buildArgs: 'Argumentos de Build',
|
||||
imageBuild: 'Construção de imagem',
|
||||
pathSelect: 'Caminho',
|
||||
label: 'Etiqueta',
|
||||
|
|
|
|||
|
|
@ -915,7 +915,7 @@ const message = {
|
|||
pull: 'Загрузить',
|
||||
path: 'Путь',
|
||||
importImage: 'Импорт',
|
||||
build: 'Сборка',
|
||||
buildArgs: 'Аргументы Сборки',
|
||||
imageBuild: 'Сборка',
|
||||
pathSelect: 'Путь',
|
||||
label: 'Метка',
|
||||
|
|
|
|||
|
|
@ -934,7 +934,7 @@ const message = {
|
|||
pull: 'Çek',
|
||||
path: 'Yol',
|
||||
importImage: 'İçe aktar',
|
||||
build: 'Oluştur',
|
||||
buildArgs: 'Derleme Argümanları',
|
||||
imageBuild: 'Oluştur',
|
||||
pathSelect: 'Yol',
|
||||
label: 'Etiket',
|
||||
|
|
|
|||
|
|
@ -886,7 +886,7 @@ const message = {
|
|||
path: '路徑',
|
||||
importImage: '匯入鏡像',
|
||||
imageBuild: '構建鏡像',
|
||||
build: '構建鏡像',
|
||||
buildArgs: '構建參數',
|
||||
pathSelect: '路徑選擇',
|
||||
label: '標籤',
|
||||
imageTag: '鏡像標籤',
|
||||
|
|
|
|||
|
|
@ -887,7 +887,7 @@ const message = {
|
|||
path: '路径',
|
||||
importImage: '导入镜像',
|
||||
imageBuild: '构建镜像',
|
||||
build: '构建镜像',
|
||||
buildArgs: '构建参数',
|
||||
pathSelect: '路径选择',
|
||||
label: '标签',
|
||||
imageTag: '镜像标签',
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@
|
|||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('container.buildArgs')">
|
||||
<el-input :placeholder="$t('container.tagHelper')" type="textarea" :rows="3" v-model="form.argStr" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('container.tag')">
|
||||
<el-input :placeholder="$t('container.tagHelper')" type="textarea" :rows="3" v-model="form.tagStr" />
|
||||
</el-form-item>
|
||||
|
|
@ -71,6 +74,8 @@ const form = reactive({
|
|||
name: '',
|
||||
tagStr: '',
|
||||
tags: [] as Array<string>,
|
||||
argStr: '',
|
||||
args: [] as Array<string>,
|
||||
});
|
||||
|
||||
const rules = reactive({
|
||||
|
|
@ -83,6 +88,7 @@ const acceptParams = async () => {
|
|||
form.from = 'path';
|
||||
form.dockerfile = '';
|
||||
form.tagStr = '';
|
||||
form.argStr = '';
|
||||
form.name = '';
|
||||
};
|
||||
const emit = defineEmits<{ (e: 'search'): void }>();
|
||||
|
|
@ -102,6 +108,9 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||
if (form.tagStr !== '') {
|
||||
form.tags = form.tagStr.split('\n');
|
||||
}
|
||||
if (form.argStr !== '') {
|
||||
form.args = form.argStr.split('\n');
|
||||
}
|
||||
form.taskID = newUUID();
|
||||
await imageBuild(form);
|
||||
openTaskLog(form.taskID);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue