Skip to content

Commit e551ff9

Browse files
committed
chore: Modify orchestration environment variable style
1 parent 2546809 commit e551ff9

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

agent/app/dto/container.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ type ComposeInfo struct {
261261
Workdir string `json:"workdir"`
262262
Path string `json:"path"`
263263
Containers []ComposeContainer `json:"containers"`
264-
Env []string `json:"env"`
264+
Env string `json:"env"`
265265
}
266266
type ComposeContainer struct {
267267
ContainerID string `json:"containerID"`
@@ -271,13 +271,13 @@ type ComposeContainer struct {
271271
Ports []string `json:"ports"`
272272
}
273273
type ComposeCreate struct {
274-
TaskID string `json:"taskID"`
275-
Name string `json:"name"`
276-
From string `json:"from" validate:"required,oneof=edit path template"`
277-
File string `json:"file"`
278-
Path string `json:"path"`
279-
Template uint `json:"template"`
280-
Env []string `json:"env"`
274+
TaskID string `json:"taskID"`
275+
Name string `json:"name"`
276+
From string `json:"from" validate:"required,oneof=edit path template"`
277+
File string `json:"file"`
278+
Path string `json:"path"`
279+
Template uint `json:"template"`
280+
Env string `json:"env"`
281281
}
282282
type ComposeOperation struct {
283283
Name string `json:"name" validate:"required"`
@@ -287,10 +287,10 @@ type ComposeOperation struct {
287287
Force bool `josn:"force"`
288288
}
289289
type ComposeUpdate struct {
290-
Name string `json:"name" validate:"required"`
291-
Path string `json:"path" validate:"required"`
292-
Content string `json:"content" validate:"required"`
293-
Env []string `json:"env"`
290+
Name string `json:"name" validate:"required"`
291+
Path string `json:"path" validate:"required"`
292+
Content string `json:"content" validate:"required"`
293+
Env string `json:"env"`
294294
}
295295
type ComposeLogClean struct {
296296
Name string `json:"name" validate:"required"`

agent/app/service/container_compose.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,34 +410,22 @@ func loadEnv(list []dto.ComposeInfo) []dto.ComposeInfo {
410410
if err != nil {
411411
continue
412412
}
413-
lines := strings.Split(string(file), "\n")
414-
for _, line := range lines {
415-
lineItem := strings.TrimSpace(line)
416-
if len(lineItem) != 0 && !strings.HasPrefix(lineItem, "#") {
417-
list[i].Env = append(list[i].Env, lineItem)
418-
}
419-
}
413+
list[i].Env = string(file)
420414
}
421415
return list
422416
}
423417

424-
func newComposeEnv(pathItem string, env []string) error {
425-
if len(env) == 0 {
426-
return nil
427-
}
418+
func newComposeEnv(pathItem string, env string) error {
428419
envFilePath := path.Join(path.Dir(pathItem), ".env")
429420
file, err := os.OpenFile(envFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
430421
if err != nil {
431422
global.LOG.Errorf("failed to create env file: %v", err)
432423
return err
433424
}
434425
defer file.Close()
435-
for _, env := range env {
436-
envItem := strings.TrimSpace(env)
437-
if _, err := file.WriteString(fmt.Sprintf("%s\n", envItem)); err != nil {
438-
global.LOG.Errorf("failed to write env to file: %v", err)
439-
return err
440-
}
426+
if _, err := file.WriteString(env); err != nil {
427+
global.LOG.Errorf("failed to write env to file: %v", err)
428+
return err
441429
}
442430
return nil
443431
}

0 commit comments

Comments
 (0)