Commit Graph

299 Commits

Author SHA1 Message Date
Christopher Obbard
21fdbc283a docker: recipes-test: move tests to project root directory
The tests are first-class citizens; they should be present in the
directory as such.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 22:11:52 +02:00
Christopher Obbard
8b60bab5d2 docker: unit-tests: run all of the unit-tests
Currently only the unit-tests under the actions directory are ran. This
patch runs all of the available unit tests in the project.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 22:11:52 +02:00
Christopher Obbard
ba83a9631f docker: dockerfile: install unzip for unit-test
The unit tests require the unzip package to be installed.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 22:11:52 +02:00
Christopher Obbard
5c0e4e728e actions/image-partition: remove useless linebreak
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 21:30:10 +02:00
Christopher Obbard
38f490c9b4 actions/image-partition: convert local variable to camelCase
Local variables should be stylized using camelCase.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 21:30:10 +02:00
Christopher Obbard
669ebed1d5 actions/image-partition: define ImagePath variable
The variable hasn't been defined yet so ends up producing
a build failure:

    actions/image_partition_action.go:371:2: undefined: ImagePath
    actions/image_partition_action.go:372:26: undefined: ImagePath
    actions/image_partition_action.go:384:34: undefined: ImagePath

Fix the syntax used to initialise this variable.

Fixes: a7afc01562 ("actions/image-partition: Consistently use artifactdir")

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-07 21:30:10 +02:00
Punit Agrawal
a7afc01562 actions/image-partition: Consistently use artifactdir
The "image-partition" action uses artifactdir in the
PostMachineCleanup() step but not during the PreMachine() and
PreNoMachine() steps. Also, other debos actions such as pack, unpack
are relative to the specified "artifactdir" when invoking debos.

Fix this inconsistency by bringing image-partition action to the
fold. Also update the documentation to clarify this.

Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
2021-07-06 22:37:11 +02:00
Sjoerd Simons
0dec131ed3 docker: Add some useful deployment tools
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-06 21:59:21 +02:00
Nguyen Thi Huong
fe62ce195a image-partition: add support for xfs
This patch adds support for XFS, including the ability
to specify the UUID through the fsuuid property of the
image-partition action.

Signed-off-by: Nguyen Thi Huong <huong4.nguyenthi@toshiba.co.jp>
Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
2021-07-06 21:54:17 +02:00
Nguyen Thi Huong
a5f59ab026 image-partition: use fsuuid to set the filesystem UUID
This patch adds functionality that allows you to specify
the UUID of your file system instead of getting a random one.
Some use cases include reproducible builds and software updates.

Currently, only btrfs, xfs, ext2, ext3, and ext4 are supported.

The uuid library is used for verifying the input value of
the FSUUID property (specified by the user on the
image-partition action). The verification is based on RFC 4122
and DCE 1.1: Authentication and Security Services. Check
https://github.com/google/uuid for more details.

Signed-off-by: Nguyen Thi Huong <huong4.nguyenthi@toshiba.co.jp>
Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
2021-07-06 21:54:17 +02:00
Christopher Obbard
28394e92a0 actions: raw: Actually make offset optional
The documentation suggests that offset should be optional; in practice
offset isn't optional and the action will return an error out if unset:

    Action `` failed at stage Run, error: Couldn't parse offset strconv.ParseInt: parsing "": invalid syntax

So set the offset by default to 0 then only attempt to parse the parameter
from the YAML if it is explicitly set.

Fixes: b792b4722a ("Add a raw action")

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-07-06 19:59:14 +02:00
Christopher Obbard
306d2ea194 docker: Manually register binfmts
Debian's qemu-user-static package no longer registers binfmts on postinst
when running inside a virtualmachine; dockerhub builds are now built inside
a vm so the binfmts are not generated inside the docker container.

Fixes: 91af617bea ("docker: Install qemu-user-static 6.0 to fix segfault")

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-05-28 16:24:37 +02:00
Christopher Obbard
91af617bea docker: Install qemu-user-static 6.0 to fix segfault
There are issues with qemu-user-static 5.2 crashing when attempting
to allocate guest memory when compiled as a proper statically-linked
binary.

From testing, qemu 6.0 fixes the bug but it's not yet clear which
patch fixes the bug. So until the correct patch is backported to
bullseye, let's install qemu from experimental to pickup the bugfix.

