-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for finalize plugins
- Loading branch information
Showing
21 changed files
with
1,366 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package api | ||
|
||
// / Get the final tagged Image name | ||
var IMAGENAME int32 = 1 | ||
|
||
// / Get the final tagged Image ID | ||
var IMAGEID int32 = 2 | ||
|
||
// / Get the build recipe | ||
var RECIPE int32 = 4 | ||
|
||
// Get the used build runtime | ||
var RUNTIME int32 = 8 | ||
|
||
// / Get a read-only filesystem of the Image | ||
var FS int32 = 16 | ||
|
||
type ScopeData struct { | ||
ImageName string | ||
ImageID string | ||
Recipe Recipe | ||
Runtime string | ||
FS string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
cstorage "github.com/containers/storage" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type StorageConf struct { | ||
Driver string | ||
Runroot string | ||
Graphroot string | ||
} | ||
|
||
func GetContainerStorage(runtime string) (cstorage.Store, error) { | ||
storageconfig := &StorageConf{} | ||
if runtime == "podman" { | ||
podmanPath, err := exec.LookPath("podman") | ||
out, err := exec.Command( | ||
podmanPath, "info", "-f json").Output() | ||
if err != nil { | ||
fmt.Println("Failed to get podman info") | ||
} else { | ||
driver := strings.Split(strings.Split(string(out), "\"graphDriverName\": \"")[1], "\",")[0] | ||
storageconfig.Driver = driver | ||
|
||
graphRoot := strings.Split(strings.Split(string(out), "\"graphRoot\": \"")[1], "\",")[0] | ||
storageconfig.Graphroot = graphRoot | ||
|
||
runRoot := strings.Split(strings.Split(string(out), "\"runRoot\": \"")[1], "\",")[0] | ||
storageconfig.Runroot = runRoot | ||
} | ||
|
||
} | ||
if storageconfig.Runroot == "" { | ||
storageconfig.Runroot = "/var/lib/vib/runroot" | ||
storageconfig.Graphroot = "/var/lib/vib/graphroot" | ||
storageconfig.Driver = "overlay" | ||
} | ||
store, err := cstorage.GetStore(cstorage.StoreOptions{ | ||
RunRoot: storageconfig.Runroot, | ||
GraphRoot: storageconfig.Graphroot, | ||
GraphDriverName: storageconfig.Driver, | ||
}) | ||
if err != nil { | ||
return store, err | ||
} | ||
|
||
return store, err | ||
} | ||
|
||
func GetImageID(name string, store cstorage.Store) (string, error) { | ||
images, err := store.Images() | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, img := range images { | ||
for _, imgname := range img.Names { | ||
if imgname == name { | ||
return img.ID, nil | ||
} | ||
} | ||
} | ||
return "", fmt.Errorf("image not found") | ||
} | ||
|
||
func GetTopLayerID(imageid string, store cstorage.Store) (string, error) { | ||
images, err := store.Images() | ||
if err != nil { | ||
return "", err | ||
} | ||
for _, img := range images { | ||
if img.ID == imageid { | ||
return img.TopLayer, nil | ||
} | ||
} | ||
return "", fmt.Errorf("no top layer for id %s found", imageid) | ||
} | ||
|
||
func MountImage(imagename string, imageid string, runtime string) (string, error) { | ||
store, err := GetContainerStorage(runtime) | ||
if err != nil { | ||
return "", err | ||
} | ||
topLayerID, err := GetTopLayerID(imageid, store) | ||
if err != nil { | ||
return "", err | ||
} | ||
mountDir, err := store.Mount(topLayerID, "") | ||
if err != nil { | ||
return "", err | ||
} | ||
return mountDir, err | ||
} |
Oops, something went wrong.