Skip to content

Commit

Permalink
push plugins.in
Browse files Browse the repository at this point in the history
  • Loading branch information
axtloss committed Aug 9, 2024
1 parent 351d01b commit b9d81b0
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions core/plugins.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)
import (
"os"
"os/exec"
)

var openedBuildPlugins map[string]Plugin
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -202,4 +176,4 @@ func LoadFinalizePlugin(name string, module interface{}, recipe *api.Recipe, run
} else {
return nil
}
}
}

0 comments on commit b9d81b0

Please sign in to comment.