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

Resolve deployment issues with Ubuntu/Cloudimg builds + a custom kernel #176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions ubuntu/scripts/cloudimg/curtin-hooks
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# curtin-hooks - Curtin installation hooks for Ubuntu
#
# Copyright (C) 2022 Canonical
# Copyright (C) 2023 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -21,7 +21,19 @@ import shutil

from curtin.commands.curthooks import builtin_curthooks
from curtin.config import load_command_config
from curtin.util import load_command_environment
from curtin.util import load_command_environment, ChrootableTarget
from curtin.log import LOG
from curtin.paths import target_path

def run_hook_in_target(target, hook):
"""Look for "hook" in "target" and run in a chroot"""
target_hook = target_path(target, '/curtin/' + hook)
if os.path.isfile(target_hook):
LOG.debug("running %s" % target_hook)
with ChrootableTarget(target=target) as in_chroot:
in_chroot.subp(['/curtin/' + hook])
return True
return False


def configure_custom_kernel(config):
Expand Down Expand Up @@ -52,6 +64,7 @@ def main():

config = configure_custom_kernel(config)
builtin_curthooks(config, target, state)
run_hook_in_target(target, 'install-custom-kernel')
cleanup()


Expand Down
15 changes: 5 additions & 10 deletions ubuntu/scripts/cloudimg/install-custom-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# install-custom-kernel.sh - Install custom kernel, if specified
#
# Copyright (C) 2021 Canonical
# Copyright (C) 2023 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -18,14 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export DEBIAN_FRONTEND=noninteractive

if [ -z "${CLOUDIMG_CUSTOM_KERNEL}" ]; then
echo "Not installing custom kernel, since none was specified."
exit 0
if [ -f /curtin/CUSTOM_KERNEL ]; then
KERNEL_PKG=$(cat /curtin/CUSTOM_KERNEL)
echo "Installing custom kernel ${KERNEL_PKG}"
apt-get install -y ${KERNEL_PKG}
fi

echo "Installing custom kernel ${CLOUDIMG_CUSTOM_KERNEL}"
apt-get install -y ${CLOUDIMG_CUSTOM_KERNEL}

# Record the installed kernel version, so that the curtin hook knows about it.
mkdir -p /curtin
echo -n "${CLOUDIMG_CUSTOM_KERNEL}" > /curtin/CUSTOM_KERNEL
28 changes: 28 additions & 0 deletions ubuntu/scripts/cloudimg/register-custom-kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -ex
#
# register-custom-kernel.sh - Register a custom kernel to be installed
#
# Copyright (C) 2023 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export DEBIAN_FRONTEND=noninteractive

if [ -z "${CLOUDIMG_CUSTOM_KERNEL}" ]; then
echo "Not installing custom kernel, since none was specified."
exit 0
fi

# Register the custom kernel version, so that the curtin hook knows about it.
mkdir -p /curtin
echo -n "${CLOUDIMG_CUSTOM_KERNEL}" > /curtin/CUSTOM_KERNEL
5 changes: 3 additions & 2 deletions ubuntu/ubuntu-cloudimg.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ build {
"CLOUDIMG_CUSTOM_KERNEL=${var.kernel}",
"DEBIAN_FRONTEND=noninteractive"
]
scripts = ["${path.root}/scripts/cloudimg/install-custom-kernel.sh"]
scripts = ["${path.root}/scripts/cloudimg/register-custom-kernel.sh"]
}

provisioner "file" {
destination = "/tmp/"
sources = ["${path.root}/scripts/cloudimg/curtin-hooks"]
sources = ["${path.root}/scripts/cloudimg/curtin-hooks",
"${path.root}/scripts/cloudimg/install-custom-kernel.sh"]
}

provisioner "shell" {
Expand Down