-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a template for building images from Ubuntu cloud images. (#58)
It's faster than using the other Ubuntu templates, and allows to create images that don't have a kernel in them, like the images from images.maas.io. It also allows building for arm64, as well as amd64.
- Loading branch information
Showing
12 changed files
with
507 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
instance-id: iid-local01 | ||
local-hostname: packer-ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash -e | ||
# | ||
# cleanup.sh - Clean up what we did to be able to build the image. | ||
# | ||
# Copyright (C) 2022 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/>. | ||
|
||
|
||
# cloud-init put networking in place on initial boot. Let's remove that, to | ||
# allow MAAS to configure the networking on deploy. | ||
rm /etc/netplan/50-cloud-init.yaml | ||
|
||
# Everything in /run/packer_backup should be restored. | ||
find /run/packer_backup | ||
cp --preserve -r /run/packer_backup/ / | ||
rm -rf /run/packer_backup | ||
|
||
# We had to allow root to ssh for the image setup. Let's try to revert that. | ||
sed -i s/^root:[^:]*/root:*/ /etc/shadow | ||
rm -r /root/.ssh | ||
rm -r /root/.cache | ||
rm -r /etc/ssh/ssh_host_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
# curtin-hooks - Curtin installation hooks for Ubuntu | ||
# | ||
# Copyright (C) 2022 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/>. | ||
|
||
import os | ||
import shutil | ||
|
||
from curtin.commands.curthooks import builtin_curthooks | ||
from curtin.config import load_command_config | ||
from curtin.util import load_command_environment | ||
|
||
|
||
def configure_custom_kernel(config): | ||
"""Amend the curtin config to explicity specify the kernel to install. | ||
The name of the kernel to install should already have been written to the | ||
CUSTOM_KERNEL file in the same directory as this file. | ||
""" | ||
custom_kernel_path = os.path.join( | ||
os.path.dirname(__file__), "CUSTOM_KERNEL") | ||
with open(custom_kernel_path, "r") as custom_kernel_file: | ||
custom_kernel_package = custom_kernel_file.read().strip() | ||
kernel_config = config.setdefault("kernel", {}) | ||
kernel_config["package"] = custom_kernel_package | ||
return config | ||
|
||
|
||
def cleanup(): | ||
"""Remove curtin-hooks so its as if we were never here.""" | ||
curtin_dir = os.path.dirname(__file__) | ||
shutil.rmtree(curtin_dir) | ||
|
||
|
||
def main(): | ||
state = load_command_environment() | ||
config = load_command_config(None, state) | ||
target = state['target'] | ||
|
||
config = configure_custom_kernel(config) | ||
builtin_curthooks(config, target, state) | ||
cleanup() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash -e | ||
# | ||
# install-custom-kernel.sh - Install custom kernel, if specified | ||
# | ||
# Copyright (C) 2021 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 | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash -e | ||
# | ||
# setup-boot.sh - Set up the image after initial boot | ||
# | ||
# Copyright (C) 2022 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/>. | ||
|
||
|
||
# Configure apt proxy if needed. | ||
packer_apt_proxy_config="/etc/apt/apt.conf.d/packer-proxy.conf" | ||
if [ ! -z "${http_proxy}" ]; then | ||
echo "Acquire::http::Proxy \"${http_proxy}\";" >> ${packer_apt_proxy_config} | ||
fi | ||
if [ ! -z "${https_proxy}" ]; then | ||
echo "Acquire::https::Proxy \"${https_proxy}\";" >> ${packer_apt_proxy_config} | ||
fi | ||
|
||
# Reset cloud-init, so that it can run again when MAAS deploy the image. | ||
cloud-init clean --logs | ||
|
||
# The cloud image for qemu has a kernel already. Remove it, since the user | ||
# should either install a kernel in the customize script, or let MAAS install | ||
# the right kernel when deploying. | ||
apt-get remove --purge -y linux-virtual 'linux-image-*' | ||
apt-get autoremove --purge -yq | ||
apt-get clean -yq |
Oops, something went wrong.