Files
devvm/internal/cli/layer.go
T
w3cjandClaude Opus 5.5 e6681035b2 feat(images): a built-in docker layer
Docker is a layer devvm ships, docker, chosen per VM like any layer
(devvm node+docker, devvm build docker) and added to an existing VM in
place. base installs no Docker.

- Built-in layers: image.Builtins (docker) and IsBuiltin; a name is
  looked up in devvm's assets/layers first, so a user's docker.sh is never
  read; devvm layer new docker is refused (layer_name_reserved); an
  image's key hashes the shipped script (own file, must exist); Layers,
  Environments, completion and unknown_layer/no_image_for list it;
  Env.LayerData reads either kind's script.
- assets/layers/docker.sh: Docker's apt repository (pinned key, pinned
  package versions; Alpine's own packages, rc-update, the docker group),
  the daemon started now too (OpenRC, or with no init system as
  services.sh does) for a VM it's added to in place. scripts/bump.sh's
  docker pins read it.
- assets/layers/docker.policy: Docker's packages and the registries,
  applied to VMs with the layer (netpolicy.PolicyFiles); base.policy
  keeps OS packages (Alpine's too), mise and GitHub.
- Adding layers in place sets the new image in the VM's state before
  their scripts run, so a network-policy VM's proxy allows their hosts;
  a failing script sets it back.
- smolvm's sshd.sh keeps the snapshot's package lists, for layers'
  apt-get install.
- Docs: images (base, built-in layers, keys), customizing, commands,
  network, smolvm, from, install, maintaining, design, coding-agents,
  contributing; the CLI reference; AGENTS.md's assets/ line.
- Tests: key, layers, build, policy files, in-place add (devvm's script,
  image during the run, set back on failure), layer new docker; e2e:
  a base VM has no Docker (Lima, smolvm), the docker layer on Debian 12
  and Alpine (from), and smolvm's network-policy VM is a docker VM whose
  Docker pulls through the proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 07:18:30 -06:00

44 lines
1.5 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/w3cj/devvm/internal/build"
"github.com/w3cj/devvm/internal/msg"
"github.com/w3cj/devvm/internal/paths"
"github.com/w3cj/devvm/internal/ui"
)
// newLayerCmd is devvm layer new NAME.
func newLayerCmd(u *ui.UI) *cobra.Command {
cmd := &cobra.Command{
Use: "layer",
Short: "Your own image layers",
Long: "Your own image layers: scripts in ~/.config/devvm/layers that an image runs on top of base, " +
"named in images like the shared tools and devvm's built-in layers (node+docker+NAME).",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error { return cmd.Help() },
}
cmd.AddCommand(&cobra.Command{
Use: "new NAME",
Short: "Start a layer of your own",
Long: "Start a layer: ~/.config/devvm/layers/NAME.sh, a script to edit, and NAME.policy next to it, " +
"the hosts VMs with the layer can reach with network policy (kept if it exists). NAME is " +
"lowercase letters, digits and dashes, and not base, a built-in layer's (docker) or a shared " +
"tool's. Then devvm build NAME " +
"builds its image, and devvm node+NAME makes a VM with it.",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
dirs, err := paths.FromEnv()
var script, policy string
if err == nil {
script, policy, err = build.NewLayer(dirs, args[0])
}
fail(u, err, msg.LayerNewFailed)
u.Info(msg.LayerCreated(args[0], policy, script))
return nil
},
})
return cmd
}