Skip to content

Commit

Permalink
Invoke-Build script and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rajch committed Jun 7, 2022
1 parent 5bd9aea commit 533b1be
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 16 deletions.
6 changes: 3 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ The following instructions are for manual building of images. For automated buil
25. Use SSH to log on to the installation VM as kuttiadmin. Go to the **kutti-installscripts** directory and run `chmod +x *.sh`. Then, run `ln -v -s -t /usr/local/bin/ /home/kuttiadmin/kutti-installscripts/*.sh`.
26. Run `KUBE_VERSION=<version> ./setup-kubernetes.sh` to install kubernetes with containderd. Currently suppported versions are:

* 1.24\* (The '*' is important)
* 1.23*
* 1.22*
* 1.24
* 1.23
* 1.22

27. Verify that kubeadm is installed by running `kubeadm`. Verify the kubectl autocomplete works.

Expand Down
2 changes: 1 addition & 1 deletion COMPONENTS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Components

- Debian Linux v11.3.0
- containerd.io v1.6.4-1
- containerd.io v1.6.6
- kubelet, kubectl, kubeadm (appropriate versions)
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ usage:
output-kutti-base/Virtual\ Machines/box.xml: kutti.step1.pkr.hcl
packer build -var "iso-url=$(OS_ISO_PATH)" -var "iso-checksum=$(OS_ISO_CHECKSUM)" $<

output-kutti-hyperv/kutti-hyperv.vhdx: kutti.step2.pkr.hcl output-kutti-base/Virtual\ Machines/box.xml
packer build -var "vm-version=$(VERSION_STRING)" -var "vm-description=$$VM_DESCRIPTION" $<
output-kutti-hyperv/Virtual\ Hard\ Disks/kutti-base.vhdx: kutti.step2.pkr.hcl output-kutti-base/Virtual\ Machines/box.xml
packer build -var "vm-version=$(VERSION_STRING)" -var "kube-version=$KUBE_VERSION" $<

.PHONY: step1
step1: output-kutti-base/Virtual\ Machines/box.xml

.PHONY: step2
step2: output-kutti-hyperv/kutti-hyperv.vhdx
step2: output-kutti-hyperv/Virtual\ Hard\ Disks/kutti-base.vhdx

.PHONY: all
all: step1 step2

.PHONY: clean-step1
clean-step1:
rm -r output-kutti-base/
rd /s output-kutti-base

.PHONY: clean-step2
clean-step2:
rd /s output-kutti-hyperv/
rd /s output-kutti-hyperv

.PHONY: clean
clean: clean-step2 clean-step1
14 changes: 9 additions & 5 deletions PACKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ second step can be run multiple times to generate images for different versions
4. Run `packer build kutti.step1.pkr.hcl` to generate an exported VM for a bare OS image.
5. Run `packer -var "kube-version=DESIREDVERSION" kutti.step2.pkr.hcl`. Here, DESIREDVERSION is the kubernetes version, as it is published in the google debian repository for Kubernetes. If you leave out the `-var "kube-version=` part, the script will pick up the latest available Kubernetes version. Currently supported values are:

* 1.24\* (The '*' is important)
* 1.23*
* 1.22*
* 1.24
* 1.23
* 1.22

## Details

Expand Down Expand Up @@ -52,11 +52,15 @@ The second step is the script `kutti.step.pkr.hcl`. This starts from a VM import
* Adds an icon
* Exports to the final VHDX.

## Makefile
## Makefile or Invoke-Build script

The steps described above can also be performed via a supplied makefile and GNU make.
The steps described above can be performed via a supplied makefile and GNU make.
`make step1` and `make step2` can be used.