See: #245
See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988174

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-05-26 08:33:10 +02:00
Christopher Obbard
da53d4b001 docker: Add git package
Add the git package to the docker image.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-04-29 11:42:55 +02:00
Christopher Obbard
f017e9348e actions: run: Expose paths to postprocess commands
Expose the environment variables $ARTIFACTDIR and $RECIPEDIR
to the postprocess commands to allow the postprocess commands
to be more flexible.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-04-29 11:42:38 +02:00
Christopher Obbard
59c38c76ed docker: Add zip package
Add the zip package to allow the cration of compressed zip archives.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-04-28 18:51:36 +02:00
mtt2hi
c8f6962c33 systemd-nspawn shall be called with option "--register=no" to prevent error after debootstrap
After debootstrap the call of "debos" fails with message "Failed to register machine: Unit machine-root.scope already exists".
With the option "--register=no" this works fine. This change is derived from https://gitlab.collabora.com/smcv/flatdeb/-/merge_requests/6

Signed-off-by: mtt2hi <thomas.mittelstaedt@de.bosch.com>
2021-04-06 13:25:33 +02:00
Christopher Obbard
0427306a09 Docker tests should run without fakemachine
Since we have the support for the new user-mode-linux backend in the
docker container, Debos defaults to attempting to use that.
Unfortunately that isn't possible to run inside the Docker Hub where the
test suite runs, so let's explicitly disable the fakemachine library
when running the Docker Hub test suite.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-03-23 10:54:58 +01:00
Christopher Obbard
88464339d6 dockerfile: Add fakemachine uml backend support
The fakemachine uml backend uses user-mode-linux and libslirp-helper
packages available from bullseye, let's include those inside the container.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-03-23 10:54:58 +01:00
Christopher Obbard
6fbb5752d7 docker: Upgrade from buster to bullseye
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-03-23 10:54:58 +01:00
Christopher Obbard
bd53aff709 docker: Add equivs package
The equivs package is used to create dummy Debian packages which can
be useful in development to satisfy dependencies without installing the
real package. Note that this package is not the recommended way of
dealing with broken dependencies: a bug report should be filed instead.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-01-25 14:10:39 +01:00
Christopher Obbard
0303282b25 docker: Fix formatting
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2021-01-25 14:10:39 +01:00
Corentin Noël
7ceed7ebc3 actions/pack_action: Add several compression options
Match the same compression options as unpack and allow to have an uncompressed
tar when removing the `compression` parameter.

Signed-off-by: Corentin Noël <corentin.noel@collabora.com>
2020-12-11 12:22:50 +01:00
Christopher Obbard
e9390903ae doc: man: Refresh man page
The readme got updated, so refresh the man page

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-12-03 11:28:13 +01:00
Christopher Obbard
ce6d00831a readme: add information about fakemachine backend choice
Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-12-03 11:28:13 +01:00
Christopher Obbard
ab58845a55 readme: refresh readme with new command-line arguments
The readme has got a bit out-of-sync with the help command; update the
readme for the new options and descriptions.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-12-03 11:28:13 +01:00
Christopher Obbard
ffb75b94fd cmd/debos: Add backend argument to choose fakemachine backend
Fakemachine now allows the virtualisation backend to be chosen when
creating the machine, so allow the backend to be chosen by the user.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-12-03 11:28:13 +01:00
Trung Do
458b7b39e4 actions/apt_action: Add property 'update'
This property is a boolean value indicating if `apt update` will be run
before install package. Default value is 'true'.

Signed-off-by: Trung Do <trung1.dothanh@toshiba.co.jp>
Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
2020-12-02 15:02:09 +01:00
Christopher Obbard
fa6d9d5f23 cmd/debos: Don't print command-line parsing error twice
The command-line argument parsing library already prints any parsing
errors; there's no need to print the error again ourselves.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-12-02 14:31:06 +01:00
Andrej Shadura
3998634802 Don’t indent the NAME section, this results in incorrectly formatted manpage
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
2020-12-02 14:26:05 +01:00
Andrej Shadura
42711f357b Synopsis, not sypnosis
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
2020-12-02 14:26:05 +01:00
Denis Pynkin
d2ab9d3b08 action/debootstrap: allow to use files outside of RecipeDir
Added stages "Verify" and "PreMachine" allowing to use secret files
outside of recipe directory tree (both absolute and relative paths
are supported).
Verification stage ensures that configuration files from options
are existing on file system.

