Merge lp:~tobijk/livecd-rootfs/image-sets into lp:livecd-rootfs

Proposed by Tobias Koch
Status: Merged
Merged at revision: 1735
Proposed branch: lp:~tobijk/livecd-rootfs/image-sets
Merge into: lp:livecd-rootfs
Diff against target: 565 lines (+343/-62)
18 files modified
live-build/auto/config (+13/-0)
live-build/ubuntu-cpc/README.cpc.md (+68/-0)
live-build/ubuntu-cpc/hooks.d/base/disk-image.binary (+3/-1)
live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary (+0/-9)
live-build/ubuntu-cpc/hooks.d/base/root-squashfs.binary (+0/-9)
live-build/ubuntu-cpc/hooks.d/base/series/base (+7/-0)
live-build/ubuntu-cpc/hooks.d/base/series/disk-image (+3/-0)
live-build/ubuntu-cpc/hooks.d/base/series/qcow2 (+2/-0)
live-build/ubuntu-cpc/hooks.d/base/series/root-dir (+1/-0)
live-build/ubuntu-cpc/hooks.d/base/series/squashfs (+2/-0)
live-build/ubuntu-cpc/hooks.d/base/series/tarball (+2/-0)
live-build/ubuntu-cpc/hooks.d/base/series/vagrant (+2/-0)
live-build/ubuntu-cpc/hooks.d/base/series/vmdk (+3/-0)
live-build/ubuntu-cpc/hooks.d/base/vagrant.binary (+0/-9)
live-build/ubuntu-cpc/hooks.d/base/vmdk-image.binary (+0/-9)
live-build/ubuntu-cpc/hooks.d/base/vmdk-ova-image.binary (+0/-9)
live-build/ubuntu-cpc/hooks.d/make-hooks (+237/-0)
live-build/ubuntu-cpc/hooks/999-extras.binary (+0/-16)
To merge this branch: bzr merge lp:~tobijk/livecd-rootfs/image-sets
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Philip Roche (community) Abstain
Dan Watkins (community) Approve
Francis Ginther (community) Approve
Review via email: mp+356246@code.launchpad.net

Commit message

Use series files with dependency handling to generate hook symlinks dynamically

This patch currently only applies to the "ubuntu-cpc" project.

More and more logic has been going into the hook scripts to decide under which conditions they should run or not. As we are moving to parallelized builds of image sets, this will get even more complicated. Base hooks will have to know which image sets they belong to and modification of the dependency chain between scripts will become more complicated and prone to errors, as the number of image sets grows.

This patch introduces explicit ordering and dependency handling for scripts through the use of `series` files and an explicit syntax for dependency specification.

Description of the change

Please read

    https://bazaar.launchpad.net/~tobijk/livecd-rootfs/image-sets/view/head:/live-build/ubuntu-cpc/README.cpc.md

In order to try out the hook generation, change to

    live-build/ubuntu-cpc/hooks.d

and call `make-hooks` with different arguments, for example:

    ./make-hooks --hooks-dir hook-test vagrant

or

    ./make-hooks --hooks-dir hook-test squashfs disk-image vagrant

Take a look at hooks.d/base/series for available series files.

To post a comment you must log in.
Revision history for this message
Dan Watkins (oddbloke) wrote :

Overall, I really like this. The code is well laid out, and the series concept should serve us well in the future due to its flexibility. Thanks!

(I have some inline comments on the Python script, but none of these relate to the overall behaviour of the script or this MP.)

review: Needs Fixing
Revision history for this message
Tobias Koch (tobijk) wrote :

Thanks a lot for the detailed review, @daniel-thewatkins! I think I have addressed everything you brought up in the new submission below. I also verified that the script works as Python3-only on Xenial.

Revision history for this message
Philip Roche (philroche) wrote :

Very nice approach and the Readme is very helpful. I would like some docstrings in the python script though as I know future me will need them ;p

Apart from that I am +1

review: Needs Fixing
Revision history for this message
Tobias Koch (tobijk) wrote :

Thank you @philroche, let me know if this works or if anything needs further clarification.

Revision history for this message
Francis Ginther (fginther) wrote :

Is the intention that the execution order of hooks be identical once this change lands? That currently isn't the case and may lead to changes in the images. For example, the following generates:

./make-hooks --hooks-dir ../hooks vmdk vagrant
...
[HOOK] 005-ssh_authentication.chroot => chroot/ssh_authentication.chroot
...
[HOOK] 016-vagrant.binary => base/vagrant.binary

