From 24fd649152b3ca18a1024d3a2ea40806c0c96cf2 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 31 Oct 2023 11:33:00 -0400 Subject: [PATCH] fix: run SOCI as a systemd service (#667) Issue #, if available: #660 and probably #661 *Description of changes:* - Run SOCI as a systemd service - Ported from #649, which still needs more time before we can merge it *Testing done:* - e2e/unit tests - [x] I've reviewed the guidance in CONTRIBUTING.md #### License Acceptance By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Signed-off-by: Justin Alvarez --- pkg/config/lima_config_applier.go | 28 +++++++++++++++++--------- pkg/config/lima_config_applier_test.go | 12 ++++++++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pkg/config/lima_config_applier.go b/pkg/config/lima_config_applier.go index 2ed4000c1..68db18892 100644 --- a/pkg/config/lima_config_applier.go +++ b/pkg/config/lima_config_applier.go @@ -22,6 +22,7 @@ const ( sociInstallationProvisioningScriptHeader = "# soci installation and configuring" sociFileNameFormat = "soci-snapshotter-%s-linux-%s.tar.gz" sociDownloadURLFormat = "https://github.com/awslabs/soci-snapshotter/releases/download/v%s/%s" + sociServiceDownloadURLFormat = "https://raw.githubusercontent.com/awslabs/soci-snapshotter/v%s/soci-snapshotter.service" sociInstallationScriptFormat = `%s if [ ! -f /usr/local/bin/soci ]; then # download soci @@ -29,18 +30,23 @@ if [ ! -f /usr/local/bin/soci ]; then curl --retry 2 --retry-max-time 120 -OL "%s" # move to usr/local/bin tar -C /usr/local/bin -xvf %s soci soci-snapshotter-grpc + # changing containerd config + echo " [proxy_plugins.soci] + type = \"snapshot\" + address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> /etc/containerd/config.toml + + # install as a systemd service + curl --retry 2 --retry-max-time 120 -OL "%s" + mv soci-snapshotter.service /usr/local/lib/systemd/system/ + ln -s /usr/local/lib/systemd/system/soci-snapshotter.service /etc/systemd/system/multi-user.target.wants/ + restorecon -v /usr/local/lib/systemd/system/soci-snapshotter.service + systemctl daemon-reload + sudo systemctl add-requires soci-snapshotter.service containerd.service + systemctl enable --now soci-snapshotter fi -# changing containerd config -export config=etc/containerd/config.toml -echo " [proxy_plugins.soci] - type = \"snapshot\" - address = \"/run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock\" " >> $config - sudo systemctl restart containerd.service -sudo soci-snapshotter-grpc &> ~/soci-snapshotter-logs & - - ` +` userModeEmulationProvisioningScriptHeader = "# cross-arch tools" ) @@ -251,7 +257,9 @@ func toggleSoci(limaCfg *limayaml.LimaYAML, enabled bool, isDefault bool, sociVe idx, hasScript := findSociInstallationScript(limaCfg) sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) - sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadURL, sociFileName) + sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion) + sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, + sociDownloadURL, sociFileName, sociServiceDownloadURL) if !hasScript && enabled { limaCfg.Provision = append(limaCfg.Provision, limayaml.Provision{ Mode: "system", diff --git a/pkg/config/lima_config_applier_test.go b/pkg/config/lima_config_applier_test.go index 6ea05586b..c8ffb50ae 100644 --- a/pkg/config/lima_config_applier_test.go +++ b/pkg/config/lima_config_applier_test.go @@ -116,10 +116,12 @@ fi sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) + sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion) sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadURL, - sociFileName) + sociFileName, + sociServiceDownloadURL) var limaCfg limayaml.LimaYAML err = yaml.Unmarshal(buf, &limaCfg) @@ -286,10 +288,12 @@ fi sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) + sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion) sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadURL, - sociFileName) + sociFileName, + sociServiceDownloadURL) var limaCfg limayaml.LimaYAML err = yaml.Unmarshal(buf, &limaCfg) @@ -348,10 +352,12 @@ fi sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, system.NewStdLib().Arch()) sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName) + sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion) sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader, sociDownloadURL, - sociFileName) + sociFileName, + sociServiceDownloadURL) var limaCfg limayaml.LimaYAML err = yaml.Unmarshal(buf, &limaCfg)