Skip to content

Commit

Permalink
PR For Issue 157 (#158)
Browse files Browse the repository at this point in the history
- Added support for SERIES, URL, SUMS and ISO Makefile parameters.
- Moved flat and lvm variables into their own files. 
- Updated README.md to reflect these changes.

Resolves: #157
  • Loading branch information
alanbach authored Nov 8, 2023
1 parent f96da99 commit 0fe47d1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
17 changes: 13 additions & 4 deletions ubuntu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ PACKER ?= packer
PACKER_LOG ?= 0
export PACKER_LOG

SERIES ?= jammy
URL ?= http://releases.ubuntu.com
SUMS ?= SHA256SUMS

ISO=$(shell wget -O- -q ${URL}/${SERIES}/${SUMS} | grep live-server | cut -d'*' -f2)

.PHONY: all clean

all: custom-cloudimg.tar.gz
Expand All @@ -29,15 +35,18 @@ OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd
cp -v $< $@

custom-cloudimg.tar.gz: check-deps clean
${PACKER} init . && ${PACKER} build -only='cloudimg.*' .
${PACKER} init . && ${PACKER} build -only='cloudimg.*' -var ubuntu_series=${SERIES} .

custom-ubuntu.tar.gz: check-deps clean seeds-flat.iso OVMF_VARS.fd \
packages/custom-packages.tar.gz
${PACKER} init . && ${PACKER} build -only=qemu.flat .
${PACKER} init . && ${PACKER} build -only=qemu.flat \
-var ubuntu_series=${SERIES} \
-var ubuntu_iso=${ISO} .

custom-ubuntu-lvm.dd.gz: check-deps clean seeds-lvm.iso OVMF_VARS.fd
${PACKER} init . && ${PACKER} build -only=qemu.lvm .

${PACKER} init . && ${PACKER} build -only=qemu.lvm \
-var ubuntu_series=${SERIES} \
-var ubuntu_lvm_iso=${ISO} .
clean:
${RM} -rf output-* custom-*.gz \
seeds-flat.iso seeds-lvm.iso seeds-cloudimg.iso \
Expand Down
14 changes: 14 additions & 0 deletions ubuntu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ Note: ubuntu-lvm.pkr.hcl and ubuntu-flat.pkr.hcl are configured to run Packer in

Installation is non-interactive. Note that the installation will attempt an SSH connection to the QEMU VM where the newly-built image is being booted. This is the final provisioning step in the process. Packer uses SSH to discover that the image has, in fact, booted, so there may be a number of failed tries -- over 3-5 minutes -- until the connection is successful. This is normal behavior for packer.

### Makefile Parameters

#### PACKER_LOG
Enable (1) or Disable (0) verbose packer logs. The default value is set to 0.

#### SERIES
Specify the Ubuntu Series to build. The default value is set to Jammy.

#### URL
The URL prefix for mirror that is hosting the ISO images for a given series. The default value is set to http://releases.ubuntu.com. ISO images are expected to be under URL/SERIES/.

#### SUMS
The file name for the checksums file. The default value is set to SHA256SUMS.

### Default Username

The default username is ```ubuntu```
Expand Down
14 changes: 4 additions & 10 deletions ubuntu/ubuntu-flat.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
variable "flat_filename" {
type = string
default = "custom-ubuntu.tar.gz"
description = "The filename of the tarball to produce"
}

source "qemu" "flat" {
boot_command = ["<wait>e<wait5>", "<down><wait><down><wait><down><wait2><end><wait5>", "<bs><bs><bs><bs><wait>autoinstall ---<wait><f10>"]
boot_wait = "2s"
Expand All @@ -12,9 +6,9 @@ source "qemu" "flat" {
format = "raw"
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"
iso_checksum = "file:http://releases.ubuntu.com/${var.ubuntu_series}/SHA256SUMS"
iso_target_path = "packer_cache/${var.ubuntu_series}.iso"
iso_url = "https://releases.ubuntu.com/${var.ubuntu_series}/${var.ubuntu_iso}"
memory = 2048
qemuargs = [
["-vga", "qxl"],
Expand All @@ -25,7 +19,7 @@ source "qemu" "flat" {
["-drive", "if=pflash,format=raw,file=OVMF_VARS.fd"],
["-drive", "file=output-flat/packer-flat,if=none,id=drive0,cache=writeback,discard=ignore,format=raw"],
["-drive", "file=seeds-flat.iso,format=raw,cache=none,if=none,id=drive1,readonly=on"],
["-drive", "file=packer_cache/ubuntu.iso,if=none,id=cdrom0,media=cdrom"]
["-drive", "file=packer_cache/${var.ubuntu_series}.iso,if=none,id=cdrom0,media=cdrom"]
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
Expand Down
12 changes: 12 additions & 0 deletions ubuntu/ubuntu-flat.variables.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
variable "flat_filename" {
type = string
default = "custom-ubuntu.tar.gz"
description = "The filename of the tarball to produce"
}

variable "ubuntu_iso" {
type = string
default = "ubuntu-22.04.3-live-server-amd64.iso"
description = "The ISO name to build the image from"
}

8 changes: 4 additions & 4 deletions ubuntu/ubuntu-lvm.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ source "qemu" "lvm" {
format = "raw"
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"
iso_checksum = "file:http://releases.ubuntu.com/${var.ubuntu_series}/SHA256SUMS"
iso_target_path = "packer_cache/${var.ubuntu_series}.iso"
iso_url = "https://releases.ubuntu.com/${var.ubuntu_series}/${var.ubuntu_lvm_iso}"
memory = 2048
qemuargs = [
["-vga", "qxl"],
Expand All @@ -19,7 +19,7 @@ source "qemu" "lvm" {
["-drive", "if=pflash,format=raw,file=OVMF_VARS.fd"],
["-drive", "file=output-lvm/packer-lvm,if=none,id=drive0,cache=writeback,discard=ignore,format=raw"],
["-drive", "file=seeds-lvm.iso,format=raw,cache=none,if=none,id=drive1,readonly=on"],
["-drive", "file=packer_cache/ubuntu.iso,if=none,id=cdrom0,media=cdrom"]
["-drive", "file=packer_cache/${var.ubuntu_series}.iso,if=none,id=cdrom0,media=cdrom"]
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
Expand Down
6 changes: 6 additions & 0 deletions ubuntu/ubuntu-lvm.variables.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
variable "ubuntu_lvm_iso" {
type = string
default = "ubuntu-22.04.3-live-server-amd64.iso"
description = "The ISO name to build the image from"
}

0 comments on commit 0fe47d1

Please sign in to comment.