|
1 | | -# `builder` scripts |
| 1 | +# Introduction |
2 | 2 |
|
3 | | -See [documentation](https://github.com/scaleway/image-builder). |
| 3 | +If you're looking for explanations about how to use the image builder, you can refer to [its documentation](https://github.com/scaleway/image-builder). |
| 4 | +This document is an introduction to the internals behind it. |
| 5 | + |
| 6 | +The current build process uses docker to produce disk images for all supported architectures. |
| 7 | +The program in charge of doing so is `docker-rules.mk`, which is downloaded when building an scaleway image. |
| 8 | + |
| 9 | +Using this docker image, it can then create the rootfs that would run on your server and export it to some storage drivers. |
| 10 | + |
| 11 | +## Did you say architecture`s`? |
| 12 | +As docker does not natively support building and running images for other architectures, the image builder relies on [docker multiarch](https://hub.docker.com/u/multiarch/) to do so. |
| 13 | + |
| 14 | +multiarch uses `binfmt` to register a hook running the `qemu` emulator with programs meant for architectures different from the host's. Even if it works fairly well, it doesn't always work well enough to perform some operations, so you might have to find to workarounds. |
| 15 | + |
| 16 | +## Well, ok, but how does it *actually* work ? |
| 17 | + |
| 18 | +### Step 1: Generating the architecture-specific docker project |
| 19 | + |
| 20 | +As you might have noticed, the Dockerfiles of multiarch-powered projects have multiple commented `FROM` statements. `docker-rules.mk` chooses the first one matching the target architecture using some sed magic. |
| 21 | + |
| 22 | +The new Dockerfile is then copied to a separate folder, named `tmp-$(ARCH)`, along with `overlay/` and some others. |
| 23 | + |
| 24 | +### Step 2: Building |
| 25 | + |
| 26 | +Using the newly built architecture-specific project, the makefile runs docker to build and tag the image. |
| 27 | + |
| 28 | +The whole build process relies on `qemu`. You can find its binary distribution at `/usr/bin/qemu-$(ARCH)-static` inside the container. |
| 29 | + |
| 30 | +### Step 3: Exporting |
| 31 | + |
| 32 | +The export process works as follows: |
| 33 | + |
| 34 | + - Create a new machine with some tags telling it to drop a ssh server at the end of initrd |
| 35 | + - Once it's up, connect to it and write the rootfs to the attached image |
| 36 | + - Stop the server |
| 37 | + - Create a snapshot of the attached disk |
| 38 | + - Convert it to an image |
| 39 | + |
| 40 | + This whole process is performed by [`create-image-from-http.sh`](https://github.com/scaleway/scaleway-cli/blob/master/examples/create-image-from-http.sh). |
| 41 | + |
| 42 | +Exporting to an s3 compatible server is also possible. |
0 commit comments