Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show deployment information in app summary for console deployed apps #1243

Merged
merged 3 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 49 additions & 24 deletions components/cf-app-push/backend/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -325,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)
Expand All @@ -345,12 +358,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
Expand All @@ -368,29 +390,30 @@ 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
}

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)
Expand All @@ -399,34 +422,36 @@ 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
}

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{
Expand Down
2 changes: 1 addition & 1 deletion components/cf-app-push/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions components/cf-app-push/backend/vcs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package main

// Based on https://github.com/golang/go/blob/master/src/cmd/go/internal/get/vcs.go

import (
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@
function sendGitHubSourceMetadata() {
var github = {
project: sourceUserInput.githubProject,
branch: sourceUserInput.githubBranch.name
branch: sourceUserInput.githubBranch.name,
type: sourceUserInput.gitType
};

var msg = {
Expand All @@ -211,7 +212,8 @@
function sendGitUrlSourceMetadata() {
var giturl = {
url: sourceUserInput.gitUrl,
branch: sourceUserInput.gitUrlBranch
branch: sourceUserInput.gitUrlBranch,
type: sourceUserInput.gitType
};

var msg = {
Expand All @@ -234,6 +236,7 @@

sourceUserInput.fileTransfers = metadata.files;
metadata.files = metadata.files.length;
metadata.type = 'filefolder';
data.uploadingFiles = {
remaining: metadata.files,
bytes: 0,
Expand Down
2 changes: 2 additions & 0 deletions components/cloud-foundry/frontend/i18n/en_US/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,30 @@
</dd>
<dd class="pull-right" ng-if="!appCtrl.model.application.summary.package_updated_at">-</dd>

<dt translate ng-if="applicationSummaryCtrl.stratosProject">app.app-info.app-tabs.summary.summary-panel.deployed-label</dt>
<dd class="pull-right" ng-if="applicationSummaryCtrl.stratosProject">
{{ applicationSummaryCtrl.stratosProject.timestamp * 1000 | momentDateFormat }}
<dt translate ng-if="applicationSummaryCtrl.stratosProject.deploySource">app.app-info.app-tabs.summary.summary-panel.deployed-label</dt>
<dd class="pull-right" ng-if="applicationSummaryCtrl.stratosProject.deploySource">
{{ applicationSummaryCtrl.stratosProject.deploySource.timestamp * 1000 | momentDateFormat }}
</dd>

<dt translate ng-if="applicationSummaryCtrl.stratosProject">app.app-info.app-tabs.summary.summary-panel.deployed-source-label</dt>
<dd class="pull-right" ng-if="applicationSummaryCtrl.stratosProject">
<a href="{{applicationSummaryCtrl.stratosProject.url}}/commit/{{applicationSummaryCtrl.stratosProject.commit}}"
rel="noopener noreferrer" target="_blank">
{{applicationSummaryCtrl.stratosProject.commit | limitTo:8}}
<dt translate ng-if="applicationSummaryCtrl.stratosProject.deploySource">app.app-info.app-tabs.summary.summary-panel.deployed-source-label</dt>
<dd class="pull-right" ng-if="applicationSummaryCtrl.stratosProject.deploySource"
ng-switch="applicationSummaryCtrl.stratosProject.deploySource.type">
<a ng-switch-when="github"
href="{{applicationSummaryCtrl.stratosProject.deploySource.url}}/commit/{{applicationSummaryCtrl.stratosProject.deploySource.commit}}"
rel="noopener noreferrer" target="_blank">
{{applicationSummaryCtrl.stratosProject.deploySource.commit | limitTo:8}}
</a>
<span ng-switch-when="giturl"
uib-popover="{{ applicationSummaryCtrl.stratosProject.deploySource.branch }} {{applicationSummaryCtrl.stratosProject.deploySource.commit | limitTo:8 }}"
popover-trigger="'mouseenter'"
popover-placement="top"
popover-popup-delay="200"
popover-popup-close-delay="1500"
>
{{applicationSummaryCtrl.stratosProject.deploySource.url}}
</span>
<span ng-switch-when="filefolder" translate>app.app-info.app-tabs.summary.summary-panel.deployed-source-filefolder</span>
<span ng-switch-when="archive" translate>app.app-info.app-tabs.summary.summary-panel.deployed-source-archive</span>
</dd>

<dt translate>cf.ssh.access</dt>
Expand Down