Build a GCE image

- this is a raw 1GB filesystem image with syslinux for booting
- built with libguestfs so does not need any privileges
- need not be built on GCE
- there is a target that runs the image in qemu for local tests

Does not yet have a script to upload the image to cloud storage or create image from it.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack
2016-12-12 19:17:24 -08:00
parent 73c1134f99
commit 9245dd656f
10 changed files with 122 additions and 1 deletions

1
alpine/.gitignore vendored
View File

@@ -2,6 +2,7 @@
*.tag
*.iso
*.vhd
*.tar.gz
/mobylinux-boot.vhdx
/mobylinux.efi
etc/moby-commit

View File

@@ -16,6 +16,9 @@ BIOS_IMAGE=mobylinux/mkimage-iso-bios@sha256:7e28f7745fd62284142dce59a137c3331f7
# Tag: 95d4fef1a9555b640b4f94a4a3968533714059fe
PAD4_IMAGE=mobylinux/pad4@sha256:a26e02f16bdafa241a55e05fa09b9bb260e69a3a8c90418bb40b4ae936437d17
# Tag: df1b8ef666d66694e84f23772937ff45c46fa6c1
GCE_IMAGE=mobylinux/mkimage-gce@sha256:b19ba24184ed5602df5b666ed475d5d7211fa67bee51d3e6380cf0380c63f65b
moby.img: Dockerfile mkinitrd.sh init $(ETCFILES)
$(MAKE) -C kernel
$(MAKE) -j -C packages
@@ -76,7 +79,13 @@ mobylinux-efi.iso: Dockerfile.efi initrd.img kernel/x86_64/vmlinuz64
mobylinux-bios.iso: initrd.img kernel/x86_64/vmlinuz64
tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
docker run --rm --net=none --log-driver=none -i $(BIOS_IMAGE) >$@
docker run --rm --net=none --log-driver=none -i $(BIOS_IMAGE) >$@
gce: gce.img.tar.gz
gce.img.tar.gz: common
tar cf - initrd.img -C kernel/x86_64 vmlinuz64 | \
docker run --rm --net=none --log-driver=none -i $(GCE_IMAGE) >$@
common: initrd.img
$(MAKE) -C kernel

View File

@@ -0,0 +1,4 @@
FROM debian:jessie
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get -yq upgrade && apt-get install -yq libguestfs-tools syslinux linux-image-amd64 vim

View File

@@ -0,0 +1,29 @@
.PHONY: tag push
BASE=debian:jessie
IMAGE=guestfs
default: push
hash: Dockerfile
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm $(IMAGE):build sh -c 'apt list --installed 2>/dev/null | sha1sum' | sed 's/ .*//' > hash
push: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
docker push mobylinux/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
clean:
rm -f hash
.DELETE_ON_ERROR:

View File

@@ -0,0 +1,10 @@
# Tag: 8719f0f33b3cf9d59a62be64a42220978ac96486
FROM mobylinux/guestfs@sha256:c7229f01c1a54270d2bc3597c30121628c18db211ed32fb7202823b6eaa4f853
WORKDIR /tmp/image
COPY . .
COPY make-gce /usr/bin
CMD [ "/usr/bin/make-gce" ]

View File

@@ -0,0 +1,27 @@
.PHONY: tag push
IMAGE=mkimage-gce
default: push
hash: Dockerfile make-gce syslinux.cfg
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm $(IMAGE):build sh -c "(cat $^; apt list --installed 2>/dev/null) | sha1sum" | sed 's/ .*//' > hash
push: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
docker push mobylinux/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
clean:
rm -f hash
.DELETE_ON_ERROR:

View File

@@ -0,0 +1,25 @@
#!/bin/sh
set -e
# input is a tarball of vmlinuz64 and initrd.img on stdin
# output is a compressed tarball of a raw disk image on stdout
mkdir -p files
tar xf - -C files
cp syslinux.cfg files
tar cf files.tar -C files .
virt-make-fs --size=1G --type=ext4 --partition files.tar disk.raw
guestfish -a disk.raw -m /dev/sda1 <<EOF
upload /usr/lib/SYSLINUX/mbr.bin /mbr.bin
copy-file-to-device /mbr.bin /dev/sda size:440
rm /mbr.bin
extlinux /
part-set-bootable /dev/sda 1 true
EOF
tar cf - disk.raw | gzip -9

View File

@@ -0,0 +1,5 @@
DEFAULT linux
LABEL linux
KERNEL /vmlinuz64
INITRD /initrd.img
APPEND earlyprintk=ttyS0,115200 console=ttyS0,115200