diff --git a/cmd/incus-simplestreams/main_remove.go b/cmd/incus-simplestreams/main_remove.go index 275754f7ee6..7d6cab2ef97 100644 --- a/cmd/incus-simplestreams/main_remove.go +++ b/cmd/incus-simplestreams/main_remove.go @@ -65,55 +65,41 @@ func (c *cmdRemove) Run(cmd *cobra.Command, args []string) error { } for kVersion, version := range product.Versions { - // Find the incus.tar.xz and figure out what to delete. - var deleteDisk bool - var deleteSquashfs bool - var metadataPath string - - for _, item := range version.Items { - if item.FileType != "incus.tar.xz" { - continue - } - - metadataPath = item.Path - - if item.CombinedSha256DiskKvmImg == image.Fingerprint { - deleteDisk = true - break - } - - if item.CombinedSha256SquashFs == image.Fingerprint { - deleteSquashfs = true - break - } + // Get the metadata entry. + metaEntry, ok := version.Items["incus.tar.xz"] + if !ok { + // Image isn't using our normal structure. + continue } - // Delete the entry and associated files. - for kItem, item := range version.Items { - if deleteDisk && item.FileType == "disk-kvm.img" { - err = os.Remove(item.Path) - if err != nil && !os.IsNotExist(err) { - return err - } - - delete(version.Items, kItem) - break + if metaEntry.CombinedSha256DiskKvmImg == image.Fingerprint { + // Deleting a VM image. + err = os.Remove(version.Items["disk-kvm.img"].Path) + if err != nil && !os.IsNotExist(err) { + return err } - if deleteSquashfs && item.FileType == "squashfs" { - err = os.Remove(item.Path) - if err != nil && !os.IsNotExist(err) { - return err - } - - delete(version.Items, kItem) - break + delete(version.Items, "disk-kvm.img") + metaEntry.CombinedSha256DiskKvmImg = "" + } else if metaEntry.CombinedSha256SquashFs == image.Fingerprint { + // Deleting a container image. + err = os.Remove(version.Items["squashfs"].Path) + if err != nil && !os.IsNotExist(err) { + return err } + + delete(version.Items, "squashfs") + metaEntry.CombinedSha256SquashFs = "" + } else { + continue } + // Update the metadata entry. + version.Items["incus.tar.xz"] = metaEntry + // Delete the version if it's now empty. if len(version.Items) == 1 { - err = os.Remove(metadataPath) + err = os.Remove(metaEntry.Path) if err != nil && !os.IsNotExist(err) { return err } diff --git a/doc/images.md b/doc/images.md index 238c3918bb2..cdfe682291d 100644 --- a/doc/images.md +++ b/doc/images.md @@ -10,6 +10,6 @@ Manage images Copy and import images Create images Associate profiles -reference/remote_image_servers reference/image_format +reference/image_servers ``` diff --git a/doc/reference/remote_image_servers.md b/doc/reference/image_servers.md similarity index 54% rename from doc/reference/remote_image_servers.md rename to doc/reference/image_servers.md index 935eb5e7d72..69a96044fec 100644 --- a/doc/reference/remote_image_servers.md +++ b/doc/reference/image_servers.md @@ -1,7 +1,7 @@ -(remote-image-servers)= -# Remote image servers +(image-servers)= +# Default image server -The [`incus`](incus.md) CLI command comes pre-configured with the following default remote image servers: +The [`incus`](incus.md) CLI command comes pre-configured with the following default remote image server: `images:` : This server provides unofficial images for a variety of Linux distributions. @@ -9,14 +9,17 @@ The [`incus`](incus.md) CLI command comes pre-configured with the following defa See [`images.linuxcontainers.org`](https://images.linuxcontainers.org) for an overview of available images. -(remote-image-server-types)= -## Remote server types +Additional image servers can be added through `incus remote add`. + +(image-server-types)= +## Image server types Incus supports the following types of remote image servers: Simple streams servers : Pure image servers that use the [simple streams format](https://git.launchpad.net/simplestreams/tree/). - The default image servers are simple streams servers. + No special software is required to run such a server as it's only made of static files. + The default `images:` server uses simplestreams. Public Incus servers : Incus servers that are used solely to serve images and do not run instances themselves. @@ -29,3 +32,16 @@ Incus servers For security reasons, you should restrict the access to the remote API and configure an authentication method to control access. See {ref}`server-expose` and {ref}`authentication` for more information. + +(image-server-tooling)= +## Tooling to manage a simplestreams server +Incus includes a tool called `incus-simplestreams` which can be used to manage a file system tree using the Simple streams format. + +It supports importing either a container (`squashfs`) or virtual-machine (`qcow2`) image +with `incus-simplestreams add`, list all images available as well as their fingerprints +with `incus-simplestreams list` and remove images from the server with `incus-simplestreams remove`. + +That file system tree must then be placed on a regular web server which supports HTTPS with a valid certificate. + +When importing an image that doesn't come with an Incus metadata tarball, the `incus-simplestreams generate-metadata` command +can be used to generate a new basic metadata tarball from a few questions.