But prior to this change, these two hooks were in the opposite order:

042-vagrant.binary
052-ssh_authentication.chroot

Am I missing something (like are all the chroot hooks executed before the binary hooks)?

I also have a concern with defining the RESOURCE map in the make-hooks script (see inline comment).

Otherwise, I think this is a good approach to the problem. Thanks for working on it.

review: Needs Fixing
Revision history for this message
Steve Langasek (vorlon) wrote :

On Thu, Oct 25, 2018 at 03:47:11PM -0000, Francis Ginther wrote:
> Am I missing something (like are all the chroot hooks executed before the
> binary hooks)?

Yes, all chroot hooks are executed before the binary hooks.

Revision history for this message
Tobias Koch (tobijk) wrote :

> Am I missing something (like are all the chroot hooks executed before the
> binary hooks)?

Yes, exactly, chroot hooks and binary hooks are run in separate batches, it is not possible to interleave them. See the ACHTUNG note in the script header.

Revision history for this message
Francis Ginther (fginther) wrote :

> > Am I missing something (like are all the chroot hooks executed before the
> > binary hooks)?
>
> Yes, exactly, chroot hooks and binary hooks are run in separate batches, it is
> not possible to interleave them. See the ACHTUNG note in the script header.

DOH! Thanks for already mentioning this in the comments.

My only remaining concern is the definition of the extra RESOURCES.

Revision history for this message
Tobias Koch (tobijk) wrote :

@fginther, nobody reads the comments ;) I think you having missed that piece of information is really just bad documentation. I added the same note to the README, where it really belongs.

Thank you for suggesting to take out the resource mappings. That really makes a lot of sense. Following your suggestion, the script now looks for base/resources.yaml and extra/resources.yaml.

I also updated

https://code.launchpad.net/~cloudware/livecd-rootfs/+git/cpc_packaging.extra/+merge/356266

to match these changes.

@daniel-thewatkins, @philroche, I believe I have addressed your concerns, as well. Please have another look.

Revision history for this message
Francis Ginther (fginther) wrote :

Thanks for working on the resource map. I'm happy with this approach.

I do prefer to use yaml.safe_load() over yaml.load(), but I think it's use is fine here considering we're only loading our own code.

review: Approve
Revision history for this message
Dan Watkins (oddbloke) wrote :

Thanks!

review: Approve
Revision history for this message
Philip Roche (philroche) wrote :

Happy to go merge with the two current approvals

review: Abstain
Revision history for this message
Steve Langasek (vorlon) wrote :

Apologies for taking so long to give feedback on this. I knew that such a significant refactor was owed a thorough review, and I didn't find time to do so until now.

Comments inline.

review: Needs Fixing
Revision history for this message
Tobias Koch (tobijk) wrote :

Also revamped this taking into account @xnox's comments on

https://code.launchpad.net/~tobijk/livecd-rootfs/snap-coherence/+merge/358632

Revision history for this message
Tobias Koch (tobijk) wrote :

@vorlon, thank you so much for taking the time to review this in depth!

* There is now also a series file for the qcow2 target.

* It turned out that copying resources was not even necessary, because all scripts except one reference resources relative to their location. So I have removed that part completely.

I would like to keep the series file for the chroot, because:

* I find it more consistent to have all hooks placed/generated in the same way in the CPC subproject.

* We will want to augment the syntax of the series files in the future to also take into account arch, subarch and other attributes of the build that are currently handled by case statements in the scripts and this can also be useful for chroot customization,

* This is not on the table, right now, but I can imagine that we will find it useful to drop the ability to build different image target sets together and do per target set (and arch) chroot customizations. There can be advantages to this such being able to seed all target specific packages and snaps into the chroot instead of having to mount, fiddle and re-sparsen an image.

Revision history for this message
Dan Watkins (oddbloke) wrote :

On Fri, Nov 30, 2018 at 01:01:15PM -0000, Tobias Koch wrote:
> * This is not on the table, right now, but I can imagine that we will find it useful to drop the ability to build different image target sets together and do per target set (and arch) chroot customizations. There can be advantages to this such being able to seed all target specific packages and snaps into the chroot instead of having to mount, fiddle and re-sparsen an image.

+1, we definitely want to leave the door open to be able to do this in
the future.

Revision history for this message
Steve Langasek (vorlon) wrote :

