Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Compute Platform Packer template #435

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packer/images.json.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ source "azure-arm" "cos" {
}
}

source "googlecompute" "cos" {
project_id = var.gcp_project_id
source_image_family = var.gcp_source_image
ssh_password = var.root_password
ssh_username = var.root_username
zone = var.gcp_location
disk_size = var.gcp_disk_size
enable_secure_boot = false
image_name = "${lower(var.name)}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${substr(var.git_sha, 0, 7)}-${var.flavor}"
image_description = "${var.name}-${replace(var.cos_version, "+", "-")}-${formatdate("DDMMYYYY", timestamp())}-${substr(var.git_sha, 0, 7)}-${var.flavor}"
image_labels = {
name = "${lower(var.name)}"
version = var.cos_version
flavor = var.flavor
git_sha = var.git_sha # use full sha here
}
image_storage_locations = [var.gcp_image_storage_location]
machine_type = var.gcp_machine_type
metadata_files = {
user-data = var.gcp_user_data_file
}
}

source "qemu" "cos" {
accelerator = "${var.accelerator}"
boot_wait = "${var.sleep}"
Expand Down Expand Up @@ -104,22 +127,22 @@ source "virtualbox-iso" "cos" {
build {
description = "cOS"

sources = ["source.amazon-ebs.cos", "source.qemu.cos", "source.virtualbox-iso.cos", "source.azure-arm.cos"]
sources = ["source.amazon-ebs.cos", "source.qemu.cos", "source.virtualbox-iso.cos", "source.azure-arm.cos", "source.googlecompute.cos"]

provisioner "file" {
except = ["amazon-ebs.cos", "azure-arm.cos"]
except = ["amazon-ebs.cos", "azure-arm.cos", "googlecompute.cos"]
destination = "/90_custom.yaml"
source = "config.yaml"
}

provisioner "file" {
except = ["amazon-ebs.cos", "azure-arm.cos"]
except = ["amazon-ebs.cos", "azure-arm.cos", "googlecompute.cos"]
destination = "/vagrant.yaml"
source = "vagrant.yaml"
}

provisioner "shell" {
except = ["amazon-ebs.cos", "azure-arm.cos"]
except = ["amazon-ebs.cos", "azure-arm.cos", "googlecompute.cos"]
inline = ["INTERACTIVE=false cos-installer --config /90_custom.yaml /dev/sda",
"if [ -n \"${var.feature}\" ]; then mount /dev/disk/by-label/COS_OEM /oem; cos-feature enable ${var.feature}; fi"
]
Expand All @@ -135,6 +158,15 @@ build {
pause_after = "30s"
}

provisioner "shell" {
only = ["googlecompute.cos"]
inline = [
"${var.gcp_cos_deploy_args}",
"sync"
]
pause_after = "30s"
}

provisioner "shell" {
only = ["azure-arm.cos"]
inline = [
Expand Down
2 changes: 1 addition & 1 deletion packer/user-data/aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ stages:
filesystem: ext4
- fsLabel: COS_PERSISTENT
pLabel: persistent
filesystem: ext4
filesystem: ext4
16 changes: 16 additions & 0 deletions packer/user-data/gcp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Default deployment"
stages:
rootfs.after:
- if: '[ -f "/run/cos/recovery_mode" ]'
name: "Repart image"
layout:
device:
label: COS_RECOVERY
add_partitions:
- fsLabel: COS_STATE
size: 9192
pLabel: state
filesystem: ext4
- fsLabel: COS_PERSISTENT
pLabel: persistent
filesystem: ext4
47 changes: 47 additions & 0 deletions packer/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,53 @@ variable "aws_cos_deploy_args" {
description = "Arguments to execute while provisioning cloud images with packer. This will use the shell provisioner"
}

variable "gcp_source_image" {
type = string
default = "cos-vanilla"
description = "Image family to use as source. The lastest of the given family is used"
}

variable "gcp_location" {
type = string
default = "europe-west3-a"
description = "Zone used for the build process"
}

variable "gcp_image_storage_location" {
type = string
default = "eu"
description = "Location for the resulting image"
}

variable "gcp_disk_size" {
type = number
default = 16
description = "Size in of the disk in GB"
}

variable "gcp_machine_type" {
type = string
default = "n1-standard-1"
description = "Instance type to use"
}

variable "gcp_user_data_file" {
type = string
default = "user-data/gcp.yaml"
description = "Path to the user-data file to boot the base instance with"
}

variable "gcp_cos_deploy_args" {
type = string
default = "cos-deploy"
description = "Arguments to execute while provisioning cloud images with packer. This will use the shell provisioner"
}

variable "gcp_project_id" {
type = string
description = "Project to look for the image family"
}

variable "cos_version" {
type = string
default = "latest"
Expand Down