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

ubuntu: enable packing riscv64 cloud images #214

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions ubuntu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ kernel on deploy.

### Building different architectures

By default, images are produces for amd64. You can build for arm64 as well if
you specify the `architecture` parameter:
By default, images are produces for amd64. You can build for arm64 or riscv64
as well if you specify the `architecture` parameter:

```shell
packer init .
Expand Down Expand Up @@ -149,7 +149,8 @@ Specify the Ubuntu Series to build. The default value is set to Jammy.

#### ARCH

Target image architecture. Supported values are amd64 (default) and arm64.
Target image architecture. Supported values are amd64 (default), arm64, and
riscv64.

#### URL

Expand Down
19 changes: 15 additions & 4 deletions ubuntu/ubuntu-cloudimg.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@ locals {
qemu_arch = {
"amd64" = "x86_64"
"arm64" = "aarch64"
"riscv64" = "riscv64"
}
uefi_dir = {
"amd64" = "OVMF"
"arm64" = "AAVMF"
"riscv64" = "qemu-efi-riscv64"
}
uefi_imp = {
"amd64" = "OVMF"
"arm64" = "AAVMF"
"riscv64" = "RISCV_VIRT"
}
qemu_machine = {
"amd64" = "ubuntu,accel=kvm"
"arm64" = "virt"
"riscv64" = "virt,acpi=off"
}
qemu_cpu = {
"amd64" = "host"
"arm64" = "cortex-a57"
"riscv64" = "rv64"
}

proxy_env = [
Expand Down Expand Up @@ -46,10 +55,12 @@ source "qemu" "cloudimg" {
["-machine", "${lookup(local.qemu_machine, var.architecture, "")}"],
["-cpu", "${lookup(local.qemu_cpu, var.architecture, "")}"],
["-device", "virtio-gpu-pci"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/${lookup(local.uefi_imp, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_CODE${var.ovmf_suffix}.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/${lookup(local.uefi_dir, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_CODE${var.ovmf_suffix}.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd"],
["-drive", "file=output-cloudimg/packer-cloudimg,format=qcow2"],
["-drive", "file=seeds-cloudimg.iso,format=raw"]
["-drive", "file=output-cloudimg/packer-cloudimg,format=qcow2,if=none,id=disk1"],
["-device", "virtio-blk-pci,drive=disk1,bootindex=1"],
["-drive", "file=seeds-cloudimg.iso,format=raw,if=none,id=disk2"],
["-device", "virtio-blk-pci,drive=disk2"]
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
Expand All @@ -66,7 +77,7 @@ build {

provisioner "shell-local" {
inline = [
"cp /usr/share/${lookup(local.uefi_imp, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd ${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd",
"cp /usr/share/${lookup(local.uefi_dir, var.architecture, "")}/${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd ${lookup(local.uefi_imp, var.architecture, "")}_VARS.fd",
"cloud-localds seeds-cloudimg.iso user-data-cloudimg meta-data"
]
inline_shebang = "/bin/bash -e"
Expand Down
2 changes: 1 addition & 1 deletion ubuntu/ubuntu-cloudimg.variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ variable "customize_script" {
variable "architecture" {
type = string
default = "amd64"
description = "The architecture to build the image for (amd64 or arm64)"
description = "The architecture to build the image for (amd64, arm64, or riscv64)"
}

variable "ovmf_suffix" {
Expand Down
Loading