diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..bf22d58 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,11 @@ +# Tools + +This directory contains the source code used to generate the VM image used in NGF tests. + +## Building the VM image + +To build the VM image, run the following command: + +```bash +packer build -var 'project_id=' -var 'builder_sa=' build.pkr.hcl +``` diff --git a/tools/build.pkr.hcl b/tools/build.pkr.hcl new file mode 100644 index 0000000..7e684ca --- /dev/null +++ b/tools/build.pkr.hcl @@ -0,0 +1,67 @@ +packer { + required_plugins { + googlecompute = { + source = "github.com/hashicorp/googlecompute" + version = "1.1.3" + } + } +} + +variable "project_id" { + type = string +} + +variable "builder_sa" { + type = string +} + +source "googlecompute" "ngf-image" { + project_id = var.project_id + source_image_family = "debian-12" + zone = "us-west1-a" + image_description = "Debian VM for NGF testing" + ssh_username = "username" + tags = ["test-packer"] + impersonate_service_account = var.builder_sa + image_name = "ngf-debian-12-{{timestamp}}" + image_family = "ngf-debian" + machine_type = "n2-standard-4" +} + +build { + sources = ["sources.googlecompute.ngf-image"] + + provisioner "shell" { + inline = [ + "curl -L https://nixos.org/nix/install -o install-nix.sh", + "chmod +x install-nix.sh", + "bash install-nix.sh --daemon", + "rm install-nix.sh", + "sed -i '1i. /etc/bashrc' ~/.bashrc" + ] + } + + provisioner "file" { + source = "packages.nix" + destination = "/tmp/packages.nix" + + } + provisioner "shell" { + inline = [ + "nix-env -if /tmp/packages.nix", + "sudo apt-get update", + "sudo apt-get install -y --no-install-recommends --no-install-suggests google-cloud-sdk-gke-gcloud-auth-plugin locales", + "echo 'en_US.UTF-8 UTF-8' | sudo tee /etc/locale.gen", + "sudo locale-gen", + ] + } + + provisioner "shell" { + inline = [ + "git clone https://github.com/nginxinc/nginx-gateway-fabric.git", + "cd nginx-gateway-fabric/tests", + "go mod download", + ] + } + +} diff --git a/tools/packages.nix b/tools/packages.nix new file mode 100644 index 0000000..4038e6d --- /dev/null +++ b/tools/packages.nix @@ -0,0 +1,13 @@ +{ pkgs ? import {} }: + +[ + pkgs.gh + pkgs.gnumake + pkgs.gnuplot + pkgs.go + pkgs.kubectl + pkgs.kubernetes-helm + pkgs.rsync + pkgs.wrk + pkgs.git +]