From 155363afa676aeb623376fc30cb8d09e1c6efa2e Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:46:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=A4=B1=E8=B4=A5=E7=9A=84=20BUG=20(#534)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/model/app_install.go | 4 +++ backend/app/service/app_install.go | 2 +- backend/app/service/app_utils.go | 48 +++++++++++++++++++----------- backend/utils/compose/compose.go | 2 +- backend/utils/docker/compose.go | 2 ++ frontend/src/lang/modules/en.ts | 23 ++++++++++++++ 6 files changed, 62 insertions(+), 19 deletions(-) diff --git a/backend/app/model/app_install.go b/backend/app/model/app_install.go index dbc9e1423..b66d9f162 100644 --- a/backend/app/model/app_install.go +++ b/backend/app/model/app_install.go @@ -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") +} diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 2eb3bc77a..34088feb2 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -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") } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 44d6da4d5..7b12c9f40 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -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 diff --git a/backend/utils/compose/compose.go b/backend/utils/compose/compose.go index e0ed15037..022c68525 100644 --- a/backend/utils/compose/compose.go +++ b/backend/utils/compose/compose.go @@ -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 } diff --git a/backend/utils/docker/compose.go b/backend/utils/docker/compose.go index 882124999..17a3edcc1 100644 --- a/backend/utils/docker/compose.go +++ b/backend/utils/docker/compose.go @@ -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 } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 824250ef9..654015c8e 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -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',