Skip to content

Commit

Permalink
Use packer templatefile (#211)
Browse files Browse the repository at this point in the history
fixes #188, #197
  • Loading branch information
alexsander-souza authored Feb 23, 2024
1 parent 3b02dc4 commit 0ca4de9
Show file tree
Hide file tree
Showing 43 changed files with 653 additions and 295 deletions.
11 changes: 3 additions & 8 deletions centos6/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: centos6.tar.gz

$(eval $(call check_packages_deps))

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

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

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

.INTERMEDIATE: http/centos6.ks
${RM} -rf output-centos6 centos6.tar.gz
2 changes: 1 addition & 1 deletion centos6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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 an image
Expand Down
66 changes: 63 additions & 3 deletions centos6/centos6.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,89 @@ variable "centos6_sha256sum_url" {
default = "https://mirrors.edge.kernel.org/centos/6.10/isos/x86_64/sha256sum.txt"
}

# use can use "--url" to specify the exact url for os repo
variable "ks_os_repos" {
type = string
default = "--url='http://mirror.centos.org/centos/6/os/x86_64'"
}

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

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

# Use --baseurl to specify the exact url for EPEL6 repo
variable "ks_epel6_repos" {
type = string
default = "--mirrorlist='https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64'"
}

# Use --baseurl to specify the exact url for EPEL6 repo
variable "ks_cloudinit_repos" {
type = string
default = "--baseurl='http://copr-be.cloud.fedoraproject.org/results/@cloud-init/el-stable/epel-6-x86_64'"
}

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" "centos6" {
boot_command = ["<tab> ", "ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos6.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_wait = "3s"
communicator = "none"
disk_size = "4G"
headless = true
http_directory = "http"
iso_checksum = "file:${var.centos6_sha256sum_url}"
iso_url = var.centos6_iso_url
memory = 2048
qemuargs = [["-serial", "stdio"]]
shutdown_timeout = "1h"
http_content = {
"/centos6.ks" = templatefile("${path.root}/http/centos6.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
KS_EPEL6_REPOS = var.ks_epel6_repos
KS_CLOUDINIT_REPOS = var.ks_cloudinit_repos
}
)
}

}

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

post-processor "shell-local" {
inline = [
"SOURCE=centos6",
"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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
url --url="http://mirror.centos.org/centos/6/os/x86_64" ${KS_PROXY}
url ${KS_OS_REPOS} ${KS_PROXY}
poweroff
firewall --enabled --service=ssh
firstboot --disable
Expand All @@ -12,17 +12,17 @@ timezone UTC --isUtc
bootloader --location=mbr --driveorder="vda" --timeout=1
rootpw --plaintext password

repo --name="Updates" --mirrorlist="http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=updates" ${KS_PROXY}
repo --name="Extras" --mirrorlist="http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=extras" ${KS_PROXY}
repo --name="EPEL6" --mirrorlist="https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64" ${KS_PROXY}
repo --name="Updates" ${KS_UPDATES_REPOS} ${KS_PROXY}
repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY}
repo --name="EPEL6" ${KS_EPEL6_REPOS} ${KS_PROXY}
# CentOS 6 requires a newer version of cloud-init to use advanced features with MAAS.
repo --name="cloud-init" --baseurl="http://copr-be.cloud.fedoraproject.org/results/@cloud-init/el-stable/epel-6-x86_64" ${KS_PROXY}
repo --name="cloud-init" ${KS_CLOUDINIT_REPOS} ${KS_PROXY}

zerombr
clearpart --all --initlabel
part / --size=1 --grow --asprimary --fstype=ext4

%post --erroronfai
%post --erroronfail
# workaround anaconda requirements and clear root password
passwd -d root
passwd -l root
Expand Down
11 changes: 3 additions & 8 deletions centos8-stream/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: centos8-stream.tar.gz

$(eval $(call check_packages_deps))

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

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

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

.INTERMEDIATE: http/centos8-stream.ks
${RM} -rf output-centos8-stream centos8-stream.tar.gz
2 changes: 1 addition & 1 deletion centos8-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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 an image
Expand Down
52 changes: 49 additions & 3 deletions centos8-stream/centos8-stream.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,75 @@ variable "centos8_stream_sha256sum_url" {
default = "https://mirrors.edge.kernel.org/centos/8-stream/isos/x86_64/CHECKSUM"
}

# use can use "--url" to specify the exact url for os repo
variable "ks_os_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=BaseOS'"
}

# Use --baseurl to specify the exact url for AppStream repo
variable "ks_appstream_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=AppStream'"
}

# Use --baseurl to specify the exact url for extras repo
variable "ks_extras_repos" {
type = string
default = "--mirrorlist='http://mirrorlist.centos.org/?release=8-stream&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_appstream_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/AppStream/x86_64" : var.ks_appstream_repos
ks_extras_repos = var.ks_mirror != "" ? "--baseurl=${var.ks_mirror}/extras/x86_64" : var.ks_extras_repos
}

source "qemu" "centos8-stream" {
boot_command = ["<up><tab> ", "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos8-stream.ks ", "console=ttyS0 inst.cmdline", "<enter>"]
boot_wait = "3s"
communicator = "none"
disk_size = "4G"
headless = true
http_directory = "http"
iso_checksum = "file:${var.centos8_stream_sha256sum_url}"
iso_url = var.centos8_stream_iso_url
memory = 2048
qemuargs = [["-serial", "stdio"]]
shutdown_timeout = "1h"
http_content = {
"/centos8-stream.ks" = templatefile("${path.root}/http/centos8-stream.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.centos8-stream"]

post-processor "shell-local" {
inline = [
"SOURCE=centos8-stream",
"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
71 changes: 0 additions & 71 deletions centos8-stream/http/centos8-stream.ks.in

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
url --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=BaseOS" ${KS_PROXY}
url ${KS_OS_REPOS} ${KS_PROXY}
poweroff
firewall --enabled --service=ssh
firstboot --disable
Expand All @@ -12,8 +12,8 @@ timezone UTC --isUtc
bootloader --location=mbr --driveorder="vda" --timeout=1
rootpw --plaintext password

repo --name="AppStream" --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=AppStream" ${KS_PROXY}
repo --name="Extras" --mirrorlist="${KS_MIRROR}/?release=8&arch=x86_64&repo=extras" ${KS_PROXY}
repo --name="AppStream" ${KS_APPSTREAM_REPOS} ${KS_PROXY}
repo --name="Extras" ${KS_EXTRAS_REPOS} ${KS_PROXY}

zerombr
clearpart --all --initlabel
Expand Down
11 changes: 3 additions & 8 deletions centos8/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
KS_MIRROR ?= http://mirrorlist.centos.org
export PACKER_LOG KS_PROXY KS_MIRROR
export PACKER_LOG

.PHONY: all clean

all: centos8.tar.gz

$(eval $(call check_packages_deps))

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

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

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

.INTERMEDIATE: http/centos8.ks
${RM} -rf output-centos8 centos8.tar.gz
2 changes: 1 addition & 1 deletion centos8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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 an image
Expand Down
Loading

0 comments on commit 0ca4de9

Please sign in to comment.