Skip to content

Commit

Permalink
Switch build to debian (still build ubuntu alongside) (#426)
Browse files Browse the repository at this point in the history
* Try debian base image

* bookworm

* fix docker install

* try debian 11

* disable cloud-init wait

* new packer

* build debian12 alongside ubuntu

* packer fmt

* fix typo
  • Loading branch information
alexmasi authored Oct 5, 2023
1 parent 2966f93 commit 977f0c0
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 17 deletions.
30 changes: 15 additions & 15 deletions cloudbuild/internal.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
packer {
required_plugins {
googlecompute = {
version = ">= 1.1.1"
source = "github.com/hashicorp/googlecompute"
}
}
}

variable "short_sha" {
type = string
}
Expand All @@ -17,7 +26,7 @@ variable "zone" {

source "googlecompute" "kne-image" {
project_id = "gep-kne"
source_image_family = "ubuntu-2004-lts"
source_image_family = "debian-12"
disk_size = 50
image_name = "kne-${var.build_id}"
image_family = "kne-untested"
Expand All @@ -26,7 +35,7 @@ source "googlecompute" "kne-image" {
"kne_gh_branch_name" : "${var.branch_name}",
"cloud_build_id" : "${var.build_id}",
}
image_description = "Ubuntu based linux VM image with KNE and all internal dependencies installed."
image_description = "Debian based linux VM image with KNE and all internal dependencies installed."
ssh_username = "user"
machine_type = "e2-medium"
zone = "${var.zone}"
Expand All @@ -40,14 +49,6 @@ build {
name = "kne-builder"
sources = ["sources.googlecompute.kne-image"]

provisioner "shell" {
inline = [
"echo Waiting for initial updates...",
"/usr/bin/cloud-init status --wait",
"sleep 60",
]
}

provisioner "shell" {
inline = [
"echo Installing golang...",
Expand All @@ -65,15 +66,15 @@ build {
"echo Installing docker...",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
"sudo apt-get -o DPkg::Lock::Timeout=60 install apt-transport-https ca-certificates curl gnupg lsb-release -y",
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
"echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
"curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
"echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
"sudo apt-get -o DPkg::Lock::Timeout=60 install docker-ce docker-ce-cli containerd.io build-essential -y",
"sudo usermod -aG docker $USER",
"sudo docker version",
"sudo apt-get -o DPkg::Lock::Timeout=60 install openvswitch-switch-dpdk -y", # install openvswitch for cisco containers
"echo \"fs.inotify.max_user_instances=64000\" | sudo tee -a /etc/sysctl.conf", # configure inotify for cisco containers
"echo \"kernel.pid_max=1048575\" | sudo tee -a /etc/sysctl.conf", # configure pid_max for cisco containers
"echo \"fs.inotify.max_user_instances=64000\" | sudo tee -a /etc/sysctl.conf", # configure inotify for cisco xrd containers
"echo \"kernel.pid_max=1048575\" | sudo tee -a /etc/sysctl.conf", # configure pid_max for cisco 8000e containers
"sudo sysctl -p",
"echo Pulling containers...",
"gcloud auth configure-docker us-west1-docker.pkg.dev -q", # configure sudoless docker
Expand All @@ -89,7 +90,6 @@ build {
provisioner "shell" {
inline = [
"echo Installing kubectl...",
"sudo mkdir /etc/apt/keyrings -m 755",
"curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg",
"echo \"deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main\" | sudo tee /etc/apt/sources.list.d/kubernetes.list",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
Expand Down
177 changes: 177 additions & 0 deletions cloudbuild/internal_ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
packer {
required_plugins {
googlecompute = {
version = ">= 1.1.1"
source = "github.com/hashicorp/googlecompute"
}
}
}

variable "short_sha" {
type = string
}

variable "branch_name" {
type = string
}

variable "build_id" {
type = string
}

variable "zone" {
type = string
default = "us-central1-b"
}

source "googlecompute" "kne-image" {
project_id = "gep-kne"
source_image_family = "ubuntu-2004-lts"
disk_size = 50
image_name = "kne-ubuntu-${var.build_id}"
image_family = "kne-ubuntu-untested"
image_labels = {
"kne_gh_commit_sha" : "${var.short_sha}",
"kne_gh_branch_name" : "${var.branch_name}",
"cloud_build_id" : "${var.build_id}",
}
image_description = "Ubuntu based linux VM image with KNE and all internal dependencies installed."
ssh_username = "user"
machine_type = "e2-medium"
zone = "${var.zone}"
service_account_email = "packer@gep-kne.iam.gserviceaccount.com"
use_internal_ip = true
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
state_timeout = "15m"
}

build {
name = "kne-builder"
sources = ["sources.googlecompute.kne-image"]

provisioner "shell" {
inline = [
"echo Waiting for initial updates...",
"/usr/bin/cloud-init status --wait",
"sleep 60",
]
}

provisioner "shell" {
inline = [
"echo Installing golang...",
"curl -O https://dl.google.com/go/go1.20.1.linux-amd64.tar.gz",
"sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.20.1.linux-amd64.tar.gz",
"rm go1.20.1.linux-amd64.tar.gz",
"echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc",
"echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.bashrc",
"/usr/local/go/bin/go version",
]
}

provisioner "shell" {
inline = [
"echo Installing docker...",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
"sudo apt-get -o DPkg::Lock::Timeout=60 install apt-transport-https ca-certificates curl gnupg lsb-release -y",
"curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
"echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
"sudo apt-get -o DPkg::Lock::Timeout=60 install docker-ce docker-ce-cli containerd.io build-essential -y",
"sudo usermod -aG docker $USER",
"sudo docker version",
"sudo apt-get -o DPkg::Lock::Timeout=60 install openvswitch-switch-dpdk -y", # install openvswitch for cisco containers
"echo \"fs.inotify.max_user_instances=64000\" | sudo tee -a /etc/sysctl.conf", # configure inotify for cisco xrd containers
"echo \"kernel.pid_max=1048575\" | sudo tee -a /etc/sysctl.conf", # configure pid_max for cisco 8000e containers
"sudo sysctl -p",
"echo Pulling containers...",
"gcloud auth configure-docker us-west1-docker.pkg.dev -q", # configure sudoless docker
"sudo gcloud auth configure-docker us-west1-docker.pkg.dev -q", # configure docker with sudo
"sudo docker pull us-west1-docker.pkg.dev/gep-kne/arista/ceos:ga",
"sudo docker pull us-west1-docker.pkg.dev/gep-kne/cisco/xrd:ga",
"sudo docker pull us-west1-docker.pkg.dev/gep-kne/cisco/8000e:ga",
"sudo docker pull us-west1-docker.pkg.dev/gep-kne/juniper/cptx:ga",
"sudo docker pull us-west1-docker.pkg.dev/gep-kne/nokia/srlinux:ga",
]
}

provisioner "shell" {
inline = [
"echo Installing kubectl...",
"sudo mkdir /etc/apt/keyrings -m 755",
"curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg",
"echo \"deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main\" | sudo tee /etc/apt/sources.list.d/kubernetes.list",
"sudo apt-get -o DPkg::Lock::Timeout=60 update",
"sudo apt-get -o DPkg::Lock::Timeout=60 install kubelet kubeadm kubectl -y",
"kubectl version --client",
]
}

provisioner "shell" {
inline = [
"echo Installing multinode cluster dependencies...",
"git clone https://github.com/flannel-io/flannel.git",
"git clone https://github.com/Mirantis/cri-dockerd.git --branch v0.3.1",
"cd cri-dockerd",
"/usr/local/go/bin/go build",
"sudo cp cri-dockerd /usr/local/bin/",
"sudo cp -a packaging/systemd/* /etc/systemd/system",
"sudo sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service",
"sudo systemctl enable cri-docker.socket",
]
}

provisioner "shell" {
inline = [
"echo Installing kind...",
"/usr/local/go/bin/go install sigs.k8s.io/kind@v0.19.0",
"sudo cp /home/$USER/go/bin/kind /usr/local/bin/",
"/home/$USER/go/bin/kind version",
]
}

provisioner "shell" {
inline = [
"echo Cloning openconfig/kne github repo...",
"sudo apt-get -o DPkg::Lock::Timeout=60 install git -y",
"git clone -b ${var.branch_name} https://github.com/openconfig/kne.git",
"cd kne/kne_cli",
"/usr/local/go/bin/go build -o kne",
"sudo cp kne /usr/local/bin/",
"cd ../controller/server",
"/usr/local/go/bin/go build",
"cd $HOME",
"mkdir -p .config/kne",
"echo \"report_usage: true\" > .config/kne/config.yaml",
]
}

provisioner "shell" {
inline = [
"echo Cloning openconfig/ondatra github repo...",
"git clone https://github.com/openconfig/ondatra.git",
]
}

provisioner "shell" {
inline = [
"echo Cloning internal cloud source repos...",
"gcloud source repos clone kne-internal --project=gep-kne",
"cd kne-internal",
"/usr/local/go/bin/go get -d ./...",
"cd proxy/server",
"/usr/local/go/bin/go build",
"cd ../../kneproxy",
"/usr/local/go/bin/go build",
]
}

provisioner "shell" {
inline = [
"echo Installing Google cloud ops agent...",
"curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh",
"sudo bash add-google-cloud-ops-agent-repo.sh --also-install",
"rm add-google-cloud-ops-agent-repo.sh",
]
}
}
31 changes: 29 additions & 2 deletions cloudbuild/postsubmit.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
steps:
- id: packer_init_external
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["init", "cloudbuild/external.pkr.hcl"]
waitFor: ["-"] # run the builds concurrently

- id: packer_build_external
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer"
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["build", "cloudbuild/external.pkr.hcl"]
env: [
"PKR_VAR_build_id=$BUILD_ID",
"PKR_VAR_short_sha=$SHORT_SHA",
"PKR_VAR_branch_name=$BRANCH_NAME",
"PKR_VAR_zone=${_ZONE}",
]
waitFor: [packer_init_external]

- id: packer_init_internal
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["init", "cloudbuild/internal.pkr.hcl"]
waitFor: ["-"] # run the builds concurrently

- id: packer_build_internal
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer"
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["build", "cloudbuild/internal.pkr.hcl"]
env: [
"PKR_VAR_build_id=$BUILD_ID",
"PKR_VAR_short_sha=$SHORT_SHA",
"PKR_VAR_branch_name=$BRANCH_NAME",
"PKR_VAR_zone=${_ZONE}",
]
waitFor: [packer_init_internal]

- id: packer_init_internal_ubuntu
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["init", "cloudbuild/internal_ubuntu.pkr.hcl"]
waitFor: ["-"] # run the builds concurrently

- id: packer_build_internal_ubuntu
name: "us-west1-docker.pkg.dev/gep-kne/packer/packer:1.9.1"
args: ["build", "cloudbuild/internal_ubuntu.pkr.hcl"]
env: [
"PKR_VAR_build_id=$BUILD_ID",
"PKR_VAR_short_sha=$SHORT_SHA",
"PKR_VAR_branch_name=$BRANCH_NAME",
"PKR_VAR_zone=${_ZONE}",
]
waitFor: [packer_init_internal_ubuntu]

timeout: 3600s

substitutions:
Expand Down

0 comments on commit 977f0c0

Please sign in to comment.