Skip to content

Commit

Permalink
Refactor rocky8 (#201)
Browse files Browse the repository at this point in the history
Relates to #197 

Remove reliance on make when building the Rocky 8 image.
  • Loading branch information
GR360RY authored Feb 1, 2024
1 parent 8df6b78 commit 5b9b16b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
5 changes: 3 additions & 2 deletions centos7/centos7.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ build {

post-processor "shell-local" {
inline = [
"SOURCE=centos7",
"SOURCE=${source.name}",
"OUTPUT=${var.filename}",
"source ../scripts/fuse-nbd",
"source ../scripts/fuse-tar-root"
"source ../scripts/fuse-tar-root",
"rm -rf output-${source.name}",
]
inline_shebang = "/bin/bash -e"
}
Expand Down
11 changes: 3 additions & 8 deletions rocky8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ include ../scripts/check.mk
PACKER ?= packer
PACKER_LOG ?= 0

export PACKER_LOG KS_PROXY
export PACKER_LOG

.PHONY: all clean

all: rocky8.tar.gz

$(eval $(call check_packages_deps))

rocky8.tar.gz: check-deps clean http/rocky.ks
rocky8.tar.gz: check-deps clean
${PACKER} init rocky8.pkr.hcl && ${PACKER} build rocky8.pkr.hcl

http/rocky.ks: http/rocky.ks.in
envsubst '$${KS_PROXY}' < $< | tee $@

clean:
${RM} -rf output-rocky8 rocky8.tar.gz http/rocky.ks

.INTERMEDIATE: http/rocky.ks
${RM} -rf output-rocky8 rocky8.tar.gz
11 changes: 10 additions & 1 deletion rocky8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ The Packer template downloads the Rocky ISO image from the Internet. You can tel
To use a proxy during the installation define the `KS_PROXY` variable in the environment, as bellow:

```shell
export KS_PROXY="--proxy=\"${HTTP_PROXY}\""
export KS_PROXY="\"${HTTP_PROXY}\""
```

# Building the image using a kickstart mirror

To tell Packer to use a specific mirror set the `KS_MIRROR` environment variable
poiniting to the mirror URL.

```shell
export KS_MIRROR="https://dl.rockylinux.org/pub/rocky/8"
```

## Building an image
Expand Down
7 changes: 3 additions & 4 deletions rocky8/http/rocky.ks.in → rocky8/http/rocky8.ks.pkrtpl.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
url --url="https://download.rockylinux.org/pub/rocky/8/BaseOS/x86_64/os/" ${KS_PROXY}
url --mirrorlist="http://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-8" ${KS_PROXY}
repo --name="AppStream" --mirrorlist="https://mirrors.rockylinux.org/mirrorlist?release=8&arch=x86_64&repo=AppStream-8" ${KS_PROXY}
repo --name="Extras" --mirrorlist="https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=extras-8" ${KS_PROXY}
url ${KS_OS_REPOS} ${KS_PROXY}
repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY}
repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY}

eula --agreed

Expand Down
56 changes: 52 additions & 4 deletions rocky8/rocky8.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,77 @@ variable "rocky_sha256sum_url" {
default = "http://download.rockylinux.org/pub/rocky/8/isos/x86_64/CHECKSUM"
}

# use can use "--url" to specify the exact url for os repo
# for ex. "--url='https://dl.rockylinux.org/pub/rocky/8/BaseOS/x86_64/os'"
variable "ks_os_repos" {
type = string
default = "--mirrorlist='http://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=BaseOS-8'"
}

# Use --baseurl to specify the exact url for appstream repo
# for ex. "--baseurl='https://dl.rockylinux.org/pub/rocky/8/AppStream/x86_64/os'"
variable "ks_appstream_repos" {
type = string
default = "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?release=8&arch=x86_64&repo=AppStream-8'"
}

# Use --baseurl to specify the exact url for extras repo
# for ex. "--baseurl='https://dl.rockylinux.org/pub/rocky/8/extras/x86_64/os'"
variable "ks_extras_repos" {
type = string
default = "--mirrorlist='https://mirrors.rockylinux.org/mirrorlist?arch=x86_64&repo=extras-8'"
}

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

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

locals {
ks_proxy = var.ks_proxy != "" ? "--proxy=${var.ks_proxy}" : ""
ks_os_repos = var.ks_mirror != "" ? "--url=${var.ks_mirror}/BaseOS/x86_64/os" : var.ks_os_repos
ks_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/x86_64/os" : var.ks_appstream_repos
ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64/os" : var.ks_extras_repos
}

source "qemu" "rocky8" {
boot_command = ["<up><tab> ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rocky.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_command = ["<up><tab> ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/rocky8.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_wait = "3s"
communicator = "none"
disk_size = "4G"
headless = true
http_directory = "http"
iso_checksum = "file:${var.rocky_sha256sum_url}"
iso_url = var.rocky_iso_url
memory = 2048
qemuargs = [["-serial", "stdio"]]
shutdown_timeout = "1h"
http_content = {
"/rocky8.ks" = templatefile("${path.root}/http/rocky8.ks.pkrtpl.hcl",
{
KS_PROXY = local.ks_proxy,
KS_OS_REPOS = local.ks_os_repos,
KS_APPSTREAM_REPOS = local.ks_appstream_repos,
KS_EXTRAS_REPOS = local.ks_extras_repos
}
)
}
}

build {
sources = ["source.qemu.rocky8"]

post-processor "shell-local" {
inline = [
"SOURCE=rocky8",
"SOURCE=${source.name}",
"OUTPUT=${var.filename}",
"source ../scripts/fuse-nbd",
"source ../scripts/fuse-tar-root"
"source ../scripts/fuse-tar-root",
"rm -rf output-${source.name}",
]
inline_shebang = "/bin/bash -e"
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/fuse-tar-root
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if [ "${DETECT_BLS_BOOT}" -eq 1 ]; then
fi
fi

gzip --best "${TARFILE}"
gzip --best --force "${TARFILE}"

if [ -n "$MANIFEST" ]; then
echo "Creating manifest..."
Expand Down

0 comments on commit 5b9b16b

Please sign in to comment.