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

Add Option to Create Vagrant Box for Local Development with MAAS Image #147

Closed
wants to merge 8 commits 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packer_cache
\#*\#
.#*
*.*.swp
*.box
*.gz
*.xz
*.iso
Expand Down
10 changes: 8 additions & 2 deletions ubuntu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ seeds-lvm.iso: user-data-lvm meta-data
seeds-flat.iso: user-data-flat meta-data
cloud-localds $@ $^

seeds-box.iso: user-data-box meta-data
cloud-localds $@ $^

OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd
cp -v $< $@

Expand All @@ -39,9 +42,12 @@ custom-ubuntu.tar.gz: check-deps clean seeds-flat.iso OVMF_VARS.fd \
custom-ubuntu-lvm.dd.gz: check-deps clean seeds-lvm.iso OVMF_VARS.fd
${PACKER} init . && ${PACKER} build -only=qemu.lvm .

custom-ubuntu-virtual.box: check-deps clean seeds-box.iso OVMF_VARS.fd
${PACKER} init . && ${PACKER} build -only=virtualbox-iso.box .

clean:
${RM} -rf output-* custom-*.gz \
seeds-flat.iso seeds-lvm.iso seeds-cloudimg.iso \
seeds-flat.iso seeds-lvm.iso seeds-box.iso seeds-cloudimg.iso \
OVMF_VARS.fd

CUSTOM_PKGS:=${wildcard packages/*.deb}
Expand All @@ -54,4 +60,4 @@ else
endif

.INTERMEDIATE: OVMF_VARS.fd packages/custom-packages.tar.gz \
seeds-flat.iso seeds-lvm.iso seeds-cloudimg.iso
seeds-flat.iso seeds-lvm.iso seeds-box.iso seeds-cloudimg.iso
6 changes: 6 additions & 0 deletions ubuntu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ to build a raw image with LVM, alternatively, you can build a TGZ image
make custom-ubuntu.tar.gz
```

To build a virtualbox image for vagrant using the Makefile:

```shell
make custom-ubuntu-virtual.box
```

You can also manually run packer. Your current working directory must
be in packer-maas/ubuntu, where this file is located. Once in
packer-maas/ubuntu you can generate an image with:
Expand Down
62 changes: 62 additions & 0 deletions ubuntu/ubuntu-box.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
packer {
required_plugins {
virtualbox = {
version = "~> 1"
source = "github.com/hashicorp/virtualbox"
}
vagrant = {
source = "github.com/hashicorp/vagrant"
version = "~> 1"
}
}
}

source "virtualbox-iso" "box" {
boot_command = ["<wait>e<wait5>", "<down><wait><down><wait><down><wait2><end><wait5>", "<bs><bs><bs><bs><wait>autoinstall ---<wait><f10>"]
boot_wait = "2s"
cpus = 2
disk_size = 8192
guest_os_type = "Ubuntu_64"
headless = var.headless
http_directory = var.http_directory
iso_checksum = "file:http://releases.ubuntu.com/jammy/SHA256SUMS"
iso_target_path = "packer_cache/ubuntu.iso"
iso_url = "https://releases.ubuntu.com/jammy/ubuntu-22.04.3-live-server-amd64.iso"
memory = 2048
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
ssh_password = var.ssh_ubuntu_password
ssh_timeout = "45m"
ssh_username = "ubuntu"
ssh_wait_timeout = "45m"
vboxmanage = [
["modifyvm", "{{.Name}}", "--vram", "16"],
["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
["storagectl", "{{.Name}}", "--name", "IDE Controller", "--add", "ide"],
["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "0", "--device", "0", "--type", "hdd", "--medium", "output-lvm/packer-lvm.vdi"],
["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "1", "--device", "0", "--type", "dvddrive", "--medium", "seeds-lvm.iso"],
["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "2", "--device", "0", "--type", "dvddrive", "--medium", "packer_cache/ubuntu.iso"],
["modifyvm", "{{.Name}}", "--firmware", "efi"],
["modifyvm", "{{.Name}}", "--boot1", "disk", "--boot2", "dvd"]
]
}

build {
sources = ["source.virtualbox-iso.box"]

provisioner "file" {
destination = "/tmp/curtin-hooks"
source = "${path.root}/scripts/curtin-hooks"
}

provisioner "shell" {
environment_vars = ["HOME_DIR=/home/ubuntu", "http_proxy=${var.http_proxy}", "https_proxy=${var.https_proxy}", "no_proxy=${var.no_proxy}"]
execute_command = "echo 'ubuntu' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
scripts = ["${path.root}/scripts/curtin.sh", "${path.root}/scripts/networking.sh", "${path.root}/scripts/cleanup.sh"]
}

post-processor "vagrant" {
output = "custom-ubuntu-virtual.box"
}
}
23 changes: 23 additions & 0 deletions ubuntu/user-data-box
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#cloud-config
autoinstall:
version: 1
identity:
hostname: ubuntu
username: ubuntu
password: "$6$canonical.$0zWaW71A9ke9ASsaOcFTdQ2tx1gSmLxMPrsH0rF0Yb.2AEKNPV1lrF94n6YuPJmnUy2K2/JSDtxuiBDey6Lpa/"
keyboard:
layout: us
variant: ''
ssh:
install-server: true
storage:
grub:
update_nvram: true
swap:
size: 0
layout:
name: lvm
late-commands:
- echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu
package_update: true
package_upgrade: true