Skip to content

Commit

Permalink
snap: Support make run
Browse files Browse the repository at this point in the history
To build and boot Ubuntu-Core on virtualbox

Relate-to: https://discourse.ubuntu.com/t/propose-new-appliance-emilia-pinball-pincab-profile/22214
Relate-to: adoptware/pinball#21
Signed-off-by: Philippe Coval <[email protected]>
Change-Id: I13143c69a46aa306992233e72370677dbe2b03a7
  • Loading branch information
rzr committed May 10, 2021
1 parent ca04edf commit b7354de
Showing 1 changed file with 64 additions and 11 deletions.
75 changes: 64 additions & 11 deletions snap/image/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
project?= pinball-table-hurd

-include ~/bin/mk-private.mk
authority_id ?= TODO
brand_id ?= ${authority_id}

gadget?=pc
base?=core
base_version?=20
architecture?=amd64
name?=${project}-${base}${base_version}-${architecture}-${gadget}
channel?=edge
developer_id?=$(shell snapcraft whoami \
| grep 'developer-id:' | cut -d' ' -f2 \
|| echo "TODO: https://ubuntu.com/core/docs/custom-images")
authority_id?=${developer_id}
brand_id?=${authority_id}
ubuntu_image_snap_options?=
# image_size?=3G
# ubuntu_image_snap_options+=--image-size ${image_size}
key?=${project}
all?=version
all+=pc
all+=pi

snap_id?=$(shell snap info ${project} | grep '^snap-id:' | cut -d: -f2 | awk '{ print $1 }' || echo "TODO")

all ?= pc
all += pi

.PRECIOUS: %.model
.PRECIOUS: \
%.img \
%.model \
#EOL

default: ${name}.img.gz
du -hs $<

help:
snap keys


all: ${all}
-sync

Expand All @@ -33,13 +45,16 @@ ${name}.json: ubuntu-image-${gadget}.json Makefile
| sponge $@
jq -M . $@

image: ${name}.img.gz
du -hs $<

%.img: %.model
ubuntu-image snap -o $@ $<
ubuntu-image snap ${ubuntu_image_snap_options} -o $@ $<
mv seed.manifest $@.manifest
du -hsc $@

%.model: %.json Makefile
cat $< | snap sign -k default > $@.tmp
%.model: %.json timestamp Makefile
cat $< | snap sign -k ${key} > $@.tmp
mv $@.tmp $@

timestamp: ${name}.json
Expand All @@ -49,6 +64,7 @@ clean:
rm -fv *~ *.img *.img.gz *.model

%.img.gz: %.img
rm -f "$@"
du -hsc $<
gzip -9 $<
du -hsc $@
Expand All @@ -58,3 +74,40 @@ pc:

pi:
${MAKE} gadget=$@ architecture=arm64

version:
${MAKE} --version
ubuntu-image --version
snap --version
jq --version

%.key.tmp:
snap keys | grep "^${key}" \
|| snap create-key ${key}
snap keys | grep "^${key}" | awk '{ print $$2 }' | tee $@


register:
snapcraft list | grep '^${project} ' && exit 1
snapcraft whoami || snapcraft login
snapcraft whoami | grep '^developer-id: ${developer_id}'
snapcraft list | grep '^${project} ' || snapcraft register "${project}"
snapcraft list | grep '^${project} '

${project}.reg.tmp:
snapcraft list | grep '^${project} ' || ${MAKE} register
snapcraft list | grep '^${project} ' | tee "$@"

key: ${project}.key.tmp
ls $<

run/%: %.img
sudo qemu-system-x86_64 \
-enable-kvm -smp 2 -m 1500 -cpu host \
-device virtio-vga,virgl=on \
-drive file=/usr/share/OVMF/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::50022-:22,hostfwd=tcp::50080-:80 \
-drive file=$<,format=raw

run: run/${name}

0 comments on commit b7354de

Please sign in to comment.