On Fri, Nov 30, 2018 at 02:27:22PM -0000, Dan Watkins wrote:
> On Fri, Nov 30, 2018 at 01:01:15PM -0000, Tobias Koch wrote:
> > * This is not on the table, right now, but I can imagine that we will
> > find it useful to drop the ability to build different image target
> > sets together and do per target set (and arch) chroot customizations.
> > There can be advantages to this such being able to seed all target
> > specific packages and snaps into the chroot instead of having to
> > mount, fiddle and re-sparsen an image.

> +1, we definitely want to leave the door open to be able to do this in
> the future.

I would argue, however, that until this actually *is* on the table, such
handling of chroot scripts is still just unnecessary complexity.

Revision history for this message
Tobias Koch (tobijk) wrote :

So is that a veto? Subsystem maintainers are +1.

Revision history for this message
Steve Langasek (vorlon) wrote :

> So is that a veto? Subsystem maintainers are +1.

Yes, I think I do have to insist that the changes to chroot hooks not be included here. Having to keep the list of chroot hooks in sync between the directory contents and the series file is error-prone, and should be avoided unless and until there is a reason to define a series that doesn't include all the chroot hooks.

review: Needs Fixing
Revision history for this message
Tobias Koch (tobijk) wrote :

@vorlon, I have made the necessary changes. Please check, if you are ok with this. Thanks!

