#135: Started building app exist validation
This commit is contained in:
@@ -3,11 +3,11 @@ NAME=app_sdk
|
||||
VERSION=0.6.0
|
||||
|
||||
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
|
||||
docker build . -t frikky/shuffle:$NAME -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t gchr.io/frikky/app_sdk:0.6.0
|
||||
docker build . -t frikky/shuffle:$NAME -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/app_sdk:0.6.0
|
||||
|
||||
#docker push frikky/shuffle:$NAME
|
||||
#docker push frikky/$NAME:$VERSION
|
||||
#docker push docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION
|
||||
#docker push ghcr.io/frikky/$NAME:$VERSION
|
||||
|
||||
docker push gchr.io/frikky/app_sdk
|
||||
docker push ghcr.io/frikky/$NAME:$VERSION
|
||||
|
||||
@@ -642,6 +642,49 @@ func handleStartHookDocker(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Checks if an image exists
|
||||
func imageCheckBuilder(images []string) error {
|
||||
log.Printf("ImageNames: %#v", images)
|
||||
ctx := context.Background()
|
||||
client, err := client.NewEnvClient()
|
||||
if err != nil {
|
||||
log.Printf("Unable to create docker client: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
allImages, err := client.ImageList(ctx, types.ImageListOptions{
|
||||
All: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed creating imagelist: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
filteredImages := []types.ImageSummary{}
|
||||
for _, image := range allImages {
|
||||
found := false
|
||||
for _, repoTag := range image.RepoTags {
|
||||
if strings.Contains(repoTag, baseDockerName) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
filteredImages = append(filteredImages, image)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Continue fixing apps here
|
||||
// https://github.com/frikky/Shuffle/issues/135
|
||||
// 1. Find if app exists
|
||||
// 2. Create app if it doesn't
|
||||
//log.Printf("Apps: %#v", filteredImages)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func hookTest() {
|
||||
var hook Hook
|
||||
err := json.Unmarshal([]byte(webhook), &hook)
|
||||
|
||||
+20
-32
@@ -42,14 +42,10 @@ var localBase = "http://localhost:5001"
|
||||
var baseEnvironment = "onprem"
|
||||
|
||||
var cloudname = "cloud"
|
||||
|
||||
var defaultLocation = "europe-west2"
|
||||
var scheduledJobs = map[string]*newscheduler.Job{}
|
||||
|
||||
// To test out firestore before potential merge
|
||||
var shuffleTestProject = "shuffle-test-258209"
|
||||
var shuffleTestPath = "./shuffle-test-258209-5a2e8d7e508a.json"
|
||||
|
||||
//var upgrader = websocket.Upgrader{
|
||||
// ReadBufferSize: 1024,
|
||||
// WriteBufferSize: 1024,
|
||||
@@ -2146,7 +2142,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
|
||||
//log.Printf("Execution data: %#v", execution)
|
||||
if len(execution.Start) == 36 {
|
||||
log.Printf("SHOULD START ON NODE %s", execution.Start)
|
||||
log.Printf("[INFO] Should start execution on node %s", execution.Start)
|
||||
workflowExecution.Start = execution.Start
|
||||
|
||||
found := false
|
||||
@@ -2157,12 +2153,12 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
}
|
||||
|
||||
if !found {
|
||||
log.Printf("ACTION %s WAS NOT FOUND!", workflow.Start)
|
||||
log.Printf("[ERROR] ACTION %s WAS NOT FOUND!", workflow.Start)
|
||||
return WorkflowExecution{}, fmt.Sprintf("Startnode %s was not found in actions", workflow.Start), errors.New(fmt.Sprintf("Startnode %s was not found in actions", workflow.Start))
|
||||
}
|
||||
} else if len(execution.Start) > 0 {
|
||||
|
||||
log.Printf("START ACTION %s IS WRONG ID LENGTH %d!", execution.Start, len(execution.Start))
|
||||
log.Printf("[ERROR] START ACTION %s IS WRONG ID LENGTH %d!", execution.Start, len(execution.Start))
|
||||
return WorkflowExecution{}, fmt.Sprintf("Startnode %s was not found in actions", execution.Start), errors.New(fmt.Sprintf("Startnode %s was not found in actions", execution.Start))
|
||||
}
|
||||
|
||||
@@ -2292,10 +2288,10 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
}
|
||||
|
||||
if len(workflowExecution.ExecutionSource) == 0 {
|
||||
log.Printf("No execution source specified. Setting to default")
|
||||
log.Printf("[INFO] No execution source (trigger) specified. Setting to default")
|
||||
workflowExecution.ExecutionSource = "default"
|
||||
} else {
|
||||
log.Printf("Execution source is %s for execution ID %s", workflowExecution.ExecutionSource, workflowExecution.ExecutionId)
|
||||
log.Printf("[INFO] Execution source is %s for execution ID %s", workflowExecution.ExecutionSource, workflowExecution.ExecutionId)
|
||||
}
|
||||
|
||||
workflowExecution.ExecutionVariables = workflow.ExecutionVariables
|
||||
@@ -2315,7 +2311,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
if len(workflowExecution.Start) == 0 {
|
||||
workflowExecution.Start = workflowExecution.Workflow.Start
|
||||
}
|
||||
log.Printf("STARTNODE: %s", workflowExecution.Start)
|
||||
log.Printf("[INFO] New startnode: %s", workflowExecution.Start)
|
||||
|
||||
childNodes := findChildNodes(workflowExecution, workflowExecution.Start)
|
||||
|
||||
@@ -2423,6 +2419,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
environments := []string{}
|
||||
|
||||
// Check if the actions are children of the startnode?
|
||||
imageNames := []string{}
|
||||
for _, action := range workflowExecution.Workflow.Actions {
|
||||
if action.Environment != cloudname {
|
||||
found := false
|
||||
@@ -2433,6 +2430,11 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the app exists?
|
||||
newName := action.AppName
|
||||
newName = strings.ReplaceAll(newName, " ", "-")
|
||||
imageNames = append(imageNames, fmt.Sprintf("%s:%s_%s", baseDockerName, newName, action.AppVersion))
|
||||
|
||||
if !found {
|
||||
environments = append(environments, action.Environment)
|
||||
}
|
||||
@@ -2441,6 +2443,12 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
}
|
||||
}
|
||||
|
||||
err = imageCheckBuilder(imageNames)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed building the required images from %#v: %s", imageNames, err)
|
||||
return WorkflowExecution{}, "Failed building missing Docker images", err
|
||||
}
|
||||
|
||||
err = setWorkflowExecution(ctx, workflowExecution)
|
||||
if err != nil {
|
||||
log.Printf("Error saving workflow execution for updates %s: %s", topic, err)
|
||||
@@ -2452,7 +2460,7 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
if onpremExecution {
|
||||
// FIXME - tmp name based on future companyname-companyId
|
||||
for _, environment := range environments {
|
||||
log.Printf("EXECUTION: %s should execute onprem with execution environment \"%s\"", workflowExecution.ExecutionId, environment)
|
||||
log.Printf("[INFO] Execution: %s should execute onprem with execution environment \"%s\"", workflowExecution.ExecutionId, environment)
|
||||
|
||||
executionRequest := ExecutionRequest{
|
||||
ExecutionId: workflowExecution.ExecutionId,
|
||||
@@ -2539,7 +2547,7 @@ func executeWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("STARTING EXEC OF %s!", fileId)
|
||||
log.Printf("[INFO] Starting execution of %s!", fileId)
|
||||
workflowExecution, executionResp, err := handleExecution(fileId, *workflow, request)
|
||||
|
||||
if err == nil {
|
||||
@@ -3051,26 +3059,6 @@ func getSpecificWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
resp.Write(body)
|
||||
}
|
||||
|
||||
//func setWorkflowExecutionFS(ctx context.Context, reference string, workflowExecution WorkflowExecution) error {
|
||||
// if len(workflowExecution.ExecutionId) == 0 {
|
||||
// log.Printf("Workflowexeciton executionId can't be empty.")
|
||||
// return errors.New("ExecutionId can't be empty.")
|
||||
// }
|
||||
//
|
||||
// firestoreClient, err := firestore.NewClient(ctx, shuffleTestProject, option.WithCredentialsFile(shuffleTestPath))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// executionRef := firestoreClient.Doc(reference)
|
||||
// _, err = executionRef.Set(ctx, workflowExecution)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func setWorkflowExecution(ctx context.Context, workflowExecution WorkflowExecution) error {
|
||||
if len(workflowExecution.ExecutionId) == 0 {
|
||||
log.Printf("Workflowexeciton executionId can't be empty.")
|
||||
|
||||
Reference in New Issue
Block a user