Skip to content

Commit

Permalink
Convert Ubuntu 20.04 base image template into HCL2
Browse files Browse the repository at this point in the history
This runs the `packer hcl2_upgrade` command on the template file of
the Ubuntu 20.04 base image to use the new HCL2 format instead of the
legacy JSON one.
  • Loading branch information
replaceafill committed Jan 21, 2025
1 parent 9079a5d commit e10539d
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 116 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/vagrant-box-archivematica.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ jobs:
run: |
echo "USER=$USER" >> $GITHUB_ENV
echo "LOGNAME=$USER" >> $GITHUB_ENV
- name: Install packer plugins
run: |
packer plugins install github.com/hashicorp/virtualbox
packer plugins install github.com/hashicorp/ansible
packer plugins install github.com/hashicorp/vagrant
- name: Build
run: |
cd ${{ github.workspace }}/packer/templates/vagrant-base-ubuntu-20.04-amd64
packer build -on-error=abort template.json
packer init template.json.pkr.hcl
packer build -on-error=abort template.json.pkr.hcl
- name: Upload base image
uses: actions/upload-artifact@v4
with:
Expand Down
110 changes: 0 additions & 110 deletions packer/templates/vagrant-base-ubuntu-20.04-amd64/template.json

This file was deleted.

182 changes: 182 additions & 0 deletions packer/templates/vagrant-base-ubuntu-20.04-amd64/template.json.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
packer {
required_plugins {
virtualbox = {
source = "github.com/hashicorp/virtualbox"
version = "~> 1"
}
}
}

variable "box_basename" {
type = string
default = "ubuntu-20.04"
}

variable "cpus" {
type = string
default = "2"
}

variable "disk_size" {
type = string
default = "20960"
}

variable "git_revision" {
type = string
default = "__unknown_git_revision__"
}

variable "headless" {
type = string
default = "true"
}

variable "http_proxy" {
type = string
default = "${env("http_proxy")}"
}

variable "https_proxy" {
type = string
default = "${env("https_proxy")}"
}

variable "iso_checksum" {
type = string
default = "f11bda2f2caed8f420802b59f382c25160b114ccc665dbac9c5046e7fceaced2"
}

variable "iso_name" {
type = string
default = "ubuntu-20.04.1-legacy-server-amd64.iso"
}

variable "memory" {
type = string
default = "4096"
}

variable "metadata" {
type = string
default = "floppy/dummy_metadata.json"
}

variable "mirror" {
type = string
default = "http://cdimage.ubuntu.com/ubuntu-legacy-server/releases"
}

variable "mirror_directory" {
type = string
default = "20.04.1/release/"
}

variable "name" {
type = string
default = "ubuntu-20.04"
}

variable "no_proxy" {
type = string
default = "${env("no_proxy")}"
}

variable "preseed_path" {
type = string
default = "../../http/ubuntu-20.04/preseed.cfg"
}

variable "template" {
type = string
default = "vagrant-base-ubuntu-20.04-amd64"
}

variable "version" {
type = string
default = "2.1.TIMESTAMP"
}

locals {
build_timestamp = "${timestamp()}"
}

source "virtualbox-iso" "ubuntu" {
boot_command = [
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"/install/vmlinuz<wait>",
" auto<wait>",
" console-setup/ask_detect=false<wait>",
" console-setup/layoutcode=us<wait>",
" console-setup/modelcode=pc105<wait>",
" debconf/frontend=noninteractive<wait>",
" debian-installer=en_US.UTF-8<wait>",
" fb=false<wait>",
" initrd=/install/initrd.gz<wait>",
" kbd-chooser/method=us<wait>",
" keyboard-configuration/layout=USA<wait>",
" keyboard-configuration/variant=USA<wait>",
" locale=en_US.UTF-8<wait>",
" netcfg/get_domain=vm<wait>",
" netcfg/get_hostname=vagrant<wait>",
" grub-installer/bootdev=/dev/sda<wait>",
" noapic<wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
" -- <wait>",
"<enter><wait>"
]
boot_wait = "10s"
disk_size = "${var.disk_size}"
guest_os_type = "Ubuntu_64"
hard_drive_interface = "sata"
headless = "${var.headless}"
http_directory = "../../http/ubuntu-20.04"
iso_checksum = "${var.iso_checksum}"
iso_urls = [
"iso/ubuntu-20.04.1-legacy-server-amd64.iso",
"http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04.1-legacy-server-amd64.iso"
]
output_directory = "../../builds/virtualbox/vagrant-base-ubuntu-20.04-amd64"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_port = 22
ssh_username = "vagrant"
ssh_wait_timeout = "10000s"
vboxmanage = [
["modifyvm", "{{ .Name }}", "--memory", "${var.memory}"],
["modifyvm", "{{ .Name }}", "--cpus", "${var.cpus}"]
]
virtualbox_version_file = ".vbox_version"
vm_name = "${var.template}"
}

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

provisioner "shell" {
environment_vars = [
"HOME_DIR=/home/vagrant",
"http_proxy=${var.http_proxy}",
"https_proxy=${var.https_proxy}",
"no_proxy=${var.no_proxy}"
]
execute_command = "echo 'vagrant' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
scripts = [
"../../scripts/ubuntu/update.sh",
"../../scripts/common/sshd.sh",
"../../scripts/ubuntu/networking.sh",
"../../scripts/ubuntu/sudoers.sh",
"../../scripts/ubuntu/vagrant.sh",
"../../scripts/common/virtualbox.sh",
"../../scripts/ubuntu/cleanup.sh",
"../../scripts/common/minimize.sh"
]
}

}

0 comments on commit e10539d

Please sign in to comment.