mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
fix: 解决升级应用失败的 BUG (#534)
This commit is contained in:
parent
3b3fad7278
commit
155363afa6
@ -32,3 +32,7 @@ func (i *AppInstall) GetPath() string {
|
|||||||
func (i *AppInstall) GetComposePath() string {
|
func (i *AppInstall) GetComposePath() string {
|
||||||
return path.Join(constant.AppInstallDir, i.App.Key, i.Name, "docker-compose.yml")
|
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")
|
||||||
|
}
|
||||||
|
@ -209,7 +209,7 @@ func (a *AppInstallService) Operate(ctx context.Context, req request.AppInstalle
|
|||||||
case constant.Sync:
|
case constant.Sync:
|
||||||
return syncById(install.ID)
|
return syncById(install.ID)
|
||||||
case constant.Upgrade:
|
case constant.Upgrade:
|
||||||
return updateInstall(install.ID, req.DetailId)
|
return upgradeInstall(install.ID, req.DetailId)
|
||||||
default:
|
default:
|
||||||
return errors.New("operate not support")
|
return errors.New("operate not support")
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
|
|||||||
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
|
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))
|
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -252,12 +252,17 @@ func getContainerNames(install model.AppInstall) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
containerNames := []string{install.ContainerName}
|
containerMap := make(map[string]struct{})
|
||||||
|
containerMap[install.ContainerName] = struct{}{}
|
||||||
for _, service := range project.AllServices() {
|
for _, service := range project.AllServices() {
|
||||||
if service.ContainerName == "${CONTAINER_NAME}" || service.ContainerName == "" {
|
if service.ContainerName == "${CONTAINER_NAME}" || service.ContainerName == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
containerNames = append(containerNames, service.ContainerName)
|
containerMap[service.ContainerName] = struct{}{}
|
||||||
|
}
|
||||||
|
var containerNames []string
|
||||||
|
for k := range containerMap {
|
||||||
|
containerNames = append(containerNames, k)
|
||||||
}
|
}
|
||||||
return containerNames, nil
|
return containerNames, nil
|
||||||
}
|
}
|
||||||
@ -382,23 +387,32 @@ func upAppPre(app model.App, appInstall model.AppInstall) error {
|
|||||||
return nil
|
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) {
|
func upApp(ctx context.Context, appInstall model.AppInstall) {
|
||||||
upProject := func(appInstall model.AppInstall) (err error) {
|
upProject := func(appInstall model.AppInstall) (err error) {
|
||||||
envStr, err := coverEnvJsonToStr(appInstall.Env)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var (
|
var composeService *composeV2.ComposeService
|
||||||
project *types.Project
|
composeService, err = getServiceFromInstall(appInstall)
|
||||||
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()
|
err = composeService.ComposeUp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -10,7 +10,7 @@ func Up(filePath string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Down(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
|
return stdout, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/docker/compose/v2/pkg/compose"
|
"github.com/docker/compose/v2/pkg/compose"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -109,6 +110,7 @@ func GetComposeProject(projectName, workDir string, yml []byte, env []byte) (*ty
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
project.ComposeFiles = []string{path.Join(workDir, "docker-compose.yml")}
|
||||||
return project, nil
|
return project, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1143,6 +1143,29 @@ const message = {
|
|||||||
deleteRuntimeHelper:
|
deleteRuntimeHelper:
|
||||||
'The Runtime application needs to be deleted together with the website, please handle it with caution',
|
'The Runtime application needs to be deleted together with the website, please handle it with caution',
|
||||||
proxyType: 'Listening Network Type',
|
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: {
|
nginx: {
|
||||||
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',
|
serverNamesHashBucketSizeHelper: 'The hash table size of the server name',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user