This is needed for cases if secret files are not the part of Debos
recipe directory and useful for CI.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2020-09-09 13:30:41 +02:00
Denis Pynkin
43a49b2b1d action/debootstrap: add certificate and private-key
Allow to use certificate and private key for client authentication.
Those action parameters falls thru `debootstrap` for `wget` allowing
to authenticate client on server side.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2020-09-08 13:52:51 +02:00
Christopher Obbard
26945d8833 docker: dockerfile: install testify from source
Testify is currently not built unless the manual tests are ran at which
point testify compiliation fails due to requiring a newer version of
golang than in buster. Unfortunately the main branch is no longer
compatible, so install from source to get the unit tests running again.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-08-14 15:18:47 +02:00
Sjoerd Simons
1fde503ac7 docker: Add f2fs-tools for mkfs.f2fs
Signed-off-by: Sjoerd Simons <sjoerd@collabora.com>
2020-08-14 14:27:02 +02:00
Arnaud Ferraris
0277134b77 actions: image_partition: add F2FS support
F2FS requires a few tweaks to be usable within debos:
  * its command-line option for setting the fs label is different from
    other mkfs utils
  * parted doesn't recognize "f2fs" as a valid filesystem, therefore it
    shouldn't appear on the command line

With these simple changes, it becomes possible to use F2FS partitions
with debos.

Signed-off-by: Arnaud Ferraris <arnaud.ferraris@gmail.com>
2020-08-14 14:25:36 +02:00
Punit Agrawal
5b8020bcff actions/run: Improve run action verification
For the run action, debos does not complain even if both "script" and
"command" are empty which can occur due to a typo or accidentally
missing the tag.

As the documentation already mentions that one of "script" or
"command" is mandatory for the run action, let's detect the invalid
scenario and complain to the user instead of silently continuing.

Signed-off-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>
2020-08-14 14:17:50 +02:00
Christopher Obbard
b86d0d4816 actions/image-partition: add support for setting partition type
Debos currently sets the partition type to filesystem type and
does not allow the partition type to be set from the recipe.

In some situations setting the partition type is required, so add the
property `PartType` to the Partition and set the partition type to the value
of that property. If the `PartType` property is unset, the original partition
type is retained thus not breaking backwards compatibility.

For msdos, the partition type should be hexadecimal and 2-characters long.
For gpt, the partition GUID should be in GUID format and 36-characters long.
Some examples and further reading is included in the documentation.

Resolves: #98

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-08-14 14:17:25 +02:00
Christopher Obbard
77dd08ceb6 actions/image-partition: add support for setting GPT partition label
Debos currently sets the GPT partition label to the `Name` property of the
Partition and does not allow the GPT partition label to be set from the recipe.

In some situations setting the GPT partition label is required, so add the
property `PartLabel` to the Partition and set the GPT partition label to the value
of that property. By default, the `PartLabel` property is set to the `Name`
property of the Partition to not break backwards compatibility.

Resolves: #202

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-08-14 14:17:25 +02:00
Christopher Obbard
ee15bc448d actions/image_partition: do not allow duplicate partitions or mountpoints
A common user complaint is the result of mounting a filesystem on top of another
can be confusing. So do not allow duplicate mountpoints.

Also better not allow multiple partitions with the same name.

Resolves: #176
Resolves: #178

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-28 17:13:56 +02:00
Christopher Obbard
77fd246663 actions/image_partition: trigger udev rules after image-partition completion
The image is locked while partitioning and mounting, which has a side effect of
not running udev rules so there are no entries for the freshly partitioned disk
under the children of `/dev/disk`.

Currently the workaround is to call partprobe in the recipe, which creates the
entries but we should do this as part of the image-partition action so that no
magic is needed in the recipe.

Fixes: f91e2b2c27 ("Fix partition races while partitioning")
Resolves: #154

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-28 16:52:30 +02:00
Christopher Obbard
0875e30f4b docs: action: filesystem-deploy: clarify what happens after deploy
All the filesystem-deploy action does is copy the contents from scratch into the
mounted image, then all actions after that refer to the image rather than the
scratch space. Be clearer.

Resolves: #175

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-28 15:30:28 +02:00
Christopher Obbard
30d90869da action: run: expose context.ImageMntDir for recipes which do not call filesystem-deploy
When a command is ran using `action: run` some environment variables are exposed to the script.

`$ROOTDIR` is set to `context.Rootdir=/scratch/root` which is a temporary
directory meant to hold the rootfs until `action: filesystem-deploy` is ran, which
copies from `context.Rootdir` to `context.ImageMntDir`. After the filesystem is
deployed, `context.Rootdir` is set to `context.ImageMntDir`.

The mount points defined under action: image-partition are mounted under
`context.ImageMntDir`, so if the filesystem is never deployed, there is no
(simple) way for the script to know where the images are mounted to.

So, expose `context.ImageMntDir` to the script as `$IMAGEMNTDIR` so the recipe
can know where the image is mounted.

