Skip to content

Overlay Action

The overlay action allows to overlay a file structure into the root file system at the end of the installation. The corresponding command that takes care of this is appended to <profile>.postinst. Corresponding archives that contain the overlays are copied to the extra folder and are registered in <profile>.extra. By default the overlay will be copied by root, but it's also possible to have a user do this.

Usage

Click on the to learn more about the action's options.

Overlay Action
{% set username=username or "user" -%}

actions:
  - action: overlay
    description: Bash settings for {{username}} #(1)!
    user: {{username}} #(2)!
    source: overlays/bash-settings #(3)!
    destination: /home/{{username}}/ #(4)!
  1. [Optional] Description, for documentation purposes
  2. [Optional] User that performs the overlay actions. If omitted root is used.
  3. [Required] Relative link to overlay file structure command keyword.
  4. [Optional] Destination where the overlay file structure is copied to. If destination and user are omitted, / is used. If destination is omitted but user is provided, /home/{user} is used.

Implementation

OverlayAction

Bases: Action

Overlay action

Source code in simple_cdd_yaml/actions.py
class OverlayAction(Action):
    """ Overlay action """
    def __init__(self, args):
        super().__init__(args)
        self.overlay_template = jinja2.Template(OVERLAY_TEMPLATE_STR)

    def source(self, props):
        source = props['source']
        if source.startswith('/'):
            return pl.PurePath(source)
        return pl.PurePath(self.input_dir / source)

    def overlay_name(self, props):
        overlay_name = props['source'].replace('/', '.')
        if user := props.get('user'):
            return f'{overlay_name}.{user}'
        return overlay_name

    def tar_filter(self, props):
        if user := props.get('user'):
            return OwnerTarFilter(user=user).tar_filter
        return None

    def destination(self, props):
        """ If destination is provided, this overrules the user setting """
        if dest := props.get('destination'):
            return dest
        if user := props.get('user'):
            if user == 'root':
                return '/root/'
            return f'/home/{user}/'
        return '/'

    def compress_overlay(self, props, output_dir):
        """ Compress overlay into tarball """
        name = self.overlay_name(props)
        filename = f'{self.profile}.{name}.tar.gz'
        src = self.source(props)
        tfilter = self.tar_filter(props)
        with tarfile.open(output_dir / filename, "w:gz") as tar:
            tar.add(src, arcname='', filter=tfilter)
        dest = self.destination(props)
        return filename, dest

    def perform_action(self, props):
        output_dir = self.output_dir / 'extra'
        filename, destination = self.compress_overlay(props, output_dir)
        self._write_action(f'extra/{filename}\n', extension='extra',
                           no_duplicate=True)
        extract_commands = self.overlay_template.render(
            description=props.get('description', 'Overlay'),
            overlay=filename,
            destination=destination,
        )
        self._write_action(extract_commands, extension='postinst')

    def perform_debos_action(self, props):
        output_dir = self.debos_output_dir / 'overlays'
        filename, destination = self.compress_overlay(props, output_dir)
        debos_action = dict(COMMAND_TEMPLATE_DICT,
            description=props.get('description', 'Overlay'),
            command=f'tar -xf $ARTIFACTDIR/overlays/{filename} -C $ROOTDIR{destination}'
        )
        self.append_result(debos_action)