virtapi / installimage

bash scripts for deploying every linux system
Other
37 stars 14 forks source link

provide automatic way for building images #38

Open bastelfreak opened 8 years ago

bastelfreak commented 8 years ago

can we please do something awesome here? building images with FPM? with nspawn? @killermoehre @bluewind your opinions?

bastelfreak commented 8 years ago

what about some systemd-nspawn magic + debootstrap/yum?

bastelfreak commented 8 years ago

the normal approach would be to setup a virtual machine, install a minimal OS by hand, boot it into the rescue, tar that stuff together, create gpg sigs and you are done. This could somehow be automated with virt-install / cloudinit.

bastelfreak commented 8 years ago

also it needs to be discussed if it is necessary to automate the complete build process or only a update/rebuild process.

bastelfreak commented 8 years ago

Does anybody likes pain and wants tests in serverspec for images?

bastelfreak commented 8 years ago

Maybe we want to take a look at the Hashicorp Toolstack, they recently created Packer

killermoehre commented 8 years ago

nspawn is a rather bad idea if you want to build real (virtual) machines which will have there own (virtual) hardware. If you want to pre-populate a directory with packages you don't need nspawn neither. With (pac|deboot)strap and yum/dnf you can install where you want and place your config file in it. Just need to package it afterwards and sign it.

bastelfreak commented 8 years ago

@killermoehre recommended https://de.opensuse.org/Portal:KIWI on the IRC

ghost commented 8 years ago

Perhaps it would be a good start to document first what an image for installimage actually needs to contain and how the process of building an image without using the distribution installer would look like. Would something like.

  1. Run debootstrap
  2. bind mount the usual dirs (/dev, /proc, /sys)
  3. chroot into the bootstraped system
  4. Install the kernel
  5. Exit chroot and umount bind-mounted dirs
  6. Create tar.gz
  7. Profit

be sufficient? Are there any packages or services that have to be installed, others that are recommended for convenience that are not included in the minimal installation created by the distribution specific utilities?

killermoehre commented 8 years ago
  1. bind mount the usual dirs (/dev, /proc, /sys)
  2. chroot into the bootstraped system

  1. Exit chroot and umount bind-mounted dirs

@heg-hpo the arch-install-scripts should cover this very nice.

bastelfreak commented 8 years ago

@heg-hpo ntp and ssh have to be installed, thats all.

using nspawn instead of chroot is the prefered way for everything that runs on systemd. The installimage already has functions to set that up.

killermoehre commented 8 years ago

@bastelfreak how do you want to configure the file system layout for this images? Doing everything on one (virtual) disk with one partition is easy. I see the problems with different partition layouts. At install time at least »/«, »/var« and »/usr« have to be available (providing /usr via shared storage is somehow common in virtualised environments, a /var on nfs helps to keep things central).

bastelfreak commented 8 years ago

there isn't any need to have multiple partitions for creating an image.

killermoehre commented 8 years ago

There is a need to put them in the /etc/fstab.

bastelfreak commented 8 years ago

we don't have to do that while building the image. installimage will rewrite the fstab.

killermoehre commented 8 years ago

So, if we use LARS as base build platform for abriatary distributions, than it should be quite easy.

  1. get the source definition of $DISTRIBUTION in $VERSION
  2. use debootstrap/dnf/pacstrap (from [aur] or [community]) together with the source definition to install systemd/init, bash, and $PACKAGE_MANAGER with dependencies (minimal golden image; keep updated regular) (don't forget implicit deps like sed, grep and awk)
  3. copy this golden image (rsync ftw \o/) to a working dir
  4. boot this working dir as nspawn
  5. bring up network in nspawn (reaching the package server) (systemd-run -M or machinectl shell) OR bind mount the already downloaded packages in the package cache
  6. install kernel, bootloader, ntp, ssh and $ADDITIONAL_SOFTWARE[@] (systemd-run -M or machinectl shell)
  7. quit the machine
  8. machinectl export-tar $MACHINE_DIR $OUTPUT_IMAGE.tar.gz
bastelfreak commented 8 years ago

and then wrap all in jenkins to have CD and (kind of) reproducible builds.