Skip to content

Commit

Permalink
controller: Add post-image YAML hook
Browse files Browse the repository at this point in the history
Fixes: clearlinux#531

Add new hook to be called after image generation is completed.

Update base image test to use post-image hook

This is useful for image manipulation such as compression, format
modification, etc.
  • Loading branch information
mdhorn committed Feb 27, 2020
1 parent f73d0d1 commit 7e27777
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ check-image: build-tui
echo "Test Failed: Missing ${BASEIMGNAME}.iso"; \
/bin/false; \
fi
@if [ ! -f "$(BASEBUILD_DIR)/${BASEIMGNAME}.img" ] ; then \
echo "Test Failed: Missing ${BASEIMGNAME}.img"; \
@if [ ! -f "$(BASEBUILD_DIR)/${BASEIMGNAME}.img.xz" ] ; then \
echo "Test Failed: Missing ${BASEIMGNAME}.img.xz"; \
/bin/false; \
fi
@cd ${top_srcdir}
Expand Down
9 changes: 9 additions & 0 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func Install(rootDir string, model *model.SystemInstall, options args.Args) erro
}
}

// Add the image file to the hooks variables
vars["imageFile"] = alias.File

file, err = storage.SetupLoopDevice(alias.File)
if err != nil {
return errors.Wrap(err)
Expand Down Expand Up @@ -179,6 +182,12 @@ func Install(rootDir string, model *model.SystemInstall, options args.Args) erro
for _, file := range detachMe {
storage.DetachLoopDevice(file)
}

// Now that image is unmounted, run post-image hooks
if err = applyHooks("post-image", vars, model.PostImage); err != nil {
log.Error("Error during post-image hook: %q", err)
}

// The request to keep image may have changed during execution
// such as dynamically decided to not make an ISO or failing to
// make an ISO
Expand Down
3 changes: 3 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ msgstr "pre-install"
msgid "post-install"
msgstr "post-install"

msgid "post-image"
msgstr "post-image"

#, c-format
msgid "Setting Language locale to %s"
msgstr "Setting Language locale to %s"
Expand Down
3 changes: 3 additions & 0 deletions locale/es_MX/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ msgstr "preinstalación"
msgid "post-install"
msgstr "posinstalación"

msgid "post-image"
msgstr "pos-imagen"

#, c-format
msgid "Setting Language locale to %s"
msgstr "Configurando la localidad de idioma a %s"
Expand Down
5 changes: 4 additions & 1 deletion locale/zh_CN/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,14 @@ msgid "admin"
msgstr "管理员"

msgid "pre-install"
msgstr "预先安装"
msgstr "安装前"

msgid "post-install"
msgstr "安装后"

msgid "post-image"
msgstr "创建映像后"

#, c-format
msgid "Setting Language locale to %s"
msgstr "将语言区域设置为 %s"
Expand Down
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type SystemInstall struct {
TelemetryPolicy string `yaml:"telemetryPolicy,omitempty,flow"`
PreInstall []*InstallHook `yaml:"pre-install,omitempty,flow"`
PostInstall []*InstallHook `yaml:"post-install,omitempty,flow"`
PostImage []*InstallHook `yaml:"post-image,omitempty,flow"`
SwupdFormat string `yaml:"swupdFormat,omitempty,flow"`
Version uint `yaml:"version,omitempty,flow"`
StorageAlias []*StorageAlias `yaml:"block-devices,omitempty,flow"`
Expand Down
11 changes: 8 additions & 3 deletions scripts/InstallerYAMLSyntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This document describes the syntax for constructing a clr-installer configuration file.

## Environment Variables
Environment variables can be defined which will be used when installation commands are executed. These are most commonly used for `pre-install` and `post-install` hooks.
Environment variables can be defined which will be used when installation commands are executed. These are most commonly used for `pre-install`, `post-install`, or `post-image` hooks.
```yaml
env:
<variable>: <value>
Expand Down Expand Up @@ -159,7 +159,7 @@ Supports adding or removing kernel arguments. There is NO support for directly d
Item | Description | Required?
------------ | ------------- | -------------
`add:` | A YAML list of strings with additional kernel parameters. These are always appending to the pre-defined kernel parameters.| No
`remove:` | A YAML list of strings to attempt to remove from the pre-defined kernel parameters. Only exact matches are removed. | No
`remove:` | A YAML list of strings to attempt to remove from the pre-defined kernel parameters. Only exact matches are removed. | No


```yaml
Expand All @@ -170,7 +170,7 @@ kernel-arguments: {
```

## Installation Hooks
Clear Linux OS Installer supports both `pre-install` and `post-install` hooks which are executed either before (pre) the start of the installation, or after (post) the installation steps are completed.
Clear Linux OS Installer supports `pre-install`, `post-install`, and `post-image` hooks which are executed either before (pre) the start of the installation, after (post) the installation steps are completed, or after (post) the image file is created.

Item | Description | Required?
------------ | ------------- | -------------
Expand All @@ -185,10 +185,15 @@ Environment Variable | Description
------------ | -------------
`yamlDir` | The directory where the configuration YAML file resides. This is useful as most installation hooks are stored in (or relative to) the same directory as the YAML file.
`chrootDir` | The directory where the installation is being placed (chrooted). This should be passed as an argument to the installation hook to ensure modifications are made to the correct location of the install.
`imageFile` | The file name of the image file generated by the installer. Only useful for `post-image` hooks.

```yaml
post-install: [
{cmd: "${yamlDir}/installer-post.sh ${chrootDir}"}
]

post-image: [
{cmd: "xz -q -T0 --stdout ${imageFile} > ${imageFile}.xz"}
]
```

6 changes: 5 additions & 1 deletion tests/baseline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ postArchive: true
postReboot: false
telemetry: false
iso: true
keepImage: true
keepImage: false

keyboard: us
language: en_US.UTF-8
Expand All @@ -51,4 +51,8 @@ post-install: [
{chroot:true, cmd: "/bin/ls /etc"},
]

post-image: [
{cmd: "xz -q -T0 --stdout ${imageFile} > ${imageFile}.xz"},
]

version: 0

0 comments on commit 7e27777

Please sign in to comment.