They can also be performed via the supplied build script **invoke.build.ps1** and
[Invoke-Build](https://github.com/nightroman/Invoke-Build). You can use
`Invoke-Build step1` and `Invoke-Build step1`.

## Compressing the .vhdx file

The .vhdx file produced by the second step should be renamed to **kutti-\<kubernetes version\>.vhdx**, and then compressed to a file called **kutti-\<kubernetes version\>.vhdx.zip**. **NOTE:** Do not use Windows Explorer to create the .zip file. On Windows, use 7Zip instead.
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/setup-kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ if [ "" = "${KUBE_VERSION:-}" ]; then
apt-get install -y kubelet kubeadm kubectl
else
echo "Version $KUBE_VERSION"
apt-get install -y kubelet="$KUBE_VERSION" kubeadm="$KUBE_VERSION" kubectl="$KUBE_VERSION"
apt-get install -y kubelet="$KUBE_VERSION*" kubeadm="$KUBE_VERSION*" kubectl="$KUBE_VERSION*"
fi
apt-mark hold kubelet kubeadm kubectl
echo "Done."
Expand Down
13 changes: 13 additions & 0 deletions buildscripts/stamp-kuttirelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh -eu

if [ "$(id -ur)" -ne "0" ]; then
echo "$0 can only be run as root. Use sudo."
exit 1
fi

cat > /etc/kutti-release <<EOF_RELEASESTAMP
Kutti Hyper-V Image Version: ${VM_VERSION}
Debian Linux Version: $(cat /etc/debian_version)
Containerd Version: $(containerd -v | cut -f3 -d " ")
Kubernetes Version: $(kubectl version --client -o yaml | grep "gitVersion" | cut -f2 -d ":")
EOF_RELEASESTAMP
61 changes: 61 additions & 0 deletions invoke.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Param(
$VersionMajor = (property VERSION_MAJOR 0),
$VersionMinor = (property VERSION_MINOR 1),
$BuildNumber = (property BUILD_NUMBER 0),
$PatchString = (property PATCH_NUMBER ""),
$OSISOPath = (property OS_ISO_PATH "iso/debian-11.3.0-amd64-netinst.iso"),
$OSISOChecksum = (property OS_ISO_CHECKSUM "md5:e7a5a4fc5804ae65f7487e68422368ad"),
$KubeVersion = (property KUBE_VERSION "")
)

$VersionString = "$($VersionMajor).$($VersionMinor).$($BuildNumber)$($PatchString)"
If ($KubeVersion -eq "") {
$KubeVersionDescription = "latest"
} Else {
$KubeVersionDescription = $KubeVersion
}


$VMDescription = @"
Kutti Hyper-V Image version: $($VersionString)
Debian base image: $($OSISOPath)
Kubernetes version: $($KubeVersionDescription)
"@

# Synopsis: Show usage
task . {
Write-Host "Usage: Invoke-Build step1|step2|clean-step1|clean-step2|clean"
}

# Synopsis: Build debian base image
task step1 -Outputs "output-kutti-base/Virtual Machines/box.xml" -Inputs kutti.step1.pkr.hcl {
exec {
packer build -var "iso-url=$($OSISOPath)" -var "iso-checksum=$($OSISOChecksum)" $Inputs
}
}

# Synopsis: Build kutti image
task step2 -Outputs "output-kutti-hyperv/Virtual Hard Disks/kutti-base.vhdx" -Inputs kutti.step2.pkr.hcl, "output-kutti-base/Virtual Machines/box.xml" {
Write-Host "Building..."
Write-Host $VMDescription
exec {
packer build -var "vm-version=$($VersionString)" -var "kube-version=$($KubeVersion)" kutti.step2.pkr.hcl
}
}

# Synopsis: Build everything
task all step1, step2

# Synopsis: Delete built debian base image
task clean-step1 {
Remove-Item -Recurse -Force output-kutti-base
}

# Synopsis: Delete built kutti image
task clean-step2 {
Remove-Item -Recurse -Force output-kutti-hyperv
}

# Synopsis: Delete all output
task clean clean-step2, clean-step1
12 changes: 11 additions & 1 deletion kutti.step2.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ variable "vm-description" {
source "hyperv-vmcx" "kutti-hyperv" {
clone_from_vmcx_path="output-kutti-base"

headless = "true"

ssh_username = "kuttiadmin"
ssh_password = "Pass@word1"
ssh_timeout = "20m"
Expand All @@ -28,7 +30,6 @@ source "hyperv-vmcx" "kutti-hyperv" {
disk_block_size = "1"
generation = "1"

# The output file should be called kutti-hyperv.vhdx
vm_name = "kutti-hyperv"

switch_name = "Default Switch"
Expand Down Expand Up @@ -89,16 +90,25 @@ build {
# * makes them executable
# * makes symbolic links in /usr/local/bin.
# The cleanup script removes unneeded stuff.
# The stamp-kuttirelease script creates a
# file /etc/kutti-release, which contains
# the versions of the components.
# The pre-compact script fills the VM hard
# disk with zeroes, and the deletes the file.
# This allows Hyper-V to compact the disk.
scripts = [
"buildscripts/process-scripts.sh",
"buildscripts/cleanup.sh",
"buildscripts/stamp-kuttirelease.sh",
"buildscripts/pre-compact.sh"
]
# These scripts must be run with sudo access
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"

# Ensure the VM_VERSION variable.
environment_vars = [
"VM_VERSION=${ var.vm-version }"
]

}
}

0 comments on commit 533b1be

Please sign in to comment.