diff --git a/controller/DeployController.go b/controller/DeployController.go index b5899a6..39cd6aa 100644 --- a/controller/DeployController.go +++ b/controller/DeployController.go @@ -23,6 +23,7 @@ import ( "github.com/zhenorzz/goploy/service" "github.com/zhenorzz/goploy/service/cmd" "github.com/zhenorzz/goploy/task" + "github.com/zhenorzz/goploy/utils" "io" "io/ioutil" "net/http" @@ -468,11 +469,17 @@ func (Deploy) Rebuild(gp *core.Goploy) core.Response { ch := make(chan bool, len(projectServers)) for _, projectServer := range projectServers { go func(projectServer model.ProjectServer) { - scriptName := fmt.Sprintf("GAD%d", projectServer.ServerID) + destDir := path.Join(project.SymlinkPath, project.LastPublishToken) + cmdEntity := cmd.New(projectServer.ServerOS) + afterDeployCommands := []string{cmdEntity.Symlink(destDir, project.Path), cmdEntity.ChangeDirTime(destDir)} if len(project.AfterDeployScript) != 0 { + scriptName := fmt.Sprintf("goploy-after-deploy-%d.%s", projectServer.ServerID, utils.GetScriptExt(project.AfterPullScriptMode)) scriptContent := service.ReplaceProjectVars(project.AfterDeployScript, project) scriptContent = service.ReplaceProjectServerVars(scriptContent, projectServer) ioutil.WriteFile(path.Join(core.GetProjectPath(project.ID), scriptName), []byte(service.ReplaceProjectVars(project.AfterDeployScript, project)), 0755) + afterDeployScriptPath := path.Join(project.Path, scriptName) + afterDeployCommands = append(afterDeployCommands, cmdEntity.Script(project.AfterDeployScriptMode, afterDeployScriptPath)) + afterDeployCommands = append(afterDeployCommands, cmdEntity.Remove(afterDeployScriptPath)) } client, err := projectServer.ToSSHConfig().Dial() if err != nil { @@ -488,7 +495,6 @@ func (Deploy) Rebuild(gp *core.Goploy) core.Response { return } - destDir := path.Join(project.SymlinkPath, project.LastPublishToken) // check if the path is existed or not if output, err := session.CombinedOutput("cd " + destDir); err != nil { core.Log(core.ERROR, "projectID:"+strconv.FormatInt(project.ID, 10)+" check symlink path err: "+err.Error()+", detail: "+string(output)) @@ -501,15 +507,7 @@ func (Deploy) Rebuild(gp *core.Goploy) core.Response { ch <- false return } - var afterDeployCommands []string - cmdEntity := cmd.New(projectServer.ServerOS) - afterDeployCommands = append(afterDeployCommands, cmdEntity.Symlink(destDir, project.Path)) - afterDeployCommands = append(afterDeployCommands, cmdEntity.ChangeDirTime(destDir)) - if len(project.AfterDeployScript) != 0 { - afterDeployScriptPath := path.Join(project.Path, scriptName) - afterDeployCommands = append(afterDeployCommands, cmdEntity.Script(project.AfterDeployScriptMode, afterDeployScriptPath)) - afterDeployCommands = append(afterDeployCommands, cmdEntity.Remove(afterDeployScriptPath)) - } + // redirect to project path if output, err := session.CombinedOutput(strings.Join(afterDeployCommands, "&&")); err != nil { core.Log(core.ERROR, "projectID:"+strconv.FormatInt(project.ID, 10)+" symlink err: "+err.Error()+", detail: "+string(output)) diff --git a/service/SyncService.go b/service/SyncService.go index aa578b9..b3a8a23 100644 --- a/service/SyncService.go +++ b/service/SyncService.go @@ -225,7 +225,7 @@ func (gsync Gsync) remoteSync(msgChIn chan<- syncMessage) { Type: model.Deploy, } // write after deploy script for rsync - scriptName := fmt.Sprintf("GAD%d", projectServer.ServerID) + scriptName := fmt.Sprintf("goploy-after-deploy-%d.%s", projectServer.ServerID, utils.GetScriptExt(project.AfterPullScriptMode)) if len(project.AfterDeployScript) != 0 { scriptContent := ReplaceProjectVars(project.AfterDeployScript, project) scriptContent = ReplaceProjectServerVars(scriptContent, projectServer) diff --git a/service/transmitter/RsyncTransmitter.go b/service/transmitter/RsyncTransmitter.go index 6056859..79f8df0 100644 --- a/service/transmitter/RsyncTransmitter.go +++ b/service/transmitter/RsyncTransmitter.go @@ -38,7 +38,7 @@ func (rt rsyncTransmitter) args() []string { rsyncOption, _ := utils.ParseCommandLine(project.TransferOption) rsyncOption = append([]string{ "--include", - fmt.Sprintf("GAD%d", projectServer.ServerID), + fmt.Sprintf("goploy-after-deploy-%d.%s", projectServer.ServerID, utils.GetScriptExt(project.AfterPullScriptMode)), }, rsyncOption...) rsyncOption = append(rsyncOption, "-e", projectServer.ToSSHOption()) diff --git a/service/transmitter/SftpTransmitter.go b/service/transmitter/SftpTransmitter.go index db304cf..57f5950 100644 --- a/service/transmitter/SftpTransmitter.go +++ b/service/transmitter/SftpTransmitter.go @@ -95,7 +95,7 @@ func (st sftpTransmitter) Exec() (string, error) { } nextItem = "" } - includes = append(includes, fmt.Sprintf("GAD%d", st.ProjectServer.ServerID)) + includes = append(includes, fmt.Sprintf("goploy-after-deploy-%d.%s", st.ProjectServer.ServerID, utils.GetScriptExt(project.AfterPullScriptMode))) srcPath := core.GetProjectPath(project.ID) + "/" destPath := project.Path diff --git a/web/src/views/deploy/TheDetailDialog.vue b/web/src/views/deploy/TheDetailDialog.vue index 35371ec..287227b 100644 --- a/web/src/views/deploy/TheDetailDialog.vue +++ b/web/src/views/deploy/TheDetailDialog.vue @@ -18,7 +18,8 @@ Filter [goploy ~]# {{ $t('deployPage.showDetail') }} @@ -330,7 +332,8 @@ [goploy ~]# {{ $t('deployPage.showDetail') }} @@ -356,7 +359,8 @@ [goploy ~]# {{ $t('deployPage.showDetail') }} @@ -383,7 +387,8 @@ [goploy ~]# {{ $t('deployPage.showDetail') }}