Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to run pre/post scripts #1673

Merged
merged 25 commits into from
Oct 18, 2024
Merged

feat: add support to run pre/post scripts #1673

merged 25 commits into from
Oct 18, 2024

Conversation

imobachgs
Copy link
Contributor

@imobachgs imobachgs commented Oct 16, 2024

This is the first implementation of pre/post-installation scripts. They are not as capable as their AutoYaST counterparts, but the idea is to evolve them in the future.

Specifying a script

Warning

JSON does not support multiline values (a.k.a. blocks) but Jsonnet does it. Perhaps we should consider using Jsonnet in the agama config edit command.

{
  scripts: {
    pre: [
      {
         name: "say-hi",
         body: |||
           #!/bin/bash
           echo "before starting the installation"
         |||
      }
    ]
  }
}

Note

What about having a plain list where each script has a type (or group) like pre, post, etc.?

When scripts get executed

  • Pre-scripts: when loading a profile. We plan to do some improvements to support the single-product case properly.
  • Post-scripts: after the installation.

Implementation details

The scripting support is written in Rust and does not use the YaST scripts code anymore. We will rewrite the Manager in Rust (at least the Agama-specific part) in the future, and the scripting support will be part of that.

Future

Agama scripts will gain additional features soon:

  • Running in a chroot.
  • Better error handling if the shebang line is not present.
  • Running after the first boot.

Pending tasks

  • Extend the JSON schema
  • Copy the resulting files to the installed system
  • Add some logging
  • Clean-up the old scripts when reloading a profile

@coveralls
Copy link

coveralls commented Oct 16, 2024

Pull Request Test Coverage Report for Build 11368553812

Details

  • 47 of 126 (37.3%) changed or added relevant lines in 7 files are covered.
  • 4 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.2%) to 70.862%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rust/agama-server/src/web.rs 0 1 0.0%
rust/agama-lib/src/store.rs 0 4 0.0%
rust/agama-lib/src/scripts/model.rs 32 37 86.49%
rust/agama-lib/src/scripts/client.rs 0 10 0.0%
rust/agama-server/src/scripts/web.rs 0 27 0.0%
rust/agama-lib/src/scripts/store.rs 0 32 0.0%
Files with Coverage Reduction New Missed Lines %
rust/agama-lib/src/store.rs 1 0.0%
rust/agama-server/src/web.rs 1 0.0%
service/lib/agama/storage/finisher.rb 2 98.33%
Totals Coverage Status
Change from base Build 11364775644: -0.2%
Covered Lines: 16126
Relevant Lines: 22757

💛 - Coveralls

@imobachgs imobachgs marked this pull request as ready for review October 16, 2024 15:12
Copy link
Contributor

@lslezak lslezak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments, looks good to me.

require "fileutils"
logs_dir = File.join(Yast::Installation.destdir, "var", "log", "agama")
FileUtils.mkdir_p(logs_dir)
FileUtils.cp_r(SCRIPTS_DIR, logs_dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document that the user scripts are copied to the logs in the installed system. The user scripts might contain sensitive data (passwords, tokens, keys, certificates,...) and the users should be aware of this when attaching the logs to bugzilla or sending via email.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move them to a different place (in AutoYaST they are copied to /var/adm/autoinstall.

"properties": {
"pre": {
"title": "Pre-installation scripts",
"description": "User-defined scripts to run before the installation starts",
Copy link
Contributor

@lslezak lslezak Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, when exactly? Nothing done yet?

I mean later we might add a "post-partitioning" script so it should be clean whether at this point something is already done by Agama or the system has not been touched yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the post-partitioning. I can improve the description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were expected to be used to modify the profile, but I am not sure whether we should implement that behavior. Or perhaps to activate some hardware.

service/test/agama/storage/manager_test.rb Outdated Show resolved Hide resolved
.await?;
}

self.client.run_scripts(ScriptsGroup::Pre).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I am not sure I like it. Separation of load and store is understandable, but why it runs pre script when store? This looks kind of unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's a good question. When would you run the pre-script? In the future we should be able to run the script when loading the profile (to modify it in-place). But we can postpone it until you click the "install" button. I guess we will need to do more adjustments in this area.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it one level up, when you load profile, then run any pre script it will find....but e.g. not before you validate that profile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no, question was not where in the code, but when. Given that the pre scripts does not support changing the profile yet, I am not sure there is a use case for them right now.

Perhaps you want to enable something, but then pre scripts might need to run the probing, but probing happens only once in Agama by now (and for single product scenarios it happens too early).

@imobachgs imobachgs merged commit 78edd27 into master Oct 18, 2024
9 checks passed
@imobachgs imobachgs deleted the auto-scripts branch October 18, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants