From d0fcf039f2d5d82755ba885b4f76cdf34de7b658 Mon Sep 17 00:00:00 2001 From: Piyush Jena Date: Wed, 31 Jul 2024 17:43:24 +0000 Subject: [PATCH] Add Bootstrap Commands --- packages/os/bootstrap-commands-tmpfiles.conf | 1 + packages/os/bootstrap-commands-toml | 12 + packages/os/bootstrap-commands.service | 17 + packages/os/os.spec | 25 +- sources/Cargo.lock | 597 +++++++++++++++--- sources/Cargo.toml | 1 + sources/api/bootstrap-commands/Cargo.toml | 37 ++ sources/api/bootstrap-commands/README.md | 9 + sources/api/bootstrap-commands/README.tpl | 9 + sources/api/bootstrap-commands/build.rs | 3 + sources/api/bootstrap-commands/src/main.rs | 343 ++++++++++ sources/api/bootstrap-containers/Cargo.toml | 2 +- sources/api/bootstrap-containers/src/main.rs | 12 +- sources/api/schnauzer/src/helpers.rs | 140 ++++ sources/api/schnauzer/src/v1.rs | 1 + .../api/schnauzer/src/v2/import/helpers.rs | 1 + sources/deny.toml | 1 + 17 files changed, 1105 insertions(+), 106 deletions(-) create mode 100644 packages/os/bootstrap-commands-tmpfiles.conf create mode 100644 packages/os/bootstrap-commands-toml create mode 100644 packages/os/bootstrap-commands.service create mode 100644 sources/api/bootstrap-commands/Cargo.toml create mode 100644 sources/api/bootstrap-commands/README.md create mode 100644 sources/api/bootstrap-commands/README.tpl create mode 100644 sources/api/bootstrap-commands/build.rs create mode 100644 sources/api/bootstrap-commands/src/main.rs diff --git a/packages/os/bootstrap-commands-tmpfiles.conf b/packages/os/bootstrap-commands-tmpfiles.conf new file mode 100644 index 000000000..86ab20fe9 --- /dev/null +++ b/packages/os/bootstrap-commands-tmpfiles.conf @@ -0,0 +1 @@ +d /etc/bootstrap-commands 0750 root root - diff --git a/packages/os/bootstrap-commands-toml b/packages/os/bootstrap-commands-toml new file mode 100644 index 000000000..04f1c03bb --- /dev/null +++ b/packages/os/bootstrap-commands-toml @@ -0,0 +1,12 @@ +[required-extensions] +bootstrap-commands= "v1" +std = { version = "v1", helpers = ["if_not_null", "join_nested_array"]} ++++ +{{#if_not_null settings.bootstrap-commands}} +{{#each settings.bootstrap-commands}} +[bootstrap-commands."{{@key}}"] +commands = [{{join_nested_array this.commands}}] +mode = "{{{this.mode}}}" +essential = {{this.essential}} +{{/each}} +{{/if_not_null}} diff --git a/packages/os/bootstrap-commands.service b/packages/os/bootstrap-commands.service new file mode 100644 index 000000000..5f0ae42a6 --- /dev/null +++ b/packages/os/bootstrap-commands.service @@ -0,0 +1,17 @@ +[Unit] +Description=Bootstrap Commands +After=settings-applier.service apiserver.service +Requires=settings-applier.service apiserver.service +Before=preconfigured.target +RefuseManualStart=true +RefuseManualStop=true + +[Service] +Type=oneshot +ExecStart=/usr/bin/bootstrap-commands +RemainAfterExit=true +StandardError=journal+console +SyslogIdentifier=bootstrap-commands + +[Install] +WantedBy=preconfigured.target diff --git a/packages/os/os.spec b/packages/os/os.spec index 3951761d4..fb34044de 100644 --- a/packages/os/os.spec +++ b/packages/os/os.spec @@ -32,6 +32,7 @@ Source17: corndog-toml Source18: bootstrap-containers-toml Source19: host-containers-toml Source20: bottlerocket-fips-checks-metadata-json +Source21: bootstrap-commands-toml # 1xx sources: systemd units Source100: apiserver.service @@ -52,6 +53,7 @@ Source119: reboot-if-required.service Source120: warm-pool-wait.service Source122: has-boot-ever-succeeded.service Source123: pluto.service +Source124: bootstrap-commands.service # 2xx sources: tmpfilesd configs Source200: migration-tmpfiles.conf @@ -59,6 +61,7 @@ Source201: host-containers-tmpfiles.conf Source202: thar-be-updates-tmpfiles.conf Source203: bootstrap-containers-tmpfiles.conf Source204: storewolf-tmpfiles.conf +Source205: bootstrap-commands-tmpfiles.conf # 3xx sources: udev rules Source300: ephemeral-storage.rules @@ -89,6 +92,7 @@ Requires: %{_cross_os}sundog Requires: %{_cross_os}xfscli Requires: %{_cross_os}thar-be-settings +Requires: %{_cross_os}bootstrap-commands Requires: (%{_cross_os}bootstrap-containers or %{_cross_os}image-feature(no-host-containers)) Requires: (%{_cross_os}host-containers or %{_cross_os}image-feature(no-host-containers)) @@ -246,6 +250,12 @@ Requires: %{_cross_os}binutils %description -n %{_cross_os}driverdog %{summary}. + +%package -n %{_cross_os}bootstrap-commands +Summary: Manages bootstrap-commands +%description -n %{_cross_os}bootstrap-commands +%{summary}. + %package -n %{_cross_os}bootstrap-containers Summary: Manages bootstrap-containers Requires: %{_cross_os}host-ctr @@ -350,6 +360,7 @@ echo "** Output from non-static builds:" -p metricdog \ -p ghostdog \ -p corndog \ + -p bootstrap-commands \ -p bootstrap-containers \ -p prairiedog \ -p certdog \ @@ -385,7 +396,7 @@ for p in \ storewolf settings-committer \ migrator prairiedog certdog \ signpost updog metricdog logdog \ - ghostdog bootstrap-containers \ + ghostdog bootstrap-commands bootstrap-containers \ shimpei bloodhound \ bottlerocket-cis-checks \ bottlerocket-fips-checks \ @@ -473,14 +484,14 @@ if [ -s "%{_cross_repo_root_json}" ] ; then fi install -d %{buildroot}%{_cross_templatedir} -install -p -m 0644 %{S:5} %{S:6} %{S:7} %{S:8} %{S:14} %{S:15} %{S:16} %{S:17} %{S:18} %{S:19} \ +install -p -m 0644 %{S:5} %{S:6} %{S:7} %{S:8} %{S:14} %{S:15} %{S:16} %{S:17} %{S:18} %{S:19} %{S:21} \ %{buildroot}%{_cross_templatedir} install -d %{buildroot}%{_cross_unitdir} install -p -m 0644 \ %{S:100} %{S:102} %{S:103} %{S:105} \ %{S:106} %{S:107} %{S:110} %{S:111} %{S:112} \ - %{S:113} %{S:114} %{S:119} %{S:122} %{S:123} \ + %{S:113} %{S:114} %{S:119} %{S:122} %{S:123} %{S:124} \ %{buildroot}%{_cross_unitdir} sed -e 's|PREFIX|%{_cross_prefix}|g' %{S:115} > link-kernel-modules.service @@ -502,6 +513,7 @@ install -p -m 0644 %{S:201} %{buildroot}%{_cross_tmpfilesdir}/host-containers.co install -p -m 0644 %{S:202} %{buildroot}%{_cross_tmpfilesdir}/thar-be-updates.conf install -p -m 0644 %{S:203} %{buildroot}%{_cross_tmpfilesdir}/bootstrap-containers.conf install -p -m 0644 %{S:204} %{buildroot}%{_cross_tmpfilesdir}/storewolf.conf +install -p -m 0644 %{S:205} %{buildroot}%{_cross_tmpfilesdir}/bootstrap-commands.conf install -d %{buildroot}%{_cross_udevrulesdir} install -p -m 0644 %{S:300} %{buildroot}%{_cross_udevrulesdir}/80-ephemeral-storage.rules @@ -640,6 +652,13 @@ install -p -m 0644 %{S:400} %{S:401} %{S:402} %{buildroot}%{_cross_licensedir} %{_cross_bindir}/certdog %{_cross_templatedir}/certdog-toml + +%files -n %{_cross_os}bootstrap-commands +%{_cross_bindir}/bootstrap-commands +%{_cross_unitdir}/bootstrap-commands.service +%{_cross_tmpfilesdir}/bootstrap-commands.conf +%{_cross_templatedir}/bootstrap-commands-toml + %files -n %{_cross_os}bootstrap-containers %{_cross_bindir}/bootstrap-containers %{_cross_unitdir}/bootstrap-containers@.service diff --git a/sources/Cargo.lock b/sources/Cargo.lock index 2d59b9c9a..8925b3b1f 100644 --- a/sources/Cargo.lock +++ b/sources/Cargo.lock @@ -1040,12 +1040,31 @@ dependencies = [ "walkdir", ] +[[package]] +name = "bootstrap-commands" +version = "0.1.0" +dependencies = [ + "base64 0.21.7", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-models 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "constants", + "generate-readme", + "itertools", + "log", + "serde", + "serde_json", + "simplelog", + "snafu", + "tempfile", + "toml", +] + [[package]] name = "bootstrap-containers" version = "0.1.0" dependencies = [ "base64 0.22.1", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "constants", "generate-readme", "log", @@ -1062,7 +1081,7 @@ version = "0.1.0" dependencies = [ "rand", "serde_json", - "settings-extension-updates", + "settings-extension-updates 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", ] [[package]] @@ -1075,15 +1094,47 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "bottlerocket-model-derive" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "darling 0.20.10", + "quote", + "syn 2.0.71", +] + [[package]] name = "bottlerocket-modeled-types" version = "0.2.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ "base64 0.21.7", - "bottlerocket-scalar", - "bottlerocket-scalar-derive", - "bottlerocket-string-impls-for", + "bottlerocket-scalar 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "indexmap 2.2.6", + "lazy_static", + "regex", + "semver", + "serde", + "serde_json", + "serde_plain", + "snafu", + "url", + "x509-parser", +] + +[[package]] +name = "bottlerocket-modeled-types" +version = "0.2.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "base64 0.21.7", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "indexmap 2.2.6", "lazy_static", "regex", @@ -1117,12 +1168,35 @@ dependencies = [ "serde_plain", ] +[[package]] +name = "bottlerocket-scalar" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "serde", + "serde_plain", +] + [[package]] name = "bottlerocket-scalar-derive" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-scalar", + "bottlerocket-scalar 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "darling 0.20.10", + "proc-macro2", + "quote", + "serde", + "serde_plain", + "syn 2.0.71", +] + +[[package]] +name = "bottlerocket-scalar-derive" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-scalar 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "darling 0.20.10", "proc-macro2", "quote", @@ -1147,32 +1221,68 @@ name = "bottlerocket-settings-models" version = "0.2.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-scalar", - "bottlerocket-scalar-derive", - "bottlerocket-string-impls-for", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "libc", "serde", "serde_json", - "settings-extension-autoscaling", - "settings-extension-aws", - "settings-extension-bootstrap-containers", - "settings-extension-cloudformation", - "settings-extension-container-registry", - "settings-extension-container-runtime", - "settings-extension-dns", - "settings-extension-ecs", - "settings-extension-host-containers", - "settings-extension-kernel", - "settings-extension-metrics", - "settings-extension-motd", - "settings-extension-network", - "settings-extension-ntp", - "settings-extension-oci-defaults", - "settings-extension-oci-hooks", - "settings-extension-pki", - "settings-extension-updates", + "settings-extension-autoscaling 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-aws 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-bootstrap-containers 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-cloudformation 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-container-registry 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-container-runtime 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-dns 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-ecs 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-host-containers 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-kernel 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-metrics 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-motd 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-network 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-ntp 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-oci-defaults 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-oci-hooks 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-pki 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-updates 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "toml", +] + +[[package]] +name = "bottlerocket-settings-models" +version = "0.2.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-scalar-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "libc", + "serde", + "serde_json", + "settings-extension-autoscaling 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-aws 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-bootstrap-commands", + "settings-extension-bootstrap-containers 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-cloudformation 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-container-registry 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-container-runtime 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-dns 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-ecs 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-host-containers 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-kernel 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-metrics 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-motd 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-network 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-ntp 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-nvidia-container-runtime", + "settings-extension-oci-defaults 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-oci-hooks 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-pki 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "settings-extension-updates 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "toml", ] @@ -1194,7 +1304,20 @@ version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ "argh", - "bottlerocket-template-helper", + "bottlerocket-template-helper 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "serde", + "serde_json", + "snafu", + "tracing", +] + +[[package]] +name = "bottlerocket-settings-sdk" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "argh", + "bottlerocket-template-helper 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "serde", "serde_json", "snafu", @@ -1209,6 +1332,14 @@ dependencies = [ "serde", ] +[[package]] +name = "bottlerocket-string-impls-for" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "serde", +] + [[package]] name = "bottlerocket-template-helper" version = "0.1.0" @@ -1221,6 +1352,18 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "bottlerocket-template-helper" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "darling 0.20.10", + "proc-macro2", + "quote", + "serde_json", + "syn 2.0.71", +] + [[package]] name = "bottlerocket-variant" version = "0.1.0" @@ -1350,7 +1493,7 @@ version = "0.1.0" dependencies = [ "argh", "base64 0.21.7", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "constants", "generate-readme", "log", @@ -1498,7 +1641,7 @@ checksum = "69f3b219d28b6e3b4ac87bc1fc522e0803ab22e055da177bff0068c4150c61a6" name = "corndog" version = "0.1.0" dependencies = [ - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "generate-readme", "log", "serde", @@ -2247,7 +2390,7 @@ name = "host-containers" version = "0.1.0" dependencies = [ "base64 0.21.7", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "constants", "generate-readme", "log", @@ -2777,7 +2920,7 @@ name = "models" version = "0.1.0" dependencies = [ "bottlerocket-release", - "bottlerocket-settings-models", + "bottlerocket-settings-models 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-settings-plugin", "generate-readme", "libc", @@ -3141,7 +3284,7 @@ dependencies = [ "aws-smithy-runtime", "aws-smithy-types", "aws-types", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bytes", "constants", "futures-util", @@ -3179,7 +3322,7 @@ name = "prairiedog" version = "0.1.0" dependencies = [ "argh", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bytes", "constants", "generate-readme", @@ -3498,7 +3641,7 @@ dependencies = [ "argh", "async-trait", "base64 0.22.1", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-release", "cached", "constants", @@ -3519,7 +3662,7 @@ dependencies = [ "serde", "serde_json", "serde_plain", - "settings-extension-oci-defaults", + "settings-extension-oci-defaults 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "simplelog", "snafu", "tokio", @@ -3681,236 +3824,498 @@ name = "settings-extension-autoscaling" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-autoscaling" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-aws" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-aws" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + +[[package]] +name = "settings-extension-bootstrap-commands" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", + "snafu", +] + [[package]] name = "settings-extension-bootstrap-containers" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-bootstrap-containers" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-cloudformation" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-cloudformation" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-container-registry" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-container-registry" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-container-runtime" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-container-runtime" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-dns" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-dns" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-ecs" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-ecs" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-host-containers" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-host-containers" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-kernel" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-kernel" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-metrics" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-metrics" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-motd" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-settings-sdk", - "bottlerocket-string-impls-for", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-motd" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-string-impls-for 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-network" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-network" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-ntp" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-ntp" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + +[[package]] +name = "settings-extension-nvidia-container-runtime" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-oci-defaults" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", "toml", ] +[[package]] +name = "settings-extension-oci-defaults" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", + "toml", +] + [[package]] name = "settings-extension-oci-hooks" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-oci-hooks" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-pki" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "serde", "serde_json", ] +[[package]] +name = "settings-extension-pki" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "serde", + "serde_json", +] + [[package]] name = "settings-extension-updates" version = "0.1.0" source = "git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#848b3153922c5202e4f38c428b7572a9ee313f3f" dependencies = [ - "bottlerocket-model-derive", - "bottlerocket-modeled-types", - "bottlerocket-settings-sdk", + "bottlerocket-model-derive 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "env_logger 0.10.2", "rand", "serde", "serde_json", ] +[[package]] +name = "settings-extension-updates" +version = "0.1.0" +source = "git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0#5fbf87111bfc9bc980d769c81f89ff62fb97494d" +dependencies = [ + "bottlerocket-model-derive 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "bottlerocket-settings-sdk 0.1.0 (git+https://github.com/piyush-jena/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", + "env_logger 0.11.3", + "rand", + "serde", + "serde_json", +] + [[package]] name = "sha1" version = "0.10.6" @@ -4011,7 +4416,7 @@ name = "simple-settings-plugin" version = "0.1.0" dependencies = [ "abi_stable", - "bottlerocket-settings-models", + "bottlerocket-settings-models 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-settings-plugin", "generate-readme", "serde", @@ -4089,7 +4494,7 @@ name = "static-pods" version = "0.1.0" dependencies = [ "base64 0.22.1", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "generate-readme", "log", "serde", @@ -4103,7 +4508,7 @@ dependencies = [ name = "storewolf" version = "0.1.0" dependencies = [ - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-release", "constants", "datastore", @@ -4280,7 +4685,7 @@ dependencies = [ name = "thar-be-updates" version = "0.1.0" dependencies = [ - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-release", "chrono", "fs2", @@ -4701,7 +5106,7 @@ version = "0.1.0" dependencies = [ "argh", "async-trait", - "bottlerocket-modeled-types", + "bottlerocket-modeled-types 0.2.0 (git+https://github.com/bottlerocket-os/bottlerocket-settings-sdk?tag=bottlerocket-settings-models-v0.2.0)", "bottlerocket-release", "bytes", "chrono", diff --git a/sources/Cargo.toml b/sources/Cargo.toml index 606858136..76b91f188 100644 --- a/sources/Cargo.toml +++ b/sources/Cargo.toml @@ -3,6 +3,7 @@ resolver = "1" members = [ "api/apiserver", "api/apiclient", + "api/bootstrap-commands", "api/bootstrap-containers", "api/bork", "api/certdog", diff --git a/sources/api/bootstrap-commands/Cargo.toml b/sources/api/bootstrap-commands/Cargo.toml new file mode 100644 index 000000000..e98e47cac --- /dev/null +++ b/sources/api/bootstrap-commands/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "bootstrap-commands" +version = "0.1.0" +authors = ["Piyush Jena "] +license = "Apache-2.0 OR MIT" +edition = "2021" +publish = false +build = "build.rs" +# Don't rebuild crate just because of changes to README. +exclude = ["README.md"] + +[dependencies] +base64 = "0.21" +constants = { path = "../../constants", version = "0.1" } +itertools = "0.13" +log = "0.4" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1" +simplelog = "0.12" +snafu = "0.8" +toml = "0.8" + +[dependencies.bottlerocket-modeled-types] +git = "https://github.com/piyush-jena/bottlerocket-settings-sdk" +tag = "bottlerocket-settings-models-v0.2.0" +version = "0.2.0" + +[dependencies.bottlerocket-settings-models] +git = "https://github.com/piyush-jena/bottlerocket-settings-sdk" +tag = "bottlerocket-settings-models-v0.2.0" +version = "0.2.0" + +[dev-dependencies] +tempfile = "3" + +[build-dependencies] +generate-readme = { version = "0.1", path = "../../generate-readme" } diff --git a/sources/api/bootstrap-commands/README.md b/sources/api/bootstrap-commands/README.md new file mode 100644 index 000000000..d0a9c3369 --- /dev/null +++ b/sources/api/bootstrap-commands/README.md @@ -0,0 +1,9 @@ +# bootstrap-commands + +Current version: 0.1.0 + + + +## Colophon + +This text was generated using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. diff --git a/sources/api/bootstrap-commands/README.tpl b/sources/api/bootstrap-commands/README.tpl new file mode 100644 index 000000000..bf207d023 --- /dev/null +++ b/sources/api/bootstrap-commands/README.tpl @@ -0,0 +1,9 @@ +# {{crate}} + +Current version: {{version}} + +{{readme}} + +## Colophon + +This text was generated using [cargo-readme](https://crates.io/crates/cargo-readme), and includes the rustdoc from `src/main.rs`. diff --git a/sources/api/bootstrap-commands/build.rs b/sources/api/bootstrap-commands/build.rs new file mode 100644 index 000000000..5b3a661c3 --- /dev/null +++ b/sources/api/bootstrap-commands/build.rs @@ -0,0 +1,3 @@ +fn main() { + generate_readme::from_main().unwrap(); +} diff --git a/sources/api/bootstrap-commands/src/main.rs b/sources/api/bootstrap-commands/src/main.rs new file mode 100644 index 000000000..9ea45df54 --- /dev/null +++ b/sources/api/bootstrap-commands/src/main.rs @@ -0,0 +1,343 @@ +/* +# Bootstrap commands + +Bootstrap Commands in Bottlerocket is a feature that empowers users to execute predefined commands +through the Bottlerocket API. It introduces a new systemd service that facilitates the execution of +these commands, expanding the functionality of the existing Bottlerocket API. + +Currently, Bottlerocket provides a set of actions (such as refresh-updates) that can be accessed +through the apiserver, typically by running the apiclient in the control container. However, this +new feature aims to extend the accessibility of these actions by allowing Bottlerocket consumers +to run them prior to the bootstrap container execution. + +#Example: +Given a bootstrap command called `001-test-bootstrap-commands` with the following configuration: + +[settings.bootstrap-commands.001-test-bootstrap-commands] +commands = [[ "apiclient", "set", "motd=helloworld"]] +essential = true +mode = "always" + +This would update motd from "Welcome to Bottlerocket!" to "helloworld". +*/ + +#[macro_use] +extern crate log; + +use itertools::Itertools; +use serde::{Deserialize, Serialize}; +use simplelog::{Config as LogConfig, LevelFilter, SimpleLogger}; +use snafu::{ensure, OptionExt, ResultExt}; +use std::collections::HashMap; + +use std::env; +use std::ffi::OsStr; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::{self, Command}; +use std::str::FromStr; + +use bottlerocket_modeled_types::{BootstrapMode, Identifier}; +use bottlerocket_settings_models::ValidCommand; + +const DEFAULT_CONFIG_PATH: &str = "/etc/bootstrap-commands/bootstrap-commands.toml"; + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +struct BootstrapCommandConfig { + bootstrap_commands: Option>, +} + +#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +struct BootstrapCommand { + #[serde(default, skip_serializing_if = "Option::is_none")] + commands: Option>, + #[serde(default, skip_serializing_if = "Option::is_none")] + mode: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + essential: Option, +} + +/// Stores user-supplied global arguments +struct Args { + log_level: LevelFilter, + config_path: PathBuf, +} + +impl Default for Args { + fn default() -> Self { + Self { + log_level: LevelFilter::Info, + config_path: PathBuf::from_str(DEFAULT_CONFIG_PATH).unwrap(), + } + } +} + +/// Wrapper around process::Command that adds error checking. +fn command(bin_path: &str, args: I) -> Result<()> +where + I: IntoIterator, + S: AsRef, +{ + let mut command = Command::new(bin_path); + command.args(args); + let output = command + .output() + .context(error::ExecutionFailureSnafu { command })?; + + trace!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + trace!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + + ensure!( + output.status.success(), + error::CommandFailureSnafu { bin_path, output } + ); + + Ok(()) +} + +/// Handles running of the api commands in a Bootstrap command +fn handle_bootstrap_command(name: S, bootstrap_command: &BootstrapCommand) -> Result<()> +where + S: AsRef, +{ + let name = name.as_ref(); + let mode = bootstrap_command.mode.clone().unwrap_or_default(); + let essential = bootstrap_command.essential.unwrap_or(false); + let commands = bootstrap_command.commands.clone().unwrap_or_default(); + + info!("Running bootstrap command with name: {}", name); + + if mode == "off" { + // If mode is 'off', just log this information. + info!("Bootstrap command mode for '{}' is 'off'", name); + } else { + info!("Processing Bootstrap command '{}' ... ", name); + for cmd in commands.iter() { + // this condition is already taken care of + let args = cmd.get_args(); + match args { + Ok(arguments) => { + if let Err(_e) = command("apiclient", arguments) { + if essential { + error::BootstrapCommandFailureSnafu { name }; + } + } + }, + _ => { + if essential { + error::BootstrapCommandFailureSnafu { name }; + } + }, + } + } + + if mode == "once" { + let formatted = format!("settings.bootstrap-commands.{}.mode=off", name); + info!("Turning off bootstrap-command '{}'", name); + command("apiclient", ["set", formatted.as_str()])?; + } + + info!("Succesfully ran bootstrap command '{}'", name); + } + + Ok(()) +} + +/// Query the API for the currently defined bootstrap commands +fn get_bootstrap_commands

(config_path: P) -> Result> +where + P: AsRef, +{ + let config_str = fs::read_to_string(config_path.as_ref()).context(error::ReadConfigSnafu { + config_path: config_path.as_ref(), + })?; + + let config: BootstrapCommandConfig = + toml::from_str(&config_str).context(error::DeserializationSnafu { + config_path: config_path.as_ref(), + })?; + + Ok(config.bootstrap_commands.unwrap_or_default()) +} + +/// Parse the args to the program and return an Args struct +fn parse_args(args: env::Args) -> Result { + let mut global_args = Args::default(); + + let mut iter = args.skip(1); + while let Some(arg) = iter.next() { + match arg.as_ref() { + // Global args + "--log-level" => { + let log_level = iter.next().context(error::UsageSnafu { + message: "Did not give argument to --log-level", + })?; + global_args.log_level = LevelFilter::from_str(&log_level) + .context(error::LogLevelSnafu { log_level })?; + } + + "-c" | "--config-path" => { + let config_str = iter.next().context(error::UsageSnafu { + message: "Did not give argument to --config-path", + })?; + global_args.config_path = PathBuf::from(config_str.as_str()); + } + + _ => (), + } + } + + Ok(global_args) +} + +fn run() -> Result<()> { + let args = parse_args(env::args())?; + + // SimpleLogger will send errors to stderr and anything less to stdout. + SimpleLogger::init(args.log_level, LogConfig::default()).context(error::LoggerSnafu)?; + + let bootstrap_commands = get_bootstrap_commands(args.config_path)?; + + // We want to run bootstrap commands in sorted order of their names. + for name in bootstrap_commands.keys().sorted() { + let bootstrap_command = &bootstrap_commands[name]; + if let Err(e) = handle_bootstrap_command(name, bootstrap_command) { + error!( + "Failed to run essential bootstrap command '{}' : {}", + name, e + ); + } + } + + Ok(()) +} + +fn main() { + if let Err(e) = run() { + eprintln!("{}", e); + process::exit(1); + } +} + +// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= + +mod error { + use snafu::Snafu; + use std::io; + use std::path::PathBuf; + use std::process::{Command, Output}; + + #[derive(Debug, Snafu)] + #[snafu(visibility(pub(super)))] + pub(super) enum Error { + #[snafu(display("Failed to read settings from config at {}: {}", config_path.display(), source))] + ReadConfig { + config_path: PathBuf, + source: std::io::Error, + }, + + #[snafu(display("Failed to deserialize settings from config at {}: {}", config_path.display(), source))] + Deserialization { + config_path: PathBuf, + source: toml::de::Error, + }, + + #[snafu(display("Bootstrap command with name: {} failed.", name))] + BootstrapCommandFailure { name: String }, + + #[snafu(display("'{}' failed - stderr: {}", + bin_path, String::from_utf8_lossy(&output.stderr)))] + CommandFailure { bin_path: String, output: Output }, + + #[snafu(display("Failed to execute '{:?}': {}", command, source))] + ExecutionFailure { + command: Command, + source: std::io::Error, + }, + + #[snafu(display("Logger setup error: {}", source))] + Logger { source: log::SetLoggerError }, + + #[snafu(display("Invalid log level '{}'", log_level))] + LogLevel { + log_level: String, + source: log::ParseLevelError, + }, + + #[snafu(display("Unable to serialize data: {}", source))] + Serialize { source: serde_json::Error }, + + #[snafu(display("Failed to change settings via apiclient: {}", source))] + Set { source: io::Error }, + + #[snafu(display("Failed to change settings, apiclient returned an error"))] + SetClient, + + #[snafu(display("{}", message))] + Usage { message: String }, + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_get_bootstrap_commands() { + let config_toml = r#"[bootstrap-commands."002-test-bootstrap-commands"] + commands = [["apiclient", "set", "motd=helloworld2"], ["apiclient", "set", "motd=helloworld3"]] + mode = "once" + essential = true + + [bootstrap-commands."001-test-bootstrap-commands"] + commands = [["apiclient", "set", "motd=helloworld1"]] + mode = "always" + essential = true + "#; + + let temp_dir = tempfile::TempDir::new().unwrap(); + let temp_config = Path::join(temp_dir.path(), "bootstrap-commands.toml"); + let _ = std::fs::write(&temp_config, config_toml).unwrap(); + + let bootstrap_commands = get_bootstrap_commands(&temp_config).unwrap(); + + let mut expected_bootstrap_commands = HashMap::new(); + expected_bootstrap_commands.insert( + Identifier::try_from("001-test-bootstrap-commands").unwrap(), + BootstrapCommand { + commands: Some(vec![ValidCommand(vec![ + "apiclient".to_string(), + "set".to_string(), + "motd=helloworld1".to_string(), + ])]), + mode: Some(BootstrapMode::try_from("always").unwrap()), + essential: Some(true), + }, + ); + expected_bootstrap_commands.insert( + Identifier::try_from("002-test-bootstrap-commands").unwrap(), + BootstrapCommand { + commands: Some(vec![ + ValidCommand(vec![ + "apiclient".to_string(), + "set".to_string(), + "motd=helloworld2".to_string(), + ]), + ValidCommand(vec![ + "apiclient".to_string(), + "set".to_string(), + "motd=helloworld3".to_string(), + ]), + ]), + mode: Some(BootstrapMode::try_from("once").unwrap()), + essential: Some(true), + }, + ); + + assert_eq!(bootstrap_commands, expected_bootstrap_commands) + } +} + +type Result = std::result::Result; diff --git a/sources/api/bootstrap-containers/Cargo.toml b/sources/api/bootstrap-containers/Cargo.toml index 33a472e01..2ad3d7f40 100644 --- a/sources/api/bootstrap-containers/Cargo.toml +++ b/sources/api/bootstrap-containers/Cargo.toml @@ -20,7 +20,7 @@ snafu = "0.8" toml = "0.8" [dependencies.bottlerocket-modeled-types] -git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk" +git = "https://github.com/piyush-jena/bottlerocket-settings-sdk" tag = "bottlerocket-settings-models-v0.2.0" version = "0.2.0" diff --git a/sources/api/bootstrap-containers/src/main.rs b/sources/api/bootstrap-containers/src/main.rs index 3df47745d..b8aa03b27 100644 --- a/sources/api/bootstrap-containers/src/main.rs +++ b/sources/api/bootstrap-containers/src/main.rs @@ -87,7 +87,7 @@ use std::path::{Path, PathBuf}; use std::process::{self, Command}; use std::str::FromStr; -use bottlerocket_modeled_types::{BootstrapContainerMode, Identifier, Url, ValidBase64}; +use bottlerocket_modeled_types::{BootstrapMode, Identifier, Url, ValidBase64}; const ENV_FILE_DIR: &str = "/etc/bootstrap-containers"; const DROPIN_FILE_DIR: &str = "/etc/systemd/system"; @@ -101,7 +101,7 @@ struct BootstrapContainer { #[serde(default, skip_serializing_if = "Option::is_none")] source: Option, #[serde(default, skip_serializing_if = "Option::is_none")] - mode: Option, + mode: Option, #[serde(default, skip_serializing_if = "Option::is_none")] user_data: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -134,7 +134,7 @@ enum Subcommand { #[derive(Debug)] struct MarkBootstrapArgs { container_id: String, - mode: BootstrapContainerMode, + mode: BootstrapMode, } /// Print a usage message in the event a bad arg is passed @@ -251,7 +251,7 @@ fn parse_mark_bootstrap_args(args: Vec) -> Result { Ok(Subcommand::MarkBootstrap(MarkBootstrapArgs { container_id, // Fail if 'mode' is invalid - mode: BootstrapContainerMode::try_from(mode).context(error::BootstrapContainerModeSnafu)?, + mode: BootstrapMode::try_from(mode).context(error::BootstrapModeSnafu)?, })) } @@ -605,9 +605,9 @@ mod error { source: base64::DecodeError, }, - // `try_from` in `BootstrapContainerMode` already returns a useful error message + // `try_from` in `BootstrapMode` already returns a useful error message #[snafu(display("Failed to parse mode: {}", source))] - BootstrapContainerMode { + BootstrapMode { source: bottlerocket_modeled_types::error::Error, }, diff --git a/sources/api/schnauzer/src/helpers.rs b/sources/api/schnauzer/src/helpers.rs index d99e29170..4b80acdd7 100644 --- a/sources/api/schnauzer/src/helpers.rs +++ b/sources/api/schnauzer/src/helpers.rs @@ -972,6 +972,85 @@ pub fn join_array( Ok(()) } +/// `join_nested_array` is used to join a nested array of scalar strings into a +/// nested array of quoted, delimited strings. The delimiter must be specified. +/// +/// # Example +/// +/// Consider an array of values: `[[ "a", "b", "c" ], [ "d", "e" ]]` stored in a +/// setting such as `settings.somewhere.foo-list`. In our template we can write: +/// `{{ join_nested_array settings.somewhere.foo-list }}` +/// +/// This will render `["a", "b", "c"], ["d", "e"]`. +pub fn join_nested_array( + helper: &Helper<'_, '_>, + _: &Handlebars, + _: &Context, + renderctx: &mut RenderContext<'_, '_>, + out: &mut dyn Output, +) -> Result<(), RenderError> { + trace!("Starting join_nested_array helper"); + let template_name = template_name(renderctx); + check_param_count(helper, template_name, 1)?; + + let nested_array_param = get_param(helper, 0)?; + let nested_array = + nested_array_param + .as_array() + .with_context(|| error::JoinStringsWrongTypeSnafu { + expected_type: "array", + value: nested_array_param.to_owned(), + template: template_name, + })?; + + let mut result = String::new(); + + for (i, array) in nested_array.iter().enumerate() { + if i > 0 { + result.push_str(", "); + } + + result.push('['); + + for (j, value) in array + .as_array() + .with_context(|| error::JoinStringsWrongTypeSnafu { + expected_type: "array", + value: array.to_owned(), + template: template_name, + })? + .iter() + .enumerate() + { + if j > 0 { + result.push_str(", "); + } + + result.push_str( + format!( + "\"{}\"", + value.as_str().context(error::JoinStringsWrongTypeSnafu { + expected_type: "string", + value: value.to_owned(), + template: template_name, + })? + ) + .as_str(), + ); + } + + result.push(']'); + } + + // write it to the template + out.write(&result) + .with_context(|_| error::TemplateWriteSnafu { + template: template_name.to_owned(), + })?; + + Ok(()) +} + /// kube_reserve_memory and kube_reserve_cpu are taken from EKS' calculations. /// https://github.com/awslabs/amazon-eks-ami/blob/db28da15d2b696bc08ac3aacc9675694f4a69933/files/bootstrap.sh @@ -2522,6 +2601,67 @@ mod test_join_array { } } +#[cfg(test)] +mod test_join_nested_array { + use super::*; + use handlebars::RenderError; + use serde::Serialize; + use serde_json::json; + + // A thin wrapper around the handlebars render_template method that includes + // setup and registration of helpers + fn setup_and_render_template(tmpl: &str, data: &T) -> Result + where + T: Serialize, + { + let mut registry = Handlebars::new(); + registry.register_helper("join_nested_array", Box::new(join_nested_array)); + + registry.render_template(tmpl, data) + } + + const TEMPLATE: &str = r#"{{join_nested_array settings.foo-list}}"#; + + #[test] + fn join_nested_array_empty() { + let result = + setup_and_render_template(TEMPLATE, &json!({"settings": {"foo-list": []}})).unwrap(); + let expected = ""; + assert_eq!(result, expected); + } + + #[test] + fn join_nested_array_one_item() { + let result = + setup_and_render_template(TEMPLATE, &json!({"settings": {"foo-list": [["a", "b"]]}})) + .unwrap(); + let expected = r#"["a", "b"]"#; + assert_eq!(result, expected); + } + + #[test] + fn join_nested_array_two_items() { + let result = setup_and_render_template( + TEMPLATE, + &json!({"settings": {"foo-list": [["a", "b"],["c", "d", "e"]]}}), + ) + .unwrap(); + let expected = r#"["a", "b"], ["c", "d", "e"]"#; + assert_eq!(result, expected); + } + + #[test] + fn join_nested_array_empty_item() { + let result = setup_and_render_template( + TEMPLATE, + &json!({"settings": {"foo-list": [["a", "b"], []]}}), + ) + .unwrap(); + let expected = r#"["a", "b"], []"#; + assert_eq!(result, expected); + } +} + #[cfg(test)] mod test_kube_reserve_memory { use super::*; diff --git a/sources/api/schnauzer/src/v1.rs b/sources/api/schnauzer/src/v1.rs index 93d7d65fe..79184ef12 100644 --- a/sources/api/schnauzer/src/v1.rs +++ b/sources/api/schnauzer/src/v1.rs @@ -125,6 +125,7 @@ pub fn build_template_registry() -> Result> { template_registry.register_helper("host", Box::new(helpers::host)); template_registry.register_helper("goarch", Box::new(helpers::goarch)); template_registry.register_helper("join_array", Box::new(helpers::join_array)); + template_registry.register_helper("join_nested_array", Box::new(helpers::join_nested_array)); template_registry.register_helper("kube_reserve_cpu", Box::new(helpers::kube_reserve_cpu)); template_registry.register_helper( "kube_reserve_memory", diff --git a/sources/api/schnauzer/src/v2/import/helpers.rs b/sources/api/schnauzer/src/v2/import/helpers.rs index 4b7bca351..d8dc72829 100644 --- a/sources/api/schnauzer/src/v2/import/helpers.rs +++ b/sources/api/schnauzer/src/v2/import/helpers.rs @@ -69,6 +69,7 @@ fn all_helpers() -> HashMap helper!(handlebars_helpers::base64_decode), "default" => helper!(handlebars_helpers::default), "join_array" => helper!(handlebars_helpers::join_array), + "join_nested_array" => helper!(handlebars_helpers::join_nested_array), "join_map" => helper!(handlebars_helpers::join_map), "if_not_null" => Box::new(handlebars_helpers::IfNotNullHelper), "goarch" => helper!(handlebars_helpers::goarch), diff --git a/sources/deny.toml b/sources/deny.toml index 6133441aa..7ac878262 100644 --- a/sources/deny.toml +++ b/sources/deny.toml @@ -85,4 +85,5 @@ allow-git = [ # We will allow it as an exception until the following is resolved: # https://github.com/bottlerocket-os/bottlerocket-settings-sdk/issues/18 "https://github.com/bottlerocket-os/bottlerocket-settings-sdk", + "https://github.com/piyush-jena/bottlerocket-settings-sdk", ]