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

feat(azure): baking from another existing image #910

Merged
merged 3 commits into from
Nov 1, 2022
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
4 changes: 2 additions & 2 deletions halconfig/images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ aws:

azure:
bakeryDefaults:
templateFile: azure-linux.json
templateFile: azure-linux.pkr.hcl
baseImages:
- baseImage:
id: ubuntu-1604
Expand Down Expand Up @@ -175,7 +175,7 @@ azure:
version: 4.0.20170111
osType: windows
packageType: nupkg
templateFile: azure-windows-2012-r2.json
templateFile: azure-windows.pkr.hcl

docker:
bakeryDefaults:
Expand Down
136 changes: 136 additions & 0 deletions halconfig/packer/azure-linux-managed-image.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
variable "azure_client_id" {
type = string
default = ""
sensitive = true
}

variable "azure_client_secret" {
type = string
default = ""
sensitive = true
}

variable "azure_image_name" {
type = string
default = ""
}

variable "azure_image_offer" {
type = string
default = ""
}

variable "azure_image_publisher" {
type = string
default = ""
}

variable "azure_image_sku" {
type = string
default = ""
}

variable "azure_location" {
type = string
default = ""
}

variable "azure_custom_managed_image_name" {
type = string
default = ""
}

variable "azure_managed_image_name" {
type = string
default = ""
}

variable "azure_resource_group" {
type = string
default = ""
}

variable "azure_storage_account" {
type = string
default = ""
}

variable "azure_subscription_id" {
type = string
default = ""
}

variable "azure_tenant_id" {
type = string
default = ""
}

variable "build_host" {
type = string
default = ""
}

variable "configDir" {
type = string
}

variable "package_type" {
type = string
default = ""
}

variable "packages" {
type = string
default = ""
}

variable "repository" {
type = string
default = ""
}

variable "upgrade" {
type = string
default = ""
}

source "azure-arm" "azure-linux-managed-image" {
client_id = "${var.azure_client_id}"
client_secret = "${var.azure_client_secret}"
subscription_id = "${var.azure_subscription_id}"
tenant_id = "${var.azure_tenant_id}"

custom_managed_image_name = "${var.azure_custom_managed_image_name}"
custom_managed_image_resource_group_name = "${var.azure_resource_group}"

location = "${var.azure_location}"
managed_image_name = "${var.azure_managed_image_name}"
managed_image_resource_group_name = "${var.azure_resource_group}"

os_type = "Linux"
vm_size = "Standard_DS2_v2"

polling_duration_timeout = "1h5m2s"
}

build {
sources = ["source.azure-arm.azure-linux-managed-image"]

provisioner "shell" {
environment_vars = [
"repository=${var.repository}", "package_type=${var.package_type}", "packages=${var.packages}",
"upgrade=${var.upgrade}"
]
pause_before = "20s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious: Is there a reason to set this to 20s instead of the old value 30s? I noticed it in the azure-linux.pkr.hcl as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no specific reason, I believe it is to give the VM the chance to be ready, 20s worked well, and I considered removing them even

script = "${var.configDir}/install_packages.sh"
}

provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
inline = [
"apt-get update", "apt-get upgrade -y", "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
]
inline_shebang = "/bin/sh -x"
}

}
64 changes: 0 additions & 64 deletions halconfig/packer/azure-linux.json

This file was deleted.

125 changes: 125 additions & 0 deletions halconfig/packer/azure-linux.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
variable "azure_client_id" {
type = string
default = ""
sensitive = true
}

variable "azure_client_secret" {
type = string
default = ""
sensitive = true
}

variable "azure_image_name" {
type = string
default = ""
}

variable "azure_image_offer" {
type = string
default = ""
}

variable "azure_image_publisher" {
type = string
default = ""
}

variable "azure_image_sku" {
type = string
default = ""
}

variable "azure_location" {
type = string
default = ""
}

variable "azure_managed_image_name" {
type = string
default = ""
}

variable "azure_resource_group" {
type = string
default = ""
}

variable "azure_subscription_id" {
type = string
default = ""
}

variable "azure_tenant_id" {
type = string
default = ""
}

variable "build_host" {
type = string
default = ""
}

variable "configDir" {
type = string
}

variable "package_type" {
type = string
default = ""
}

variable "packages" {
type = string
default = ""
}

variable "repository" {
type = string
default = ""
}

variable "upgrade" {
type = string
default = ""
}

source "azure-arm" "azure-linux" {
client_id = "${var.azure_client_id}"
client_secret = "${var.azure_client_secret}"
subscription_id = "${var.azure_subscription_id}"
tenant_id = "${var.azure_tenant_id}"

image_offer = "${var.azure_image_offer}"
image_publisher = "${var.azure_image_publisher}"
image_sku = "${var.azure_image_sku}"

location = "${var.azure_location}"
managed_image_name = "${var.azure_managed_image_name}"
managed_image_resource_group_name = "${var.azure_resource_group}"

os_type = "Linux"
vm_size = "Standard_DS2_v2"
}

build {
sources = ["source.azure-arm.azure-linux"]

provisioner "shell" {
environment_vars = [
"repository=${var.repository}", "package_type=${var.package_type}", "packages=${var.packages}",
"upgrade=${var.upgrade}"
]
pause_before = "20s"
script = "${var.configDir}/install_packages.sh"
}

provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
inline = [
"apt-get update", "apt-get upgrade -y", "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
]
inline_shebang = "/bin/sh -x"
}

}
Loading