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 {
return nil, err
}
go upApp(ctx, appInstall.GetComposePath(), appInstall)
go upApp(ctx, appInstall)
go updateToolApp(appInstall)
ports := []int{appInstall.HttpPort}
if appInstall.HttpsPort > 0 {

View file

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/compose-spec/compose-go/types"
"github.com/subosito/gotenv"
"math"
"os"
@ -381,15 +382,35 @@ func upAppPre(app model.App, appInstall model.AppInstall) error {
return nil
}
func upApp(ctx context.Context, composeFilePath string, appInstall model.AppInstall) {
out, err := compose.Up(composeFilePath)
if err != nil {
if out != "" {
appInstall.Message = out
func upApp(ctx context.Context, appInstall model.AppInstall) {
upProject := func(appInstall model.AppInstall) (err error) {
envStr, err := coverEnvJsonToStr(appInstall.Env)
if err == nil {
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 {
appInstall.Message = err.Error()
return
}
}
if err := upProject(appInstall); err != nil {
appInstall.Status = constant.Error
appInstall.Message = err.Error()
} else {
appInstall.Status = constant.Running
}