Majorly improved app loading from Github
This commit is contained in:
@@ -6530,7 +6530,7 @@ func handleAppHotload(location string, forceUpdate bool) error {
|
||||
}
|
||||
|
||||
//log.Printf("Reading app folder: %#v", dir)
|
||||
err = iterateAppGithubFolders(fs, dir, "", "", forceUpdate)
|
||||
_, _, err = iterateAppGithubFolders(fs, dir, "", "", forceUpdate)
|
||||
if err != nil {
|
||||
log.Printf("Err: %s", err)
|
||||
return err
|
||||
|
||||
+90
-16
@@ -1403,6 +1403,7 @@ func getWorkflows(resp http.ResponseWriter, request *http.Request) {
|
||||
q := datastore.NewQuery("workflow").Filter("owner =", user.Id)
|
||||
if user.Role == "admin" {
|
||||
q = datastore.NewQuery("workflow").Filter("org_id =", user.ActiveOrg.Id)
|
||||
log.Printf("[INFO] Getting workflows (ADMIN) for organization %s", user.ActiveOrg.Id)
|
||||
}
|
||||
|
||||
var workflows []Workflow
|
||||
@@ -2235,9 +2236,11 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
// Handles check for required params
|
||||
if !found && param.Required {
|
||||
log.Printf("Appaction %s with required param %s doesn't exist.", action.Name, param.Name)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Appaction %s with required param '%s' is empty."}`, action.Name, param.Name)))
|
||||
return
|
||||
action.Errors = append(action.Errors, "Parameter %s is required", param.Name)
|
||||
//newActions = append(newActions, action)
|
||||
//resp.WriteHeader(401)
|
||||
//resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Appaction %s with required param '%s' is empty."}`, action.Name, param.Name)))
|
||||
//return
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2252,6 +2255,12 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
workflow.IsValid = true
|
||||
log.Printf("Tags: %#v", workflow.Tags)
|
||||
|
||||
// FIXME: Is this too drastic? May lead to issues in the future.
|
||||
// Should maybe make a copy for the old org.
|
||||
if workflow.OrgId != user.ActiveOrg.Id {
|
||||
workflow.OrgId = user.ActiveOrg.Id
|
||||
}
|
||||
|
||||
err = setWorkflow(ctx, workflow, fileId)
|
||||
if err != nil {
|
||||
log.Printf("Failed saving workflow to database: %s", err)
|
||||
@@ -2277,7 +2286,7 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
Errors: workflow.Errors,
|
||||
}
|
||||
|
||||
log.Printf("Saved new version of workflow %s (%s)", workflow.Name, fileId)
|
||||
log.Printf("Saved new version of workflow %s (%s) for org %s", workflow.Name, fileId, workflow.OrgId)
|
||||
resp.WriteHeader(200)
|
||||
newBody, err := json.Marshal(returndata)
|
||||
if err != nil {
|
||||
@@ -5379,11 +5388,23 @@ func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra
|
||||
return err
|
||||
}
|
||||
|
||||
type buildLaterStruct struct {
|
||||
Tags []string
|
||||
Extra string
|
||||
}
|
||||
|
||||
// Onlyname is used to
|
||||
func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra string, onlyname string, forceUpdate bool) error {
|
||||
func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra string, onlyname string, forceUpdate bool) ([]buildLaterStruct, []buildLaterStruct, error) {
|
||||
var err error
|
||||
|
||||
allapps := []WorkflowApp{}
|
||||
reservedNames := []string{
|
||||
"OWA",
|
||||
"NLP",
|
||||
}
|
||||
|
||||
buildLaterFirst := []buildLaterStruct{}
|
||||
buildLaterList := []buildLaterStruct{}
|
||||
|
||||
// It's here to prevent getting them in every iteration
|
||||
ctx := context.Background()
|
||||
@@ -5403,11 +5424,20 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
|
||||
}
|
||||
|
||||
// Go routine? Hmm, this can be super quick I guess
|
||||
err = iterateAppGithubFolders(fs, dir, tmpExtra, "", forceUpdate)
|
||||
buildFirst, buildLast, err := iterateAppGithubFolders(fs, dir, tmpExtra, "", forceUpdate)
|
||||
if err != nil {
|
||||
log.Printf("Error reading folder: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, item := range buildFirst {
|
||||
buildLaterFirst = append(buildLaterFirst, item)
|
||||
}
|
||||
|
||||
for _, item := range buildLast {
|
||||
buildLaterList = append(buildLaterList, item)
|
||||
}
|
||||
|
||||
case mode.IsRegular():
|
||||
// Check the file
|
||||
filename := file.Name()
|
||||
@@ -5605,22 +5635,66 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin
|
||||
|
||||
//log.Printf("Added %s:%s to the database", workflowapp.Name, workflowapp.AppVersion)
|
||||
|
||||
/// Only upload if successful and no errors
|
||||
err = buildImageMemory(fs, tags, extra)
|
||||
if err != nil {
|
||||
log.Printf("Failed image build memory: %s", err)
|
||||
} else {
|
||||
if len(tags) > 0 {
|
||||
log.Printf("Successfully built image %s", tags[0])
|
||||
} else {
|
||||
log.Printf("Successfully built Docker image")
|
||||
reservedFound := false
|
||||
buildLater := buildLaterStruct{
|
||||
Tags: tags,
|
||||
Extra: extra,
|
||||
}
|
||||
for _, appname := range reservedNames {
|
||||
if strings.ToUpper(workflowapp.Name) == strings.ToUpper(appname) {
|
||||
buildLaterList = append(buildLaterList, buildLater)
|
||||
|
||||
reservedFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/// Only upload if successful and no errors
|
||||
if !reservedFound {
|
||||
buildLaterFirst = append(buildLaterFirst, buildLater)
|
||||
} else {
|
||||
log.Printf("\n\n[WARNING] Skipping build of %s to later\n\n", workflowapp.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
if len(buildLaterFirst) == 0 && len(buildLaterList) == 0 {
|
||||
return buildLaterFirst, buildLaterList, err
|
||||
}
|
||||
|
||||
//log.Printf("BUILDLATERFIRST: %d, BUILDLATERLIST: %d", len(buildLaterFirst), len(buildLaterList))
|
||||
if len(extra) == 0 {
|
||||
log.Printf("[INFO] Starting build of %d containers (FIRST)", len(buildLaterFirst))
|
||||
for _, item := range buildLaterFirst {
|
||||
err = buildImageMemory(fs, item.Tags, item.Extra)
|
||||
if err != nil {
|
||||
log.Printf("Failed image build memory: %s", err)
|
||||
} else {
|
||||
if len(item.Tags) > 0 {
|
||||
log.Printf("Successfully built image %s", item.Tags[0])
|
||||
} else {
|
||||
log.Printf("Successfully built Docker image")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Starting build of %d skipped docker images", len(buildLaterList))
|
||||
for _, item := range buildLaterList {
|
||||
err = buildImageMemory(fs, item.Tags, item.Extra)
|
||||
if err != nil {
|
||||
log.Printf("Failed image build memory: %s", err)
|
||||
} else {
|
||||
if len(item.Tags) > 0 {
|
||||
log.Printf("Successfully built image %s", item.Tags[0])
|
||||
} else {
|
||||
log.Printf("Successfully built Docker image")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buildLaterFirst, buildLaterList, err
|
||||
}
|
||||
|
||||
func setNewWorkflowApp(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user