Resolves: #204

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-28 15:29:56 +02:00
Christopher Obbard
bdfcde55c1 actions/image_partition: do not return error if removing buildtime mountpoint with a read-only parent
Returning an error in this function causes the rest of the cleanup operation to
not be executed; so in this case downgrading an error to remove the mountpoint
from the read-only filesystem to a warning is wise.

Resolves: #206

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-27 14:22:04 +02:00
Christopher Obbard
a1a5df5adb actions/image_partition: sort mountpoints by position in filesystem hierarchy before mounting
Currently the `mountpoints` are mounted in the fakemachine in the order defined
by the recipe. This is confusing for users so sort the mountpoints in a sane
order before they are mounted.

This patch sorts the mountpoints so that (if defined) the root partition would
always be mounted first, then in ascending order of how many slashes ('/')
are in the mountpoint so that the parents are mounted first.

The current verbatim syntax for mountpoints where the recursive parent filesystems
are mounted before the children could be as follows:
```
  - action: image-partition
    imagename: mountpoints-order.img
    imagesize: 5MB
    partitiontype: gpt
    partitions:
      - name: root
        fs: ext4
        start: 0M
        end: 1M
      - name: opt
        fs: ext4
        start: 2M
        end: 3M
      - name: opt_test
        fs: ext4
        start: 4M
        end: 5M
    mountpoints:
      - mountpoint: /
        partition: rootfs
      - mountpoint: /opt
        partition: opt
      - mountpoint: /opt/test
        partition: opt_test
```

After mounting the fakemachine shows:
```
$ mount
...
/dev/vda1 on /scratch/mnt type ext4 (rw,relatime)
/dev/vda2 on /scratch/mnt/opt type ext4 (rw,relatime)
/dev/vda3 on /scratch/mnt/opt/test type ext4 (rw,relatime)

$ df -h
...
/dev/vda1       940K   22K  851K   3% /scratch/mnt
/dev/vda2       955K   22K  866K   3% /scratch/mnt/opt
/dev/vda3       940K   21K  852K   3% /scratch/mnt/opt/test
```
which is the correct order.

If the user defines the recipe to mount these out of order, for example:
```
- mountpoint: /opt
  partition: opt
- mountpoint: /opt/test
  partition: opt_test
- mountpoint: /
  partition: root
```
Without this patch, no error is shown but the system has mounted the partitions
out of order (which is confusing for the user):
```
$ mount
...
/dev/vda2 on /scratch/mnt/opt type ext4 (rw,relatime)
/dev/vda3 on /scratch/mnt/opt/test type ext4 (rw,relatime)
/dev/vda1 on /scratch/mnt type ext4 (rw,relatime)

$ df -h
...
/dev/vda1       940K   21K  852K   3% /scratch/mnt
```

With this patch, the recipe would show:
```
$ mount
...
/dev/vda1 on /scratch/mnt type ext4 (rw,relatime)
/dev/vda2 on /scratch/mnt/opt type ext4 (rw,relatime)
/dev/vda3 on /scratch/mnt/opt/test type ext4 (rw,relatime)

$ df -h
...
/dev/vda1       940K   22K  851K   3% /scratch/mnt
/dev/vda2       955K   22K  866K   3% /scratch/mnt/opt
/dev/vda3       940K   21K  852K   3% /scratch/mnt/opt/test
```

Resolves: #177

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
2020-05-27 14:14:56 +02:00
Denis Pynkin
40e79c033b commands: do not touch /etc/localtime in chrooted calls
Added option `--timezone=off` for `systemd-nspawn` to leave the
file untouched during the chrooted calls.

Fixes: #180

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2020-05-27 14:01:20 +02:00
Mylène Josserand
948e1e4564 docker: Add u-boot-tools package
Add the u-boot-tools package to be able to use binaries such as
mkimage in debos' recipes.

Signed-off-by: Mylène Josserand <mylene.josserand@collabora.com>
2020-04-28 12:23:16 +02:00
Denis Pynkin
292995b521 Merge pull request #192 from d4s/wip/d4s/resolv
commands: check if the chrooted resolv.conf is a symlink
2019-12-23 14:06:47 +03:00
Denis Pynkin
a9b11af527 commands: check if the chrooted resolv.conf is a symlink
If the resolv.conf in chrooted environment changed to symlink and point to
non-existing file, the os.Stat() fail the check of file existence.
Use os.Lstat() call instead and add additional checks during the resolv.conf
restore phase.

Fixes: #190

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2019-12-23 13:39:27 +03:00
Denis Pynkin
263be37f33 commands: protect resolv.conf in chrooted calls
Protect by default the 'resolv.conf' file from changing while calling
commands and scripts in chrooted environment.

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
2019-12-17 09:57:39 +00:00