-
Notifications
You must be signed in to change notification settings - Fork 618
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
Refactor update-template-ubuntu.sh
and add update-template-debian.sh
#2731
Refactor update-template-ubuntu.sh
and add update-template-debian.sh
#2731
Conversation
153a6e2
to
8b2133d
Compare
8b2133d
to
2af6bcd
Compare
Finally, I've laid the groundwork to add code for other distributions. Now, I'll start adding code for Debian. |
2af6bcd
to
4b0396f
Compare
Added $ hack/update-template-debian.sh
update-template-debian.sh: Update the Debian image location in the specified templates
Usage:
update-template-debian.sh [--backports[=<bool>]] [--daily[=<bool>]] [--timestamped[=<bool>]] [--version <version>] <template.yaml>...
Description:
This script updates the Debian image location in the specified templates.
If the image location in the template contains a release date in the URL, the script replaces it with the latest available date.
If no flags are specified, the script uses the version from the image location basename in the template.
Image location basename format: debian-<version>[-backports]-genericcloud-<arch>[-daily][-<timestamp>].qcow[2](https://github.com/lima-vm/lima/issues/2)
Published Debian image information is fetched from the following URLs:
https://cloud.debian.org/images/cloud/<codename>[-backports]/[daily/](latest|<timestamp>)/debian-<version>[-backports]-genericcloud-<arch>[-daily][-<timestamp>].json
The downloaded JSON file will be cached in the Lima cache directory.
Examples:
Update the Debian image location in templates/**.yaml:
$ update-template-debian.sh templates/**.yaml
Update the Debian image location in ~/.lima/debian/lima.yaml:
$ update-template-debian.sh ~/.lima/debian/lima.yaml
Update the Debian image location to debian-[13](https://github.com/lima-vm/lima/issues/13)-genericcloud-<arch>.qcow[2](https://github.com/lima-vm/lima/issues/2) in ~/.lima/debian/lima.yaml:
$ update-template-debian.sh --version trixie ~/.lima/debian/lima.yaml
Flags:
--backports[=<bool>] Use the backports image
The boolean value can be true, false, [1](https://github.com/lima-vm/lima/issues/1), or [0](https://github.com/lima-vm/lima/issues/0)
--daily[=<bool>] Use the daily image
--timestamped[=<bool>] Use the timestamped image
--version <version> Use the specified version
The version can be a codename, version number, or alias (testing, stable, oldstable)
-h, --help Print this help message |
The |
Thanks, I tried $ ./hack/update-template.sh templates/*.yaml
[...]
Processing templates/centos-stream.yaml
Processing templates/debian-11.yaml
Processing templates/debian-12.yaml
Processing templates/debian.yaml
Processing templates/default.yaml
{
"location": "https://cloud-images.ubuntu.com/releases/24.04/release-20241004/ubuntu-24.04-server-cloudimg-amd64.img",
"arch": "x86_64",
"digest": "sha256:fad101d50b06b26590cf30542349f9e9d3041ad7929e3bc3531c81ec27f2c788"
}
... |
$ $(basename "${BASH_SOURCE[0]}") ~/.lima/debian/lima.yaml | ||
|
||
Update the Debian image location to debian-13-genericcloud-<arch>.qcow2 in ~/.lima/debian/lima.yaml: | ||
$ $(basename "${BASH_SOURCE[0]}") --version trixie ~/.lima/debian/lima.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs limactl refactor-reset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
$ limactl factory-reset debian
to help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Please consider squashing the commits |
…mplate{,-debian}.sh cache-common-inc.sh: Prevent `download_to_cache` from rechecking URLs within 10 minutes Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `ubuntu_` prefix to some symbols Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change some parameters order in some function Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: avoid reusing parameters for flags Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `ubuntu_{flavor,version}_from_location` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `ubuntu_location_url_spec` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: temporarily remove URL caching for refactoring Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `ubuntu_{arch,path_suffix}_from_location` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change some functions to return json Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: refactor checking `url_spec` condition Signed-off-by: Norio Nomura <norio.nomura@gmail.com> hack/cache-common-inc.sh: change `download_to_cache` to use JSON instead of tsv Since `unpacked/SHA256SUMS` has no `Content-Type`, the output of `curl -w` formatted as TSV causes `IFS=$'\t' read -r` to fail during parsing. Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change downloading `unpacked/SHA256SUMS` to use cache Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `ubuntu_image_entry_for_image_kernel_flavor_version` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change to `ubuntu_image_entry_with_kernel_info` that returns the image entry with the kernel info instead of returning the kernel info. Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change to use `json_vars` for creating JSON Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: support version aliases: latest, lts Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: change to fully utilize `set -e` Functions in this script assume error handling with 'set -e'. To ensure 'set -e' works correctly: - Use 'set +e' before assignments and '$(set -e; <function>)' to capture output without exiting on errors. - Avoid calling functions directly in conditions to prevent disabling 'set -e'. - Use 'shopt -s inherit_errexit' (Bash 4.4+) to avoid repeated 'set -e' in all '$(...)'. Changes: - Add `error_exit` and more error messages - Remove `|| return` after `$(...)` - Use `jq -e` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: simplify script for `limactl edit --set` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add `image_entry` caching Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: check for `.kernel` in `image_entry` before adding `.kernel.cmdline` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: add error message for when `com.ubuntu.cloud:released:download.json` does not contain a matching image Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: include `_with_kernel` to cache key if kernel location is not null Signed-off-by: Norio Nomura <norio.nomura@gmail.com> cache-common-inc.sh: move `error_exit` from `update-template-ubuntu.sh` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template.sh: add `update-template.sh` script to update all distributions - Move functions common to all distributions here. - Scripts for specific distributions accept distribution-specific options and perform additional actions. Signed-off-by: Norio Nomura <norio.nomura@gmail.com> hack/(cache-common-inc|update-template*).sh: fix some comments - change `return` to `print` in comments - remove stale comment Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-ubuntu.sh: rename the functions to indicate they are using location basename Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template-debian.sh: support updating Debian image information in template files ```console $ hack/update-template-debian.sh update-template-debian.sh: Update the Debian image location in the specified templates Usage: update-template-debian.sh [--backports[=<bool>]] [--daily[=<bool>]] [--timestamped[=<bool>]] [--version <version>] <template.yaml>... Description: This script updates the Debian image location in the specified templates. If the image location in the template contains a release date in the URL, the script replaces it with the latest available date. If no flags are specified, the script uses the version from the image location basename in the template. Image location basename format: debian-<version>[-backports]-genericcloud-<arch>[-daily][-<timestamp>].qcow2 Published Debian image information is fetched from the following URLs: https://cloud.debian.org/images/cloud/<codename>[-backports]/[daily/](latest|<timestamp>)/debian-<version>[-backports]-genericcloud-<arch>[-daily][-<timestamp>].json The downloaded JSON file will be cached in the Lima cache directory. Examples: Update the Debian image location in templates/**.yaml: $ update-template-debian.sh templates/**.yaml Update the Debian image location in ~/.lima/debian/lima.yaml: $ update-template-debian.sh ~/.lima/debian/lima.yaml Update the Debian image location to debian-13-genericcloud-<arch>.qcow2 in ~/.lima/debian/lima.yaml: $ update-template-debian.sh --version trixie ~/.lima/debian/lima.yaml Flags: --backports[=<bool>] Use the backports image The boolean value can be true, false, 1, or 0 --daily[=<bool>] Use the daily image --timestamped[=<bool>] Use the timestamped image --version <version> Use the specified version The version can be a codename, version number, or alias (testing, stable, oldstable) -h, --help Print this help message ``` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template{,-debian}.sh: fix update-template.sh did not sourced `update-template-debian.sh` Signed-off-by: Norio Nomura <norio.nomura@gmail.com> update-template{,-debian,-ubuntu}.sh: add `limactl factory-reset` to examples in help Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
44aaa52
to
7ff9f6b
Compare
done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Thanks! 🙏🏻 |
update-template-ubuntu.sh
to separate distribution-specific code.update-template.sh
.update-template-debian.sh
to handle Debian.This PR aims to add Debian support as per #1347.
Also fixes: #2756