mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-11 07:55:59 +08:00
fix: Fixed issue with install Mailserver failed (#9562)
Refs https://github.com/1Panel-dev/1Panel/issues/9539
This commit is contained in:
parent
a74c6dd522
commit
02cf2a80cb
3 changed files with 64 additions and 5 deletions
|
@ -1025,12 +1025,12 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
|
|||
errMsg string
|
||||
)
|
||||
if pullImages && appInstall.App.Type != "php" {
|
||||
projectName := strings.ToLower(appInstall.Name)
|
||||
//projectName := strings.ToLower(appInstall.Name)
|
||||
envByte, err := files.NewFileOp().GetContent(appInstall.GetEnvPath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
images, err := composeV2.GetDockerComposeImages(projectName, envByte, []byte(appInstall.DockerCompose))
|
||||
images, err := composeV2.GetImagesFromDockerCompose(envByte, []byte(appInstall.DockerCompose))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/compose-spec/compose-go/v2/loader"
|
||||
|
@ -152,3 +154,60 @@ func GetDockerComposeImages(projectName string, env, yml []byte) ([]string, erro
|
|||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func GetImagesFromDockerCompose(env, yml []byte) ([]string, error) {
|
||||
envVars, err := loadEnvFile(env)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load env failed: %v", err)
|
||||
}
|
||||
|
||||
var compose ComposeProject
|
||||
if err := yaml.Unmarshal(yml, &compose); err != nil {
|
||||
return nil, fmt.Errorf("parse docker-compose file failed: %v", err)
|
||||
}
|
||||
|
||||
var images []string
|
||||
for _, service := range compose.Services {
|
||||
if service.Image != "" {
|
||||
resolvedImage := replaceEnvVars(service.Image, envVars)
|
||||
images = append(images, resolvedImage)
|
||||
}
|
||||
}
|
||||
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func loadEnvFile(env []byte) (map[string]string, error) {
|
||||
envVars := make(map[string]string)
|
||||
|
||||
scanner := bufio.NewScanner(bytes.NewReader(env))
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.TrimSpace(parts[1])
|
||||
value = strings.Trim(value, `"'`)
|
||||
envVars[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return envVars, scanner.Err()
|
||||
}
|
||||
|
||||
func replaceEnvVars(input string, envVars map[string]string) string {
|
||||
re := regexp.MustCompile(`\$\{([^}]+)\}`)
|
||||
|
||||
return re.ReplaceAllStringFunc(input, func(match string) string {
|
||||
varName := match[2 : len(match)-1]
|
||||
if value, exists := envVars[varName]; exists {
|
||||
return value
|
||||
}
|
||||
return match
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
</template>
|
||||
<el-tag size="small" :type="getType(statusItem)" round effect="light">
|
||||
<span class="flx-align-center">
|
||||
{{ $t('commons.status.' + statusItem) }}
|
||||
<span v-if="statusItem != ''">{{ $t('commons.status.' + statusItem) }}</span>
|
||||
<el-icon v-if="loadingIcon(statusItem)" class="is-loading">
|
||||
<Loading />
|
||||
</el-icon>
|
||||
|
@ -15,14 +15,14 @@
|
|||
<span v-else>
|
||||
<el-tag size="small" :type="getType(statusItem)" round effect="light" v-if="!operate">
|
||||
<span class="flx-align-center">
|
||||
{{ $t('commons.status.' + statusItem) }}
|
||||
<span v-if="statusItem != ''">{{ $t('commons.status.' + statusItem) }}</span>
|
||||
<el-icon v-if="loadingIcon(statusItem)" class="is-loading">
|
||||
<Loading />
|
||||
</el-icon>
|
||||
</span>
|
||||
</el-tag>
|
||||
<el-button size="small" v-else :type="getType(statusItem)" plain round>
|
||||
{{ $t('commons.status.' + statusItem) }}
|
||||
<span v-if="statusItem != ''">{{ $t('commons.status.' + statusItem) }}</span>
|
||||
<el-icon v-if="loadingIcon(statusItem)" class="is-loading">
|
||||
<Loading />
|
||||
</el-icon>
|
||||
|
|
Loading…
Add table
Reference in a new issue