-
Notifications
You must be signed in to change notification settings - Fork 0
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
[ubuntu] add aws ami source #1
base: main
Are you sure you want to change the base?
Changes from all commits
eb0c1cd
7501ac6
849dd4a
851b484
65a3edc
e91f484
71e6691
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash -e | ||
################################################################################ | ||
## File: configure-environment.sh | ||
## Desc: Configure system and environment for azure build target | ||
################################################################################ | ||
|
||
# Change waagent entries to use /mnt for swapfile | ||
sed -i -e 's/ResourceDisk.Format=n/ResourceDisk.Format=y/g' \ | ||
-e 's/ResourceDisk.EnableSwap=n/ResourceDisk.EnableSwap=y/g' \ | ||
-e 's/ResourceDisk.SwapSizeMB=0/ResourceDisk.SwapSizeMB=4096/g' /etc/waagent.conf |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ packer { | |
source = "github.com/hashicorp/azure" | ||
version = "1.4.5" | ||
} | ||
amazon = { | ||
source = "github.com/hashicorp/amazon" | ||
version = "1.3.2" | ||
} | ||
} | ||
} | ||
|
||
|
@@ -143,6 +147,86 @@ variable "vm_size" { | |
default = "Standard_D4s_v4" | ||
} | ||
|
||
variable "sources" { | ||
type = list(string) | ||
default = ["source.azure-arm.build_image"] | ||
} | ||
|
||
variable "aws_ami_name" { | ||
type = string | ||
default = "github-runner" | ||
} | ||
|
||
variable "aws_ami_regions" { | ||
type = list(string) | ||
default = ["eu-west-1"] | ||
} | ||
|
||
variable "aws_instance_type" { | ||
type = string | ||
default = "m5.large" | ||
} | ||
|
||
variable "aws_run_tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "aws_tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "aws_force_deregister" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "aws_force_delete_snapshot" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "aws_region" { | ||
type = string | ||
default = "${env("AWS_REGION")}" | ||
} | ||
|
||
variable "aws_vpc_id" { | ||
type = string | ||
default = "${env("AWS_VPC_ID")}" | ||
} | ||
|
||
variable "aws_subnet_id" { | ||
type = string | ||
default = "${env("AWS_SUBNET_ID")}" | ||
} | ||
|
||
variable "aws_volume_size" { | ||
type = number | ||
default = 150 | ||
ostefek99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
variable "aws_run_volume_tags" { | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "aws_associate_public_ip_address" { | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "aws_ssh_username" { | ||
type = string | ||
default = "ubuntu" | ||
} | ||
|
||
variable "aws_deprecate_after" { | ||
type = string | ||
default = "4380h" # 4380 hours = 6 months | ||
} | ||
|
||
source "azure-arm" "build_image" { | ||
allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" | ||
build_resource_group_name = "${var.build_resource_group_name}" | ||
|
@@ -175,8 +259,55 @@ source "azure-arm" "build_image" { | |
} | ||
} | ||
|
||
source "amazon-ebs" "ubuntu-base-2204" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new source for aws ami source |
||
ami_name = "${var.aws_ami_name}" | ||
ami_regions = var.aws_ami_regions # all known AWS regions | ||
|
||
deprecate_at = timeadd(timestamp(), "${var.aws_deprecate_after}") | ||
|
||
run_tags = var.aws_run_tags | ||
tags = var.aws_tags | ||
|
||
instance_type = "${var.aws_instance_type}" | ||
|
||
force_deregister = var.aws_force_deregister | ||
force_delete_snapshot = var.aws_force_delete_snapshot | ||
|
||
region = "${var.aws_region}" | ||
vpc_id = "${var.aws_vpc_id}" | ||
subnet_id = "${var.aws_subnet_id}" | ||
|
||
launch_block_device_mappings { | ||
device_name = "/dev/sda1" | ||
volume_size = var.aws_volume_size | ||
delete_on_termination = true | ||
} | ||
|
||
run_volume_tags = var.aws_run_volume_tags | ||
|
||
associate_public_ip_address = var.aws_associate_public_ip_address | ||
ssh_username = "ubuntu" | ||
|
||
metadata_options { | ||
instance_metadata_tags = "enabled" | ||
} | ||
|
||
source_ami_filter { | ||
# See https://ubuntu.com/server/docs/cloud-images/amazon-ec2 | ||
filters = { | ||
virtualization-type = "hvm" | ||
name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" | ||
root-device-type = "ebs" | ||
architecture = "x86_64" | ||
} | ||
|
||
owners = ["099720109477"] # this is Canonical (official) | ||
most_recent = true | ||
} | ||
} | ||
|
||
build { | ||
ostefek99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sources = ["source.azure-arm.build_image"] | ||
sources = var.sources | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. input as variable with default value for backward compatibility reasons |
||
|
||
provisioner "shell" { | ||
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" | ||
|
@@ -252,6 +383,13 @@ build { | |
scripts = ["${path.root}/../scripts/build/configure-environment.sh"] | ||
} | ||
|
||
provisioner "shell" { | ||
only = ["azure-arm.build_image"] | ||
environment_vars = ["IMAGE_VERSION=${var.image_version}", "IMAGE_OS=${var.image_os}", "HELPER_SCRIPTS=${var.helper_script_folder}"] | ||
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" | ||
scripts = ["${path.root}/../scripts/build/configure-environment-azure-arm.sh"] | ||
} | ||
|
||
provisioner "shell" { | ||
environment_vars = ["DEBIAN_FRONTEND=noninteractive", "HELPER_SCRIPTS=${var.helper_script_folder}", "INSTALLER_SCRIPT_FOLDER=${var.installer_script_folder}"] | ||
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" | ||
|
@@ -414,6 +552,7 @@ build { | |
} | ||
|
||
provisioner "shell" { | ||
only = ["azure-arm.build_image"] | ||
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" | ||
inline = ["sleep 30", "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input as variable with default value for backward compatibility reasons
azure is always build as default if no sources variable is provided