fix: 解决应用一直安装中的 BUG (#522)

This commit is contained in:
zhengkunwang223 2023-04-06 18:32:16 +08:00 committed by GitHub
parent e3b542665d
commit e452dfdb1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View file

@ -316,7 +316,7 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
if err := upAppPre(app, appInstall); err != nil { if err := upAppPre(app, appInstall); err != nil {
return nil, err return nil, err
} }
go upApp(ctx, appInstall.GetComposePath(), appInstall) go upApp(ctx, appInstall)
go updateToolApp(appInstall) go updateToolApp(appInstall)
ports := []int{appInstall.HttpPort} ports := []int{appInstall.HttpPort}
if appInstall.HttpsPort > 0 { if appInstall.HttpsPort > 0 {

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/compose-spec/compose-go/types"
"github.com/subosito/gotenv" "github.com/subosito/gotenv"
"math" "math"
"os" "os"
@ -381,15 +382,35 @@ func upAppPre(app model.App, appInstall model.AppInstall) error {
return nil return nil
} }
func upApp(ctx context.Context, composeFilePath string, appInstall model.AppInstall) { func upApp(ctx context.Context, appInstall model.AppInstall) {
out, err := compose.Up(composeFilePath) upProject := func(appInstall model.AppInstall) (err error) {
if err != nil { envStr, err := coverEnvJsonToStr(appInstall.Env)
if out != "" { if err == nil {
appInstall.Message = out var (
project *types.Project
composeService *composeV2.ComposeService
)
project, err = composeV2.GetComposeProject(appInstall.Name, appInstall.GetPath(), []byte(appInstall.DockerCompose), []byte(envStr))
if err != nil {
return err
}
composeService, err = composeV2.NewComposeService()
if err != nil {
return
}
composeService.SetProject(project)
err = composeService.ComposeUp()
if err != nil {
return err
}
return
} else { } else {
appInstall.Message = err.Error() return
} }
}
if err := upProject(appInstall); err != nil {
appInstall.Status = constant.Error appInstall.Status = constant.Error
appInstall.Message = err.Error()
} else { } else {
appInstall.Status = constant.Running appInstall.Status = constant.Running
} }