Skip to content

Commit

Permalink
Merge pull request #1208 from SUSE/deploy-sources-git-url
Browse files Browse the repository at this point in the history
Depoy app via git url
  • Loading branch information
nwmac authored Aug 30, 2017
2 parents aebcd16 + 933f3d4 commit 97e9e3f
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ login-form {

> h1 {
margin-bottom: $console-unit-space * 1.5;
margin-top: $console-unit-space / 2;
margin-top: $console-unit-space / 4;
color: $brand-primary;
font-weight: $console-font-weight-light;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@
*/
function disableNext() {
var step = vm.steps[vm.currentIndex] || {};
if (_.isFunction(step.allowNext) && !step.allowNext()) {
return true;
if (_.isFunction(step.allowNext)) {
return !step.allowNext();
}
if ($scope.wizardForm) {
var form = $scope.wizardForm[step.formName];
Expand Down
56 changes: 47 additions & 9 deletions components/cf-app-push/backend/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const (
SOURCE_FILE
SOURCE_FILE_DATA
SOURCE_FILE_ACK
SOURCE_GITURL
)

const (
Expand Down Expand Up @@ -131,6 +132,12 @@ type GitHubSourceInfo struct {
Branch string `json:"branch"`
}

// Structure used to provide metadata about the Git Url source
type GitUrlSourceInfo struct {
Url string `json:"url"`
Branch string `json:"branch"`
}

type FolderSourceInfo struct {
Files int `json:"files"`
Folders []string `json:"folders"`
Expand All @@ -157,7 +164,6 @@ func (cfAppPush *CFAppPush) deploy(echoContext echo.Context) error {
defer pingTicker.Stop()

// We use a simple protocol to get the source to use for cf push
// This can either be a github project or one or more files

// Send a message to the client to say that we are awaiting source details
sendEvent(clientWebSocket, SOURCE_REQUIRED)
Expand Down Expand Up @@ -185,6 +191,8 @@ func (cfAppPush *CFAppPush) deploy(echoContext echo.Context) error {
sourceEnvVarMetadata, appDir, err = getGitHubSource(clientWebSocket, tempDir, msg)
case SOURCE_FOLDER:
sourceEnvVarMetadata, appDir, err = getFolderSource(clientWebSocket, tempDir, msg)
case SOURCE_GITURL:
sourceEnvVarMetadata, appDir, err = getGitUrlSource(clientWebSocket, tempDir, msg)
default:
err = errors.New("Unsupported source type; don't know how to get the source for the application")
}
Expand Down Expand Up @@ -389,6 +397,36 @@ func getGitHubSource(clientWebSocket *websocket.Conn, tempDir string, msg Socket
return string(marshalledJson), tempDir, nil
}

func getGitUrlSource(clientWebSocket *websocket.Conn, tempDir string, msg SocketMessage) (string, string, error) {

// The msg data is JSON for the GitHub info
info := GitUrlSourceInfo{}
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)
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
stratosProject := StratosProject{
Url: info.Url,
CommitHash: commitHash,
Branch: info.Branch,
Timestamp: time.Now().Unix(),
}

marshalledJson, _ := json.Marshal(stratosProject)
return string(marshalledJson), tempDir, nil
}


func getMarshalledSocketMessage(data string, messageType MessageType) ([]byte, error) {

messageStruct := SocketMessage{
Expand Down Expand Up @@ -532,22 +570,22 @@ func (cfAppPush *CFAppPush) getConfigData(echoContext echo.Context, cnsiGuid str

func cloneRepository(repoUrl string, branch string, clientWebSocket *websocket.Conn, tempDir string) (string, error) {

if len(branch) == 0 {
err := errors.New("No branch supplied")
log.Infof("Failed to checkout repo %s due to %+v", branch, repoUrl, err)
sendErrorMessage(clientWebSocket, err, CLOSE_FAILED_NO_BRANCH)
return "", err
}

vcsGit := GetVCS()

err := vcsGit.Create(tempDir, repoUrl)
err := vcsGit.Create(tempDir, repoUrl, branch)
if err != nil {
log.Infof("Failed to clone repo %s due to %+v", repoUrl, err)
sendErrorMessage(clientWebSocket, err, CLOSE_FAILED_CLONE)
return "", err
}

err = vcsGit.Checkout(tempDir, branch)
if err != nil {
log.Infof("Failed to checkout %s branch in repo %s due to %+v", branch, repoUrl, err)
sendErrorMessage(clientWebSocket, err, CLOSE_FAILED_NO_BRANCH)
return "", err
}

head, err := vcsGit.Head(tempDir)
if err != nil {
log.Infof("Unable to fetch HEAD in branch due to %s", err)
Expand Down
6 changes: 3 additions & 3 deletions components/cf-app-push/backend/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var vcsGit = &vcsCmd{
name: "Git",
cmd: "git",
createCmd: []string{"clone {repo} {dir}"},
createCmd: []string{"clone -b {branch} {repo} {dir}"},
checkoutCmd: []string{"checkout refs/remotes/origin/{branch}"},
headCmd: []string{"rev-parse HEAD"},
}
Expand All @@ -32,9 +32,9 @@ type vcsCmd struct {
headCmd []string // get current head commit
}

func (vcs *vcsCmd) Create(dir string, repo string) error {
func (vcs *vcsCmd) Create(dir string, repo string, branch string) error {
for _, cmd := range vcs.createCmd {
if err := vcs.run(".", cmd, "dir", dir, "repo", repo); err != nil {
if err := vcs.run(".", cmd, "dir", dir, "repo", repo, "branch", branch); err != nil {
return err
}
}
Expand Down
41 changes: 29 additions & 12 deletions components/cf-app-push/frontend/i18n/en_US/app-push.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,33 @@
"title": "Source",
"choose-label": "Source Type",
"choose-placeholder": "Select the source type",
"github": {
"label": "Public Github",
"project-label": "Project",
"project-placeholder": "suse/stratos-ui",
"project-not-found": "Project not found",
"branch-label": "Project Branch",
"branch-placeholder": "Select Branch",
"branch-last-commit": "",
"branch-last-commit-date": "",
"branch-last-commit-committer": ""
"git": {
"git": "Git",
"github": {
"github": "Public Github",
"project-label": "Project",
"project-placeholder": "suse/stratos-ui",
"project-not-found": "Project not found",
"branch-label": "Branch",
"branch-placeholder": "Select Branch",
"branch-last-commit": "",
"branch-last-commit-date": "",
"branch-last-commit-committer": ""
},
"gitUrl": {
"gitUrl": "Public Git URL",
"url": {
"url": "URL",
"placeholder": "HTTPS URL of git repository",
"error-required": "URL is required",
"error-pattern": "Invalid URL"
},
"branch": {
"branch": "Branch Name",
"placeholder": "Branch name will decrease clone time",
"error-required": "Branch is required"
}
}
},
"source": {
"file": "Select a source or drag and drop a GitHub url or an archive file",
Expand Down Expand Up @@ -64,8 +81,8 @@
},
"socket": {
"event-type": {
"CLOSE_FAILED_NO_BRANCH": "Failed to clone repository (invalid branch), please ensure github details are correct",
"CLOSE_FAILED_CLONE": "Failed to clone repository, please ensure github details are correct and try again",
"CLOSE_FAILED_NO_BRANCH": "Failed to clone repository (no branch supplied), please ensure git details are correct",
"CLOSE_FAILED_CLONE": "Failed to clone repository, please ensure git details are correct and try again",
"CLOSE_FAILURE": "Unknown failure. See log for more information.",
"CLOSE_INVALID_MANIFEST": "Invalid manifest",
"CLOSE_NO_MANIFEST": "Failed to find manifest",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$deploy-app-step-height: 350px;
$deploy-app-step-height: 392px;
$deploy-app-step-padding-bottom: 6px;

@import "deploy-step-deploying/deploy-step-deploying";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
},
wizard: {
allowBack: true,
sourceType: 'github'
sourceType: 'git'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
SOURCE_FOLDER: 30002,
SOURCE_FILE: 30003,
SOURCE_FILE_DATA: 30004,
SOURCE_FILE_ACK: 30005
SOURCE_FILE_ACK: 30005,
SOURCE_GITURL: 30006
};

// How often to check for the app being created
Expand Down Expand Up @@ -176,13 +177,21 @@
}

function sendSourceMetadata() {
if (wizardData.sourceType === 'github') {
sendGitHubSourceMetadata();
if (wizardData.sourceType === 'git') {
sendGitMetadata();
} else if (wizardData.sourceType === 'local') {
sendLocalSourceMetadata();
}
}

function sendGitMetadata() {
if (sourceUserInput.gitType === 'github') {
sendGitHubSourceMetadata();
} else if (sourceUserInput.gitType === 'giturl') {
sendGitUrlSourceMetadata();
}
}

function sendGitHubSourceMetadata() {
var github = {
project: sourceUserInput.githubProject,
Expand All @@ -199,6 +208,22 @@
data.webSocket.send(angular.toJson(msg));
}

function sendGitUrlSourceMetadata() {
var giturl = {
url: sourceUserInput.gitUrl,
branch: sourceUserInput.gitUrlBranch
};

var msg = {
message: angular.toJson(giturl),
timestamp: Math.round((new Date()).getTime() / 1000),
type: socketEventTypes.SOURCE_GITURL
};

// Send the source metadata
data.webSocket.send(angular.toJson(msg));
}

function sendLocalSourceMetadata() {
var metadata = {
files: [],
Expand Down
Loading

0 comments on commit 97e9e3f

Please sign in to comment.