Skip to content

Commit

Permalink
Refactor centos7 packer template (#198)
Browse files Browse the repository at this point in the history
Refactor CentOS 7 Packer templates.

Relates to #197.
  • Loading branch information
GR360RY authored Jan 29, 2024
1 parent ef85e2d commit 58a6560
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
21 changes: 3 additions & 18 deletions centos7/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,16 @@ include ../scripts/check.mk
PACKER ?= packer
PACKER_LOG ?= 0

ifneq (${KS_MIRROR},)
KS_OS_REPOS := --url="${KS_MIRROR}/os/x86_64"
KS_UPDATES_REPOS := --baseurl="${KS_MIRROR}/updates/x86_64"
KS_EXTRA_REPOS := --baseurl="${KS_MIRROR}/extras/x86_64"
else
KS_OS_REPOS := --mirrorlist="http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os"
KS_UPDATES_REPOS := --mirrorlist="http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates"
KS_EXTRA_REPOS := --mirrorlist="http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras"
endif

export PACKER_LOG KS_PROXY KS_OS_REPOS KS_UPDATES_REPOS KS_EXTRA_REPOS
export PACKER_LOG

.PHONY: all clean check-deps

all: centos7.tar.gz

$(eval $(call check_packages_deps))

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

http/centos7.ks: http/centos7.ks.in
envsubst '$${KS_PROXY} $${KS_OS_REPOS} $${KS_UPDATES_REPOS} $${KS_EXTRA_REPOS}' < $< | tee $@

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

.INTERMEDIATE: http/centos7.ks
${RM} -rf output-centos7 centos7.tar.gz
11 changes: 10 additions & 1 deletion centos7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ 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://archive.kernel.org/centos-vault/7.9.2009"
```

## Building an image
Expand Down
50 changes: 49 additions & 1 deletion centos7/centos7.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,66 @@ variable "centos7_sha256sum_url" {
default = "https://mirrors.edge.kernel.org/centos/7/isos/x86_64/sha256sum.txt"
}

# use can use "--url" to specify the exact url for os repo
# for ex. "--url='https://archive.kernel.org/centos-vault/7.9.2009/os/x86_64'"
variable "ks_os_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os'"
}

# Use --baseurl to specify the exact url for updates repo
# for ex. "--baseurl='https://archive.kernel.org/centos-vault/7.9.2009/updates/x86_64'"
variable "ks_updates_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates'"
}

# Use --baseurl to specify the exact url for extras repo
# for ex. "--baseurl='https://archive.kernel.org/centos-vault/7.9.2009/extras/x86_64'"
variable "ks_extras_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras'"
}

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}/os/x86_64" : var.ks_os_repos
ks_updates_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/updates/x86_64" : var.ks_updates_repos
ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64" : var.ks_extras_repos
}

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

}

build {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bootloader --location=mbr --driveorder="vda" --timeout=1
rootpw --plaintext password

repo --name="Updates" ${KS_UPDATES_REPOS} ${KS_PROXY}
repo --name="Extras" ${KS_EXTRA_REPOS} ${KS_PROXY}
repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY}

zerombr
clearpart --all --initlabel
Expand Down

0 comments on commit 58a6560

Please sign in to comment.