Revision history for this message
Steve Langasek (vorlon) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'live-build/auto/config'
--- live-build/auto/config 2018-11-28 15:05:24 +0000
+++ live-build/auto/config 2018-12-10 08:29:28 +0000
@@ -1026,6 +1026,19 @@
1026 ubuntu-touch:*|ubuntu-touch-custom:*|ubuntu-core:system-image|ubuntu-desktop-next:system-image|ubuntu-cpc:*|ubuntu-server:live)1026 ubuntu-touch:*|ubuntu-touch-custom:*|ubuntu-core:system-image|ubuntu-desktop-next:system-image|ubuntu-cpc:*|ubuntu-server:live)
1027 cp -af /usr/share/livecd-rootfs/live-build/${PROJECT}/* \1027 cp -af /usr/share/livecd-rootfs/live-build/${PROJECT}/* \
1028 config/1028 config/
1029
1030 if [ "$PROJECT" = "ubuntu-cpc" ]; then
1031 case ${IMAGE_TARGETS:-} in
1032 "")
1033 config/hooks.d/make-hooks --hooks-dir config/hooks all
1034 ;;
1035 *)
1036 config/hooks.d/make-hooks --hooks-dir config/hooks \
1037 "$IMAGE_TARGETS"
1038 ;;
1039 esac
1040 fi
1041
1029 if [ "$IMAGEFORMAT" = none ]; then1042 if [ "$IMAGEFORMAT" = none ]; then
1030 rm -f config/hooks/*.binary*1043 rm -f config/hooks/*.binary*
1031 fi1044 fi
10321045
=== added file 'live-build/ubuntu-cpc/README.cpc.md'
--- live-build/ubuntu-cpc/README.cpc.md 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/README.cpc.md 2018-12-10 08:29:28 +0000
@@ -0,0 +1,68 @@
1# TL;DR
2
3In order to generate the hooks for a specific image target set, call the
4`make-hooks` script, located in `hooks.d` as
5
6 ./make-hooks --hooks-dir ../hooks <image_set>
7
8where `image_set` is the name of a series file (e.g. "vagrant") without leading
9path components. Do *not* check in the `hooks` folder, it is automatically
10generated by `auto/config` during Live Build runs.
11
12
13# Hook placement and ordering
14
15Scripts live in subfolders below the `hooks.d` folder. Currently the folders
16`chroot` and `base` exist. The folder with the name `extra` is reserved for
17private scripts, which are not included in the source of livecd-rootfs. The
18scripts are not numbered, instead the order of their execution depends on the
19order in which they are listed in a *series* file.
20
21Series files are placed in subfolders `hooks.d/base/series` or
22`hooks.d/extra/series`. Each series file contains a list of scripts to be
23executed. Empty lines and lines starting with a `#` are ignored.
24
25Series files in `extra/series` override files in `base/series` with the same
26name. For example, if a series file `base/series/cloudA` exists and a series
27file `extra/series/cloudA`, then the latter will be preferred.
28
29A series file in `extra/series` may also list scripts that are located in the
30`chroot` and `base` folders. In addition, series files can *depend* on other
31series files. For example, the series files for most custom images look similar
32to this:
33
34 depends disk-image
35 depends extra-settings
36 extra/cloudB.binary
37
38Where `disk-image` and `extra-settings` may list scripts and dependencies which
39are to be processed before the script `extra/cloudB.binary` is called.
40
41ACHTUNG: live build runs scripts with the suffix ".chroot" in a batch separate
42from scripts ending in ".binary". Even if you arrange them interleaved in your
43series files, the chroot scripts will be run before the binary scripts.
44
45# Image set selection for Live Build
46
47During a Live Build, enumerated symbolic links are generated based on the
48contents of one or more series files. The series files are selected according
49to the contents of the `IMAGE_TARGETS` environment variable. For example, in
50order to trigger the build of `squashfs` and `vagrant`, list them in the
51`IMAGE_TARGETS` variable as `squashfs,vagrant`. The separator can be a comma,
52a semi-colon or whitespace.
53
54The generation of the symbolic links is triggered from the `auto/config` script,
55from where the contents of the `IMAGE_TARGETS` environment variable are passed
56on to the `make-hooks` script.
57
58
59# Symlink generation
60
61Since Live Build itself does not know about series files, a traditional `hooks`
62folder is generated using the `make-hooks` script. The script takes as arguments
63the names of the series files to be processed.
64
65The script parses the series files and generates enumerated symbolic links for
66all entries. Per default, these are placed into a directory named `hooks` next
67to the `hooks.d` directory. This can be changed using the `--hooks-dir`
68parameter.
069
=== removed directory 'live-build/ubuntu-cpc/hooks'
=== added directory 'live-build/ubuntu-cpc/hooks.d'
=== added directory 'live-build/ubuntu-cpc/hooks.d/base'
=== renamed file 'live-build/ubuntu-cpc/hooks/031-0-create-root-dir.binary' => 'live-build/ubuntu-cpc/hooks.d/base/create-root-dir.binary'
=== renamed file 'live-build/ubuntu-cpc/hooks/034-disk-image-ppc64el.binary' => 'live-build/ubuntu-cpc/hooks.d/base/disk-image-ppc64el.binary'
=== renamed file 'live-build/ubuntu-cpc/hooks/033-disk-image-uefi.binary' => 'live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary'
=== renamed file 'live-build/ubuntu-cpc/hooks/032-disk-image.binary' => 'live-build/ubuntu-cpc/hooks.d/base/disk-image.binary'
--- live-build/ubuntu-cpc/hooks/032-disk-image.binary 2018-10-04 00:21:56 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/disk-image.binary 2018-12-10 08:29:28 +0000
@@ -12,6 +12,8 @@
12BOOT_MOUNTPOINT=12BOOT_MOUNTPOINT=
13ROOTPART_START=113ROOTPART_START=1
1414
15my_d=$(dirname $(readlink -f ${0}))
16
15case $ARCH:$SUBARCH in17case $ARCH:$SUBARCH in
16 ppc64el:*|powerpc:*)18 ppc64el:*|powerpc:*)
17 echo "POWER disk images are handled separately"19 echo "POWER disk images are handled separately"
@@ -97,7 +99,7 @@
97 # not the best place for this, but neither flash-kernel nor99 # not the best place for this, but neither flash-kernel nor
98 # u-boot have provisions for installing u-boot via maintainer100 # u-boot have provisions for installing u-boot via maintainer
99 # script101 # script
100 config/hooks/raspi2/mkknlimg --dtok \102 ${my_d}/raspi2/mkknlimg --dtok \
101 mountpoint/usr/lib/u-boot/rpi_2/u-boot.bin \103 mountpoint/usr/lib/u-boot/rpi_2/u-boot.bin \
102 mountpoint/boot/firmware/uboot.bin104 mountpoint/boot/firmware/uboot.bin
103 ;;105 ;;
104106
=== renamed directory 'live-build/ubuntu-cpc/hooks/ovf' => 'live-build/ubuntu-cpc/hooks.d/base/ovf'
=== renamed file 'live-build/ubuntu-cpc/hooks/040-qcow2-image.binary' => 'live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary'
--- live-build/ubuntu-cpc/hooks/040-qcow2-image.binary 2017-11-20 20:18:33 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary 2018-12-10 08:29:28 +0000
@@ -1,14 +1,5 @@
1#!/bin/bash -ex1#!/bin/bash -ex
22
3case $IMAGE_TARGETS in
4 ""|*qcow2*)
5 ;;
6 *)
7 echo "Skipping qcow2 image build"
8 exit 0
9 ;;
10esac
11
12case $ARCH:$SUBARCH in3case $ARCH:$SUBARCH in
13 # Not sure if any other cloud images use subarch for something that4 # Not sure if any other cloud images use subarch for something that
14 # should take qcow2 format, so only skipping this on raspi2 for now.5 # should take qcow2 format, so only skipping this on raspi2 for now.
156
=== renamed directory 'live-build/ubuntu-cpc/hooks/raspi2' => 'live-build/ubuntu-cpc/hooks.d/base/raspi2'
=== renamed file 'live-build/ubuntu-cpc/hooks/031-2-root-squashfs.binary' => 'live-build/ubuntu-cpc/hooks.d/base/root-squashfs.binary'
--- live-build/ubuntu-cpc/hooks/031-2-root-squashfs.binary 2018-06-07 23:24:29 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/root-squashfs.binary 2018-12-10 08:29:28 +0000
@@ -3,15 +3,6 @@
3#3#
4# Generate a squashfs root and manifest4# Generate a squashfs root and manifest
55
6case $IMAGE_TARGETS in
7 ""|*squashfs*)
8 ;;
9 *)
10 echo "Skipping squashfs build"
11 exit 0
12 ;;
13esac
14
15if [ -n "$SUBARCH" ]; then6if [ -n "$SUBARCH" ]; then
16 echo "Skipping rootfs build for subarch flavor build"7 echo "Skipping rootfs build for subarch flavor build"
17 exit 08 exit 0
189
=== renamed file 'live-build/ubuntu-cpc/hooks/031-1-root-xz.binary' => 'live-build/ubuntu-cpc/hooks.d/base/root-xz.binary'
=== added directory 'live-build/ubuntu-cpc/hooks.d/base/series'
=== added symlink 'live-build/ubuntu-cpc/hooks.d/base/series/all'
=== target is u'base'
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/base'
--- live-build/ubuntu-cpc/hooks.d/base/series/base 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/base 2018-12-10 08:29:28 +0000
@@ -0,0 +1,7 @@
1depends root-dir
2depends tarball
3depends squashfs
4depends disk-image
5depends qcow2
6depends vmdk
7depends vagrant
08
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/disk-image'
--- live-build/ubuntu-cpc/hooks.d/base/series/disk-image 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/disk-image 2018-12-10 08:29:28 +0000
@@ -0,0 +1,3 @@
1base/disk-image.binary
2base/disk-image-uefi.binary
3base/disk-image-ppc64el.binary
04
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/qcow2'
--- live-build/ubuntu-cpc/hooks.d/base/series/qcow2 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/qcow2 2018-12-10 08:29:28 +0000
@@ -0,0 +1,2 @@
1depends disk-image
2base/qcow2-image.binary
03
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/root-dir'
--- live-build/ubuntu-cpc/hooks.d/base/series/root-dir 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/root-dir 2018-12-10 08:29:28 +0000
@@ -0,0 +1,1 @@
1base/create-root-dir.binary
02
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/squashfs'
--- live-build/ubuntu-cpc/hooks.d/base/series/squashfs 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/squashfs 2018-12-10 08:29:28 +0000
@@ -0,0 +1,2 @@
1depends root-dir
2base/root-squashfs.binary
03
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/tarball'
--- live-build/ubuntu-cpc/hooks.d/base/series/tarball 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/tarball 2018-12-10 08:29:28 +0000
@@ -0,0 +1,2 @@
1depends root-dir
2base/root-xz.binary
03
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/vagrant'
--- live-build/ubuntu-cpc/hooks.d/base/series/vagrant 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/vagrant 2018-12-10 08:29:28 +0000
@@ -0,0 +1,2 @@
1depends disk-image
2base/vagrant.binary
03
=== added file 'live-build/ubuntu-cpc/hooks.d/base/series/vmdk'
--- live-build/ubuntu-cpc/hooks.d/base/series/vmdk 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/series/vmdk 2018-12-10 08:29:28 +0000
@@ -0,0 +1,3 @@
1depends disk-image
2base/vmdk-image.binary
3base/vmdk-ova-image.binary
04
=== renamed file 'live-build/ubuntu-cpc/hooks/042-vagrant.binary' => 'live-build/ubuntu-cpc/hooks.d/base/vagrant.binary'
--- live-build/ubuntu-cpc/hooks/042-vagrant.binary 2018-10-11 10:01:48 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/vagrant.binary 2018-12-10 08:29:28 +0000
@@ -24,15 +24,6 @@
24 ;;24 ;;
25esac25esac
2626
27case $IMAGE_TARGETS in
28 ""|*vagrant*)
29 ;;
30 *)
31 echo "Skipping Vagrant image build"
32 exit 0
33 ;;
34esac
35
36cur_d=${PWD}27cur_d=${PWD}
37my_d=$(dirname $(readlink -f ${0}))28my_d=$(dirname $(readlink -f ${0}))
3829
3930
=== renamed file 'live-build/ubuntu-cpc/hooks/040-vmdk-image.binary' => 'live-build/ubuntu-cpc/hooks.d/base/vmdk-image.binary'
--- live-build/ubuntu-cpc/hooks/040-vmdk-image.binary 2018-03-20 18:30:27 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/vmdk-image.binary 2018-12-10 08:29:28 +0000
@@ -18,15 +18,6 @@
18 exit 0;;18 exit 0;;
19esac19esac
2020
21case ${IMAGE_TARGETS:-} in
22 ""|*vmdk*)
23 ;;
24 *)
25 echo "Skipping VMDK image build"
26 exit 0
27 ;;
28esac
29
30. config/functions21. config/functions
3122
32if [ -e binary/boot/disk-uefi.ext4 ]; then23if [ -e binary/boot/disk-uefi.ext4 ]; then
3324
=== renamed file 'live-build/ubuntu-cpc/hooks/041-vmdk-ova-image.binary' => 'live-build/ubuntu-cpc/hooks.d/base/vmdk-ova-image.binary'
--- live-build/ubuntu-cpc/hooks/041-vmdk-ova-image.binary 2018-03-20 18:30:27 +0000
+++ live-build/ubuntu-cpc/hooks.d/base/vmdk-ova-image.binary 2018-12-10 08:29:28 +0000
@@ -32,15 +32,6 @@
32 exit 0;;32 exit 0;;
33esac33esac
3434
35case ${IMAGE_TARGETS:-} in
36 ""|*vmdk*)
37 ;;
38 *)
39 echo "Skipping OVA image build"
40 exit 0
41 ;;
42esac
43
44cur_d=${PWD}35cur_d=${PWD}
45my_d=$(dirname $(readlink -f ${0}))36my_d=$(dirname $(readlink -f ${0}))
4637
4738
=== added directory 'live-build/ubuntu-cpc/hooks.d/chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/001-divert-sync.chroot_early' => 'live-build/ubuntu-cpc/hooks.d/chroot/001-divert-sync.chroot_early'
=== renamed file 'live-build/ubuntu-cpc/hooks/010-write-etc-ec2-version.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/010-write-etc-ec2-version.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/020-pkg-configure.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/020-pkg-configure.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/025-create-groups.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/025-create-groups.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/052-ssh_authentication.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/052-ssh_authentication.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/060-ipv6.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/060-ipv6.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/061-open-iscsi.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/061-open-iscsi.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/099-cleanup.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/099-cleanup.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/999-cpc-fixes.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/999-cpc-fixes.chroot'
=== renamed file 'live-build/ubuntu-cpc/hooks/999-undivert-sync.chroot' => 'live-build/ubuntu-cpc/hooks.d/chroot/999-undivert-sync.chroot'
=== added file 'live-build/ubuntu-cpc/hooks.d/make-hooks'
--- live-build/ubuntu-cpc/hooks.d/make-hooks 1970-01-01 00:00:00 +0000
+++ live-build/ubuntu-cpc/hooks.d/make-hooks 2018-12-10 08:29:28 +0000
@@ -0,0 +1,237 @@
1#!/usr/bin/env python3
2#-*- encoding: utf-8 -*-
3"""
4This script parses a series file and its dependencies and generates a hooks
5folder containing symbolic links to the scripts that need to be invoked for
6a given image target set.
7
8For example, if you wish to build the image target sets "vmdk" and "vagrant",
9you would call this script as
10
11./make-hooks --hooks-dir hooks vmdk vagrant
12
13Scripts live in subfolders below the "hooks.d" folder. Currently the folders
14"chroot" and "base" exist. The folder with the name "extra" is reserved for
15private scripts, which are not included in the source of livecd-rootfs. The
16scripts are not numbered, instead the order of their execution depends on the
17order in which they are listed in a series file.
18
19Series files are placed into the subfolders "base/series" or "extra/series".
20Each series file contains a list of scripts to be executed. Empty lines and
21lines starting with a '#' are ignored. Series files in "extra/series" override
22files in "base/series" with the same name. For example, if a series file
23"base/series/cloudA" exists and a series file "extra/series/cloudA", then the
24latter will be preferred.
25
26A series file in "extra/series" may also list scripts that are located in the
27"chroot" and "base" folders. In addition, series files can depend on other
28series files. For example, the series files for most custom images look similar
29to this:
30
31 depends disk-image
32 depends extra-settings
33 extra/cloudB.binary
34
35Where "disk-image" and "extra-settings" may list scripts and dependencies which
36are to be processed before the script "extra/cloudB.binary" is called.
37
38ACHTUNG: live build runs scripts with the suffix ".chroot" in a batch separate
39from scripts ending in ".binary". Even if you arrange them interleaved in your
40series files, the chroot scripts will be run before the binary scripts.
41"""
42
43import argparse
44import os
45import re
46import shutil
47import sys
48import yaml
49
50SCRIPT_DIR = os.path.normpath(os.path.dirname(os.path.realpath(sys.argv[0])))
51HOOKS_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "hooks"))
52
53EXIT_OK = 0
54EXIT_ERR = 1
55
56class MakeHooksError(Exception):
57 pass
58
59class MakeHooks:
60 """This class provides series file parsing and symlink generator
61 functionality."""
62
63 def __init__(self, hooks_dir=None, quiet=False):
64 """The hooks_dir parameter can be used to specify the path to the
65 directory, into which the hook symlinks to the actual script files
66 should be placed.
67
68 If quiet is set to True, info messages during symlink creation will
69 be suppressed. Use this if your build is not private, but you would
70 like to hide which scripts are being run.
71 """
72 self._script_dir = SCRIPT_DIR
73 self._hooks_dir = hooks_dir or HOOKS_DIR
74 self._quiet = quiet
75 self._hooks_list = []
76 self._included = set()
77
78 def reset(self):
79 """Reset the internal state allowing instance to be reused for
80 another run."""
81 self._hooks_list.clear()
82 self._included.clear()
83
84 def print_usage(self):
85 print(
86 "CPC live build hook generator script \n"
87 " \n"
88 "Usage: ./make-hooks.sh [OPTIONS] <image_set> \n"
89 " \n"
90 "Options: \n"
91 " \n"
92 " --help, -h Show this message and exit. \n"
93 " --quiet, -q Only show warnings and error messages. \n"
94 " --hooks-dir, -d <dir> The directory where to write the symlinks.\n"
95 )
96
97 def find_series_file(self, image_set):
98 """Search for the series file requested in the image_set parameter.
99
100 The image_set parameter should be a string containing the name of an
101 image target set represented by a series file. First the "extra/series"
102 folder is searched followed by the "base/series" folder.
103
104 When a file with the given name is found, the search stops and the
105 full path to the file is returned.
106 """
107 for subdir in ["extra", "base"]:
108 series_file = os.path.join(self._script_dir, subdir, "series",
109 image_set)
110 if os.path.isfile(series_file):
111 return series_file
112 return None
113
114 def make_hooks(self, image_sets):
115 """Entry point for parsing series files and their dependencies and
116 for generating the symlinks in the hooks folder.
117
118 The image_sets parameter must be an iterable containing the names of
119 the series files representing the corresponding image target sets,
120 e.g. "vmdk" or "vagrant".
121 """
122 self.collect_chroot_hooks()
123 self.collect_binary_hooks(image_sets)
124 self.create_symlinks()
125
126 def collect_chroot_hooks(self):
127 """Chroot hooks are numbered and not explicitly mentioned in series
128 files. Collect them, sort them and add them to the internal list of
129 paths to hook sripts.
130 """
131 chroot_hooks_dir = os.path.join(self._script_dir, "chroot")
132
133 chroot_entries = os.listdir(chroot_hooks_dir)
134 chroot_entries.sort()
135
136 for entry in chroot_entries:
137 if not (entry.endswith(".chroot_early") or
138 entry.endswith(".chroot")):
139 continue
140 self._hooks_list.append(os.path.join("chroot", entry))
141
142 def collect_binary_hooks(self, image_sets):
143 """Search the series files for the given image_sets and parse them
144 and their dependencies to generate a list of hook scripts to be run
145 during image build.
146
147 The image_sets parameter must be an iterable containing the names of
148 the series files representing the corresponding image target sets,
149 e.g. "vmdk" or "vagrant".
150
151 Populates the internal list of paths to hook scripts in the order in
152 which the scripts are to be run.
153 """
154 for image_set in image_sets:
155 series_file = self.find_series_file(image_set)
156
157 if not series_file:
158 raise MakeHooksError(
159 "Series file for image set '%s' not found." % image_set)
160
161 with open(series_file, "r", encoding="utf-8") as fp:
162 for line in fp:
163 line = line.strip()
164 if not line:
165 continue
166 m = re.match(r"^\s*depends\s+(\S+.*)$", line)
167 if m:
168 include_set = m.group(1)
169 if include_set in self._included:
170 continue
171 self._included.add(include_set)
172 self.collect_binary_hooks([include_set,])
173 continue
174 if not line in self._hooks_list:
175 self._hooks_list.append(line)
176
177 def create_symlinks(self):
178 """Once the internal list of hooks scripts has been populated by a
179 call to collect_?_hooks, this method is used to populate the hooks
180 folder with enumerated symbolic links to the hooks scripts. If the
181 folder does not exist, it will be created. If it exists, it must be
182 empty or a MakeHooksError will be thrown.
183 """
184 if os.path.isdir(self._hooks_dir) and os.listdir(self._hooks_dir):
185 # Only print a warning, because directory might have been created
186 # by auto/config voodoo.
187 sys.stderr.write("WARNING: Hooks directory exists and is not empty.\n")
188 os.makedirs(self._hooks_dir, exist_ok=True)
189
190 for counter, hook in enumerate(self._hooks_list, start=1):
191 hook_basename = os.path.basename(hook)
192
193 m = re.match(r"^\d+-(?:\d+-)?(?P<basename>.*)$", hook_basename)
194 if m:
195 hook_basename = m.group("basename")
196
197 linkname = ("%03d-" % counter) + hook_basename
198 linksrc = os.path.join(self._hooks_dir, linkname)
199 linkdest = os.path.relpath(os.path.join(self._script_dir, hook),
200 self._hooks_dir)
201
202 if not self._quiet:
203 print("[HOOK] %s => %s" % (linkname, hook))
204 os.symlink(linkdest, linksrc)
205
206 def cli(self, args):
207 """Command line interface to the hooks generator."""
208 parser = argparse.ArgumentParser()
209
210 parser.add_argument("-q", "--quiet", dest="quiet", type=bool,
211 help="Only show warnings and error messages.")
212 parser.add_argument("-d", "--hooks-dir", dest="hooks_dir", type=str,
213 help="The directory where to create the symlinks.")
214 parser.add_argument("image_target", nargs="+", type=str,
215 help="")
216
217 self.reset()
218 options = parser.parse_args(args)
219
220 # Copy options to object attributes.
221 for key, value in vars(options).items():
222 if value and hasattr(self, "_" + key):
223 setattr(self, "_" + key, value)
224
225 # Take remaining command line arguments, sanitize and turn into list.
226 image_sets = re.sub(r";|,", " ", " ".join(options.image_target))\
227 .split()
228
229 self.make_hooks(image_sets)
230
231
232if __name__ == "__main__":
233 try:
234 MakeHooks().cli(sys.argv[1:])
235 except MakeHooksError as e:
236 sys.stderr.write("%s: %s\n" % (os.path.basename(sys.argv[0]), str(e)))
237 sys.exit(EXIT_ERR)
0238
=== removed file 'live-build/ubuntu-cpc/hooks/999-extras.binary'
--- live-build/ubuntu-cpc/hooks/999-extras.binary 2017-04-13 17:54:14 +0000
+++ live-build/ubuntu-cpc/hooks/999-extras.binary 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
1#!/bin/bash
2# Execute extra binary hooks.
3
4my_dir=$(dirname $(readlink -f ${0}))
5extra_d=${my_dir}/extra
6
7if [ ! -d ${my_dir}/extra ]; then
8 exit 0
9fi
10
11export IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
12export CLOUD_IMG_STR="$IMAGE_STR"
13export FS_LABEL="cloudimg-rootfs"
14
15# Cleaner execution
16/bin/run-parts --exit-on-error --regex ".*\.binary" "${extra_d}"

Subscribers

People subscribed via source and target branches