fix: 解决升级应用失败的 BUG (#534)

This commit is contained in:
zhengkunwang223 2023-04-07 16:46:11 +08:00 committed by GitHub
parent 3b3fad7278
commit 155363afa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 19 deletions

View File

@ -32,3 +32,7 @@ func (i *AppInstall) GetPath() string {
func (i *AppInstall) GetComposePath() string {
return path.Join(constant.AppInstallDir, i.App.Key, i.Name, "docker-compose.yml")
}
func (i *AppInstall) GetEnvPath() string {
return path.Join(constant.AppInstallDir, i.App.Key, i.Name, ".env")
}

View File

@ -209,7 +209,7 @@ func (a *AppInstallService) Operate(ctx context.Context, req request.AppInstalle
case constant.Sync:
return syncById(install.ID)
case constant.Upgrade:
return updateInstall(install.ID, req.DetailId)
return upgradeInstall(install.ID, req.DetailId)
default:
return errors.New("operate not support")
}

View File

@ -194,7 +194,7 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
}
func updateInstall(installId uint, detailId uint) error {
func upgradeInstall(installId uint, detailId uint) error {
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
if err != nil {
return err
@ -252,12 +252,17 @@ func getContainerNames(install model.AppInstall) ([]string, error) {
if err != nil {
return nil, err
}
containerNames := []string{install.ContainerName}
containerMap := make(map[string]struct{})
containerMap[install.ContainerName] = struct{}{}
for _, service := range project.AllServices() {
if service.ContainerName == "${CONTAINER_NAME}" || service.ContainerName == "" {
continue
}
containerNames = append(containerNames, service.ContainerName)
containerMap[service.ContainerName] = struct{}{}
}
var containerNames []string
for k := range containerMap {
containerNames = append(containerNames, k)
}
return containerNames, nil
}
@ -382,23 +387,32 @@ func upAppPre(app model.App, appInstall model.AppInstall) error {
return nil
}
func getServiceFromInstall(appInstall model.AppInstall) (service *composeV2.ComposeService, err error) {
var (
project *types.Project
envStr string
)
envStr, err = coverEnvJsonToStr(appInstall.Env)
if err != nil {
return
}
project, err = composeV2.GetComposeProject(appInstall.Name, appInstall.GetPath(), []byte(appInstall.DockerCompose), []byte(envStr))
if err != nil {
return
}
service, err = composeV2.NewComposeService()
if err != nil {
return
}
service.SetProject(project)
return
}
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)
var composeService *composeV2.ComposeService
composeService, err = getServiceFromInstall(appInstall)
err = composeService.ComposeUp()
if err != nil {
return err

View File

@ -10,7 +10,7 @@ func Up(filePath string) (string, error) {
}
func Down(filePath string) (string, error) {
stdout, err := cmd.Execf("docker-compose -f %s down", filePath)
stdout, err := cmd.Execf("docker-compose -f %s down --remove-orphans", filePath)
return stdout, err
}

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/compose/v2/pkg/compose"
"github.com/docker/docker/client"
"github.com/joho/godotenv"
"path"
"strings"
"time"
)
@ -109,6 +110,7 @@ func GetComposeProject(projectName, workDir string, yml []byte, env []byte) (*ty
if err != nil {
return nil, err
}
project.ComposeFiles = []string{path.Join(workDir, "docker-compose.yml")}
return project, nil
}

View File

@ -1143,6 +1143,29 @@ const message = {
deleteRuntimeHelper:
'The Runtime application needs to be deleted together with the website, please handle it with caution',
proxyType: 'Listening Network Type',
unix: 'Uinx Network',
tcp: 'TCP/IP Network',
phpFPM: 'FPM Config',
phpConfig: 'PHP Config',
updateConfig: 'Update Config',
isOn: 'On',
isOff: 'Off',
},
php: {
short_open_tag: 'Short tag support',
max_execution_time: 'Maximum script execution time',
max_input_time: 'Maximum input time',
memory_limit: 'Script memory limit',
post_max_size: 'POST data maximum size',
file_uploads: 'Whether to allow uploading files',
upload_max_filesize: 'The maximum size allowed to upload files',
max_file_uploads: 'The maximum number of files allowed to be uploaded at the same time',
default_socket_timeout: 'Socket timeout',
error_reporting: 'Error level',
display_errors: 'Whether to output detailed error information',
cgi_fix_pathinfo: 'Whether to open pathinfo',
date_timezone: 'Time zone',
second: 'Second',
},
nginx: {
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',