From d3bd8132aa64df169cd5c7240b0513f5adc2be0e Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Fri, 1 Sep 2017 16:04:05 +0100 Subject: [PATCH 1/2] Show information on where the application was deployed from in app summary - Information only applies to applications deployed through console - We already had information shown for the basic git source - This commit adds info for git url and file/archive sources - Information covers time of deployment and basic source info --- components/cf-app-push/backend/deploy.go | 70 ++++++++++++------- components/cf-app-push/backend/main.go | 2 +- components/cf-app-push/backend/vcs.go | 11 +-- .../deploy-step-deploying.service.js | 7 +- .../frontend/i18n/en_US/app.json | 2 + .../application/summary/summary.html | 29 +++++--- 6 files changed, 81 insertions(+), 40 deletions(-) diff --git a/components/cf-app-push/backend/deploy.go b/components/cf-app-push/backend/deploy.go index 5b386fc3d3..67b76e9e70 100644 --- a/components/cf-app-push/backend/deploy.go +++ b/components/cf-app-push/backend/deploy.go @@ -120,27 +120,36 @@ var upgrader = websocket.Upgrader{ } type StratosProject struct { - Url string `json:"url"` - CommitHash string `json:"commit"` - Branch string `json:"branch"` + DeploySource interface{} `json:"deploySource"` +} + +type DeploySource struct { + SourceType string `json:"type"` Timestamp int64 `json:"timestamp"` } // Structure used to provide metadata about the GitHub source type GitHubSourceInfo struct { - Project string `json:"project"` - Branch string `json:"branch"` + DeploySource + Project string `json:"project"` + Branch string `json:"branch"` + Url string `json:"url"` + CommitHash string `json:"commit"` } // Structure used to provide metadata about the Git Url source type GitUrlSourceInfo struct { - Url string `json:"url"` + DeploySource + Project string `json:"project"` Branch string `json:"branch"` + Url string `json:"url"` + CommitHash string `json:"commit"` } type FolderSourceInfo struct { + DeploySource Files int `json:"files"` - Folders []string `json:"folders"` + Folders []string `json:"folders,omitempty"` } func (cfAppPush *CFAppPush) deploy(echoContext echo.Context) error { @@ -261,6 +270,7 @@ func (cfAppPush *CFAppPush) deploy(echoContext echo.Context) error { func getFolderSource(clientWebSocket *websocket.Conn, tempDir string, msg SocketMessage) (string, string, error) { // The msg data is JSON for the Folder info info := FolderSourceInfo{} + if err := json.Unmarshal([]byte(msg.Message), &info); err != nil { return "", tempDir, err } @@ -345,12 +355,21 @@ func getFolderSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket } // Archive done - return "", unpackPath, nil + tempDir = unpackPath } } // All done! - return "", tempDir, nil + + // Return a string that can be added to the manifest as an application env var to trace where the source originated + info.Timestamp = time.Now().Unix() + info.Folders = nil + stratosProject := StratosProject{ + DeploySource: info, + } + + marshalledJson, _ := json.Marshal(stratosProject) + return string(marshalledJson), tempDir, nil } // Check the suffix of the file name and return an archiver that can handle that file type @@ -368,17 +387,20 @@ func getArchiverFor(filePath string) archiver.Archiver { } func getGitHubSource(clientWebSocket *websocket.Conn, tempDir string, msg SocketMessage) (string, string, error) { + var ( + err error + ) // The msg data is JSON for the GitHub info info := GitHubSourceInfo{} - if err := json.Unmarshal([]byte(msg.Message), &info); err != nil { + if err = json.Unmarshal([]byte(msg.Message), &info); err != nil { return "", tempDir, err } - projectUrl := fmt.Sprintf("https://github.com/%s", info.Project) - log.Infof("GitHub Source: %s, branch %s, url: %s", info.Project, info.Branch, projectUrl) + info.Url = fmt.Sprintf("https://github.com/%s", info.Project) + log.Infof("GitHub Source: %s, branch %s, url: %s", info.Project, info.Branch, info.Url) - commitHash, err := cloneRepository(projectUrl, info.Branch, clientWebSocket, tempDir) + info.CommitHash, err = cloneRepository(info.Url, info.Branch, clientWebSocket, tempDir) if err != nil { return "", tempDir, err } @@ -386,11 +408,9 @@ func getGitHubSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket sendEvent(clientWebSocket, EVENT_CLONED) // Return a string that can be added to the manifest as an application env var to trace where the source originated + info.Timestamp = time.Now().Unix() stratosProject := StratosProject{ - Url: projectUrl, - CommitHash: commitHash, - Branch: info.Branch, - Timestamp: time.Now().Unix(), + DeploySource: info, } marshalledJson, _ := json.Marshal(stratosProject) @@ -399,15 +419,20 @@ func getGitHubSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket func getGitUrlSource(clientWebSocket *websocket.Conn, tempDir string, msg SocketMessage) (string, string, error) { + var ( + err error + ) + // The msg data is JSON for the GitHub info info := GitUrlSourceInfo{} - if err := json.Unmarshal([]byte(msg.Message), &info); err != nil { + + if err = json.Unmarshal([]byte(msg.Message), &info); err != nil { return "", tempDir, err } log.Infof("Git Url Source: %s, branch %s", info.Url, info.Branch) - commitHash, err := cloneRepository(info.Url, info.Branch, clientWebSocket, tempDir) + info.CommitHash, err = cloneRepository(info.Url, info.Branch, clientWebSocket, tempDir) if err != nil { return "", tempDir, err } @@ -415,18 +440,15 @@ func getGitUrlSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket sendEvent(clientWebSocket, EVENT_CLONED) // Return a string that can be added to the manifest as an application env var to trace where the source originated + info.Timestamp = time.Now().Unix() stratosProject := StratosProject{ - Url: info.Url, - CommitHash: commitHash, - Branch: info.Branch, - Timestamp: time.Now().Unix(), + DeploySource: info, } marshalledJson, _ := json.Marshal(stratosProject) return string(marshalledJson), tempDir, nil } - func getMarshalledSocketMessage(data string, messageType MessageType) ([]byte, error) { messageStruct := SocketMessage{ diff --git a/components/cf-app-push/backend/main.go b/components/cf-app-push/backend/main.go index 289a53ca97..0984e0708d 100644 --- a/components/cf-app-push/backend/main.go +++ b/components/cf-app-push/backend/main.go @@ -5,8 +5,8 @@ import ( "code.cloudfoundry.org/cli/cf/commands/application" "code.cloudfoundry.org/cli/cf/flags" - "github.com/labstack/echo" "github.com/SUSE/stratos-ui/components/app-core/backend/repository/interfaces" + "github.com/labstack/echo" ) type CFAppPush struct { diff --git a/components/cf-app-push/backend/vcs.go b/components/cf-app-push/backend/vcs.go index 5dee4df866..a5ae021a1d 100644 --- a/components/cf-app-push/backend/vcs.go +++ b/components/cf-app-push/backend/vcs.go @@ -1,4 +1,5 @@ package main + // Based on https://github.com/golang/go/blob/master/src/cmd/go/internal/get/vcs.go import ( @@ -24,8 +25,8 @@ func GetVCS() *vcsCmd { } type vcsCmd struct { - name string - cmd string // name of binary to invoke command + name string + cmd string // name of binary to invoke command createCmd []string // commands to download a fresh copy of a repository checkoutCmd []string // commands to checkout a branch @@ -72,7 +73,7 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool) m := make(map[string]string) for i := 0; i < len(keyval); i += 2 { - m[keyval[i]] = keyval[i + 1] + m[keyval[i]] = keyval[i+1] } args := strings.Fields(cmdline) for i, arg := range args { @@ -102,7 +103,7 @@ func (v *vcsCmd) run1(dir string, cmdline string, keyval []string, verbose bool) func expand(match map[string]string, s string) string { for k, v := range match { - s = strings.Replace(s, "{" + k + "}", v, -1) + s = strings.Replace(s, "{"+k+"}", v, -1) } return s } @@ -113,7 +114,7 @@ func EnvForDir(dir string, base []string) []string { func MergeEnvLists(in, out []string) []string { out = append([]string(nil), out...) - NextVar: +NextVar: for _, inkv := range in { k := strings.SplitAfterN(inkv, "=", 2)[0] for i, outkv := range out { diff --git a/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js b/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js index 23247c2a95..a4aacec4ea 100644 --- a/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js +++ b/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js @@ -195,7 +195,8 @@ function sendGitHubSourceMetadata() { var github = { project: sourceUserInput.githubProject, - branch: sourceUserInput.githubBranch.name + branch: sourceUserInput.githubBranch.name, + type: sourceUserInput.gitType }; var msg = { @@ -211,7 +212,8 @@ function sendGitUrlSourceMetadata() { var giturl = { url: sourceUserInput.gitUrl, - branch: sourceUserInput.gitUrlBranch + branch: sourceUserInput.gitUrlBranch, + type: sourceUserInput.gitType }; var msg = { @@ -234,6 +236,7 @@ sourceUserInput.fileTransfers = metadata.files; metadata.files = metadata.files.length; + metadata.type = metadata.files === 1 ? 'archive' : 'filefolder'; data.uploadingFiles = { remaining: metadata.files, bytes: 0, diff --git a/components/cloud-foundry/frontend/i18n/en_US/app.json b/components/cloud-foundry/frontend/i18n/en_US/app.json index 04180a3945..8cb3c42980 100644 --- a/components/cloud-foundry/frontend/i18n/en_US/app.json +++ b/components/cloud-foundry/frontend/i18n/en_US/app.json @@ -102,6 +102,8 @@ "modified-label": "modified", "deployed-label": "console deploy", "deployed-source-label": "console deploy source", + "deployed-source-filefolder": "Folder Upload", + "deployed-source-archive": "Archive File Upload", "ssh-enabled-label": "ssh enabled", "memory-label": "memory", "disk-quota-label": "disk quota", diff --git a/components/cloud-foundry/frontend/src/view/applications/application/summary/summary.html b/components/cloud-foundry/frontend/src/view/applications/application/summary/summary.html index f2c74bdc35..ccbc9721be 100644 --- a/components/cloud-foundry/frontend/src/view/applications/application/summary/summary.html +++ b/components/cloud-foundry/frontend/src/view/applications/application/summary/summary.html @@ -78,17 +78,30 @@
-
-
app.app-info.app-tabs.summary.summary-panel.deployed-label
-
- {{ applicationSummaryCtrl.stratosProject.timestamp * 1000 | momentDateFormat }} +
app.app-info.app-tabs.summary.summary-panel.deployed-label
+
+ {{ applicationSummaryCtrl.stratosProject.deploySource.timestamp * 1000 | momentDateFormat }}
-
app.app-info.app-tabs.summary.summary-panel.deployed-source-label
-
- - {{applicationSummaryCtrl.stratosProject.commit | limitTo:8}} +
app.app-info.app-tabs.summary.summary-panel.deployed-source-label
+
+ + {{applicationSummaryCtrl.stratosProject.deploySource.commit | limitTo:8}} + + {{applicationSummaryCtrl.stratosProject.deploySource.url}} + + app.app-info.app-tabs.summary.summary-panel.deployed-source-filefolder + app.app-info.app-tabs.summary.summary-panel.deployed-source-archive
cf.ssh.access
From 2c420481d6fb78d926525ae2ce88df1c99ea414f Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Mon, 18 Sep 2017 11:25:24 +0100 Subject: [PATCH 2/2] Determine zip or not deploy source in backend --- components/cf-app-push/backend/deploy.go | 3 +++ .../deploy-step-deploying/deploy-step-deploying.service.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/cf-app-push/backend/deploy.go b/components/cf-app-push/backend/deploy.go index 67b76e9e70..ed169a3d89 100644 --- a/components/cf-app-push/backend/deploy.go +++ b/components/cf-app-push/backend/deploy.go @@ -335,6 +335,9 @@ func getFolderSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket archiver := getArchiverFor(lastFilePath) if archiver != nil { + // Overwrite generic 'filefolder' type + info.DeploySource.SourceType = "archive" + log.Debug("Unpacking archive ......") unpackPath := filepath.Join(tempDir, "application") err := os.Mkdir(unpackPath, 0700) diff --git a/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js b/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js index a4aacec4ea..4529e8fc4a 100644 --- a/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js +++ b/components/cf-app-push/frontend/src/view/deploy-app-workflow/deploy-step-deploying/deploy-step-deploying.service.js @@ -236,7 +236,7 @@ sourceUserInput.fileTransfers = metadata.files; metadata.files = metadata.files.length; - metadata.type = metadata.files === 1 ? 'archive' : 'filefolder'; + metadata.type = 'filefolder'; data.uploadingFiles = { remaining: metadata.files, bytes: 0,