diff --git a/core/plugins.in b/core/plugins.in index 60ec32f..a73f70b 100644 --- a/core/plugins.in +++ b/core/plugins.in @@ -11,7 +11,6 @@ import ( ) import ( "os" - "os/exec" ) var openedBuildPlugins map[string]Plugin @@ -89,7 +88,6 @@ func LoadBuildPlugin(name string, module interface{}, recipe *api.Recipe) (strin buildModule.LoadedPlugin = loadedPlugin openedBuildPlugins[name] = buildModule } - fmt.Printf("Using plugin: %s\n", buildModule.Name) moduleJson, err := json.Marshal(module) if err != nil { return "", err @@ -107,30 +105,6 @@ func LoadBuildPlugin(name string, module interface{}, recipe *api.Recipe) (strin } } -func getImageID(name string, runtime string) (string, error) { - runtimePath, err := exec.LookPath(runtime) - if err != nil { - return "", err - } - - out, err := exec.Command( - runtimePath, "images", - "--format=\"{{json . }}\"", - ).Output() - if err != nil { - return "", err - } - for _, image := range strings.Split(string(out), "\n") { - if strings.Contains(image, fmt.Sprintf("{\"repository\":\"localhost/%s\",\"tag\":\"latest\"", name)) { - id := strings.Split(image, "\"Id\":\"")[1] - id = strings.Split(id, "\",")[0] - return id, nil - } - } - return "", fmt.Errorf("Unable to find id for: %s", name) - -} - func LoadFinalizePlugin(name string, module interface{}, recipe *api.Recipe, runtime string) error { if openedFinalizePlugins == nil { openedFinalizePlugins = make(map[string]Plugin) @@ -155,20 +129,17 @@ func LoadFinalizePlugin(name string, module interface{}, recipe *api.Recipe, run var getPluginScope func() int32 purego.RegisterLibFunc(&getPluginScope, finalizeModule.LoadedPlugin, "PluginScope") scope := getPluginScope() - fmt.Printf("\nFinalize Plugin %s registered scope:\n", finalizeModule.Name) - fmt.Printf("Get tagged image name: %t\n", (scope&api.IMAGENAME == api.IMAGENAME)) - fmt.Printf("Get tagged image id: %t\n", (scope&api.IMAGEID == api.IMAGEID)) - fmt.Printf("Get image recipe: %t\n", (scope&api.RECIPE == api.RECIPE)) - fmt.Printf("Get build runtime: %t\n", (scope&api.RUNTIME == api.RUNTIME)) - fmt.Printf("Create read-write filesystem of image: %t\n", (scope&api.RWFS == api.RWFS)) - fmt.Printf("Create read-only filesystem of image: %t\n", (scope&api.ROFS == api.ROFS)) - fmt.Printf("Prepare filesystem to be chrooted into: %t\n\n", (scope&api.CHROOTFS == api.CHROOTFS)) + containerStorage, err := GetContainerStorage(runtime) + if err != nil { + return err + } + imageName := fmt.Sprintf("localhost/%s:latest", recipe.Id) scopedata := &api.ScopeData{} if scope&api.IMAGENAME == api.IMAGENAME { - scopedata.ImageName = fmt.Sprintf("localhost/%s:latest", recipe.Id) + scopedata.ImageName = imageName } if scope&api.IMAGEID == api.IMAGEID { - imageID, err := getImageID(recipe.Id, runtime) + imageID, err := GetImageID(imageName, containerStorage) if err != nil { return err } @@ -180,13 +151,16 @@ func LoadFinalizePlugin(name string, module interface{}, recipe *api.Recipe, run if scope&api.RUNTIME == api.RUNTIME { scopedata.Runtime = runtime } - if scope&api.RWFS == api.RWFS { - scopedata.RWFS = "TO BE IMPLEMENTED" - } else if scope&api.ROFS == api.ROFS { - scopedata.ROFS = "TO BE IMPLEMENTED" - } - if scope&api.CHROOTFS == api.CHROOTFS { - // TO BE IMPLEMENTED + if scope&api.FS == api.FS { + imageID, err := GetImageID(imageName, containerStorage) + if err != nil { + return err + } + mountpoint, err := MountImage(imageName, imageID, runtime) + if err != nil { + return err + } + scopedata.FS = mountpoint } moduleJson, err := json.Marshal(module) if err != nil { @@ -202,4 +176,4 @@ func LoadFinalizePlugin(name string, module interface{}, recipe *api.Recipe, run } else { return nil } -} \ No newline at end of file +}