-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow loading images by name from imagestore
Signed-off-by: Anders F Björklund <[email protected]>
- Loading branch information
1 parent
726f61d
commit 6cb5215
Showing
12 changed files
with
182 additions
and
16 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,14 @@ | ||
images: | ||
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months. | ||
- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
digest: "sha256:32a9d30d18803da72f5936cf2b7b9efcb4d0bb63c67933f17e3bdfd1751de3f3" | ||
- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" | ||
digest: "sha256:c841bac00925d3e6892d979798103a867931f255f28fefd9d5e07e3e22d0ef22" | ||
# Fallback to the latest release image. | ||
# Hint: run `limactl prune` to invalidate the cache | ||
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img" | ||
arch: "x86_64" | ||
- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img" | ||
arch: "aarch64" |
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,63 @@ | ||
package imagestore | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
securejoin "github.com/cyphar/filepath-securejoin" | ||
"github.com/lima-vm/lima/pkg/usrlocalsharelima" | ||
) | ||
|
||
type Image struct { | ||
Name string `json:"name"` | ||
Location string `json:"location"` | ||
} | ||
|
||
func Read(name string) ([]byte, error) { | ||
dir, err := usrlocalsharelima.Dir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if name == "default" { | ||
name = Default | ||
} | ||
yamlPath, err := securejoin.SecureJoin(filepath.Join(dir, "images"), name+".yaml") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return os.ReadFile(yamlPath) | ||
} | ||
|
||
const Default = "ubuntu-24.04" | ||
|
||
func Images() ([]Image, error) { | ||
usrlocalsharelimaDir, err := usrlocalsharelima.Dir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
imagesDir := filepath.Join(usrlocalsharelimaDir, "images") | ||
|
||
var res []Image | ||
walkDirFn := func(p string, _ fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
base := filepath.Base(p) | ||
if strings.HasPrefix(base, ".") || !strings.HasSuffix(base, ".yaml") { | ||
return nil | ||
} | ||
x := Image{ | ||
// Name is like "ubuntu-24.04", "debian-12", ... | ||
Name: strings.TrimSuffix(strings.TrimPrefix(p, imagesDir+"/"), ".yaml"), | ||
Location: p, | ||
} | ||
res = append(res, x) | ||
return nil | ||
} | ||
if err = filepath.WalkDir(imagesDir, walkDirFn); err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} |
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 @@ | ||
../../images/ubuntu-24.04.yaml |
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