Skip to content

Commit

Permalink
Convert AM packer templates into HCL2
Browse files Browse the repository at this point in the history
* Convert Ubuntu 20.04 base image template into HCL2
* Clean up Ubuntu 20.04 base template variables
* Convert AM image template into HCL2
* Clean up AM image template variables
  • Loading branch information
replaceafill authored Jan 28, 2025
1 parent fac6e5b commit f2fe347
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 170 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/vagrant-box-archivematica.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,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-${{ matrix.ubuntu-version }}-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 Expand Up @@ -85,15 +81,11 @@ jobs:
run: |
sudo mkdir -p /etc/vbox/
echo "* 10.10.10.20/24" | sudo tee -a /etc/vbox/networks.conf
- 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-box-archivematica
packer build -on-error=abort template.json
packer init template.json.pkr.hcl
packer build -on-error=abort template.json.pkr.hcl
mv ${{ github.workspace }}/packer/builds/virtualbox/vagrant-am.box \
${{ github.workspace }}/archivematica-vagrant-${{ github.event.inputs.version }}.box
- name: Provision a test VM with the new image
Expand Down
110 changes: 0 additions & 110 deletions packer/templates/vagrant-base-ubuntu-20.04-amd64/template.json

This file was deleted.

133 changes: 133 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,133 @@
packer {
required_plugins {
virtualbox = {
source = "github.com/hashicorp/virtualbox"
version = "~> 1"
}
}
}

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

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

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 "memory" {
type = string
default = "4096"
}

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

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

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_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"
]
}

}
48 changes: 0 additions & 48 deletions packer/templates/vagrant-box-archivematica/template.json

This file was deleted.

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

source "virtualbox-ovf" "ubuntu" {
headless = "true"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
source_path = "../../builds/virtualbox/vagrant-base-ubuntu-20.04-amd64/vagrant-base-ubuntu-20.04-amd64.ovf"
ssh_password = "vagrant"
ssh_username = "vagrant"
ssh_wait_timeout = "30s"
}

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

provisioner "shell" {
execute_command = "echo 'vagrant'|{{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = [
"../../scripts/ubuntu/ansible-focal.sh"
]
}

provisioner "ansible-local" {
galaxy_file = "requirements.yml"
group_vars = "./provisioning/group_vars/"
inventory_groups = [
"servers"
]
playbook_file = "./provisioning/singlenode.yml"
}

provisioner "shell" {
execute_command = "echo 'vagrant'|{{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = [
"./motd.sh",
"../../scripts/ubuntu/cleanup.sh",
"../../scripts/common/minimize.sh"
]
}

post-processor "vagrant" {
output = "../../builds/{{ .Provider }}/vagrant-am.box"
vagrantfile_template = "./Vagrantfile"
}
}

0 comments on commit f2fe347

Please sign in to comment.