skiffos / SkiffOS

Any Linux distribution, anywhere.
https://skiffos.com
MIT License
703 stars 52 forks source link

virt/incus: Add support for building and running incus containers #315

Closed theCalcaholic closed 2 months ago

theCalcaholic commented 2 months ago

This PR implements support for generating incus/LXD images (and running incus containers). I have been using your implementation of the virt/docker and virt/qemu packages as inspiration. Looking forward to your feedback.

For convenience, here's the package Readme:


Containerized: Incus

This package builds a SkiffOS system for use as a Incus container image.

Incus containers are versatile system containers that, as opposed to application containers like docker, emulate a full init system by default (more details here) and are therefore well suited for multi service/container deployments. Incus utilizes the LXC APIs internally and provides a powerful toolset on top of them.

Building and starting the container requires incus to be installed and running on the host and the executing user to be in the incus-admin group.

Example

SKIFF_CONFIG=virt/incus make configure compile # Compile the system
make cmd/virt/incus/buildimage
make cmd/virt/incus/run

Executing a shell in the container:

$ make cmd/virt/incus/exec
# alternatively
$ incus exec skiff -- sh

Persistence

When using the included command cmd/virt/incus/run for creating the container, a persistence volume will be created in the first incus storage pool available and attached to the container. If you want to reset the persistence volume, just delete it, so it will be recreated:

# You can find the right storage pool with:
# incus storage list -c n -f csv | head -n 1
incus volume delete "${STORAGE_POOL}" skiff-persist
theCalcaholic commented 2 months ago

Thanks for the review! I'm on the bus right now, will make the adjustments later.

theCalcaholic commented 2 months ago

I pushed the requested changes. Let me know, if there's anything else :)

paralin commented 2 months ago

@theCalcaholic Thanks! I would be interested in adding Incus to buildroot and SkiffOS as a option for hosting containers as well.

paralin commented 2 months ago

go install mvdan.cc/sh/v3/cmd/shfmt@latest shfmt -l -w thing.sh

I am running shfmt on your scripts and a few minor changes, will apply them while merging! Thanks!

theCalcaholic commented 2 months ago

@theCalcaholic Thanks! I would be interested in adding Incus to buildroot and SkiffOS as a option for hosting containers as well.

That would be cool. Unfortunately I have no experience with adding new packages to buildroot - do you have an example you could point me to?

incus can run both containers and VMs btw, so it might make sense to add the latter as well as build target (never used them much personally, though).

paralin commented 2 months ago

@theCalcaholic

It appears incus is a Go project, so you can add one just copying + changing:

That should be about it! Also see the buildroot manual: https://nightly.buildroot.org/manual.html#_infrastructure_for_go_packages