Skip to content

Commit

Permalink
Add packer files for NGF image
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Aug 5, 2024
1 parent 85c43b0 commit 7e47994
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -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=<PROJECT_ID>' -var 'builder_sa=<BUILDER_SA>' build.pkr.hcl
```
68 changes: 68 additions & 0 deletions tools/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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",
]
}

}
13 changes: 13 additions & 0 deletions tools/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> {} }:

[
pkgs.gh
pkgs.git
pkgs.gnumake
pkgs.gnuplot
pkgs.go
pkgs.kubectl
pkgs.kubernetes-helm
pkgs.rsync
pkgs.wrk
]

0 comments on commit 7e47994

Please sign in to comment.