-
Notifications
You must be signed in to change notification settings - Fork 664
feat(images): Added ubuntu-focual example packer configuration #1644
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
Merged
npalm
merged 17 commits into
github-aws-runners:develop
from
toast-gear:feat(images)/ubuntu
Jan 28, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
74f5a54
feat: create Ubuntu image
toast-gear f6afdb1
feat: add aws v2 cli
toast-gear fb7835c
feat: add unzip
toast-gear 4c9a08f
feat: port tag changes to amazon linux image
toast-gear 3f69b20
chore(images): use same default for aws region
toast-gear c0a6787
fix: use apt-get you melon
toast-gear 1f9f6e0
feat: add cloudwatch agent
toast-gear 5bc05ad
fix: use new install location in example
toast-gear c94a441
feat: set env vars in service and align
toast-gear bfa3342
fix: setup action tool cache
toast-gear 6ced5f5
Merge branch 'develop' into feat(images)/ubuntu
toast-gear 8229022
fix: add missing arch var
toast-gear 0e9413a
fix: use Ubuntu's root device name
toast-gear b9304b7
chore: set apt to be noninteractive
toast-gear 9a64503
chore: align tag values with amzn2 image
toast-gear 4823c84
chore: better docs for tool cache location
toast-gear 2017bce
chore: include a warning
toast-gear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
packer { | ||
required_plugins { | ||
amazon = { | ||
version = ">= 0.0.2" | ||
source = "github.com/hashicorp/amazon" | ||
} | ||
} | ||
} | ||
|
||
variable "runner_version" { | ||
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases" | ||
type = string | ||
default = "2.286.1" | ||
} | ||
|
||
variable "region" { | ||
description = "The region to build the image in" | ||
type = string | ||
default = "eu-west-1" | ||
} | ||
|
||
variable "security_group_id" { | ||
description = "The ID of the security group Packer will associate with the builder to enable access" | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "subnet_id" { | ||
description = "If using VPC, the ID of the subnet, such as subnet-12345def, where Packer will launch the EC2 instance. This field is required if you are using an non-default VPC" | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "instance_type" { | ||
description = "The instance type Packer will use for the builder" | ||
type = string | ||
default = "t3.medium" | ||
} | ||
|
||
variable "root_volume_size_gb" { | ||
type = number | ||
default = 8 | ||
} | ||
|
||
variable "global_tags" { | ||
description = "Tags to apply to everything" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "ami_tags" { | ||
description = "Tags to apply to the AMI" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "snapshot_tags" { | ||
description = "Tags to apply to the snapshot" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
source "amazon-ebs" "githubrunner" { | ||
ami_name = "github-runner-ubuntu-focal-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}" | ||
instance_type = var.instance_type | ||
region = var.region | ||
security_group_id = var.security_group_id | ||
subnet_id = var.subnet_id | ||
source_ami_filter { | ||
filters = { | ||
name = "*/ubuntu-focal-20.04-amd64-server-*" | ||
root-device-type = "ebs" | ||
virtualization-type = "hvm" | ||
} | ||
most_recent = true | ||
owners = ["099720109477"] | ||
} | ||
ssh_username = "ubuntu" | ||
tags = merge( | ||
var.global_tags, | ||
var.ami_tags, | ||
{ | ||
OS_Version = "ubuntu-focal" | ||
Release = "Latest" | ||
Base_AMI_Name = "{{ .SourceAMIName }}" | ||
}) | ||
snapshot_tags = merge( | ||
var.global_tags, | ||
var.snapshot_tags, | ||
) | ||
|
||
launch_block_device_mappings { | ||
device_name = "/dev/sda1" | ||
volume_size = "${var.root_volume_size_gb}" | ||
volume_type = "gp3" | ||
} | ||
} | ||
|
||
build { | ||
name = "githubactions-runner" | ||
sources = [ | ||
"source.amazon-ebs.githubrunner" | ||
] | ||
provisioner "shell" { | ||
environment_vars = [ | ||
"DEBIAN_FRONTEND=noninteractive" | ||
] | ||
inline = [ | ||
"sudo apt-get -y update", | ||
"sudo apt-get -y install ca-certificates curl gnupg lsb-release", | ||
"sudo 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", | ||
"sudo apt-get -y update", | ||
"sudo apt-get -y install docker-ce docker-ce-cli containerd.io jq git unzip", | ||
"sudo systemctl enable containerd.service", | ||
"sudo service docker start", | ||
"sudo usermod -a -G docker ubuntu", | ||
"sudo curl -f https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb -o amazon-cloudwatch-agent.deb", | ||
"sudo dpkg -i amazon-cloudwatch-agent.deb", | ||
"sudo systemctl restart amazon-cloudwatch-agent", | ||
"sudo curl -f https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip", | ||
"unzip awscliv2.zip", | ||
"sudo ./aws/install", | ||
] | ||
} | ||
|
||
provisioner "file" { | ||
content = templatefile("../install-runner.sh", { | ||
install_runner = templatefile("../../modules/runners/templates/install-runner.sh", { | ||
ARM_PATCH = "" | ||
S3_LOCATION_RUNNER_DISTRIBUTION = "" | ||
RUNNER_ARCHITECTURE = "x64" | ||
}) | ||
}) | ||
destination = "/tmp/install-runner.sh" | ||
} | ||
|
||
provisioner "shell" { | ||
environment_vars = [ | ||
"RUNNER_TARBALL_URL=https://github.com/actions/runner/releases/download/v${var.runner_version}/actions-runner-linux-x64-${var.runner_version}.tar.gz" | ||
] | ||
inline = [ | ||
"sudo chmod +x /tmp/install-runner.sh", | ||
"echo ubuntu | tee -a /tmp/install-user.txt", | ||
"sudo RUNNER_ARCHITECTURE=x64 RUNNER_TARBALL_URL=$RUNNER_TARBALL_URL /tmp/install-runner.sh", | ||
"echo ImageOS=ubuntu20 | tee -a /opt/actions-runner/.env" | ||
] | ||
} | ||
|
||
provisioner "file" { | ||
content = templatefile("../start-runner.sh", { | ||
start_runner = templatefile("../../modules/runners/templates/start-runner.sh", {}) | ||
}) | ||
destination = "/tmp/start-runner.sh" | ||
} | ||
|
||
provisioner "shell" { | ||
inline = [ | ||
"sudo mv /tmp/start-runner.sh /var/lib/cloud/scripts/per-boot/start-runner.sh", | ||
"sudo chmod +x /var/lib/cloud/scripts/per-boot/start-runner.sh", | ||
] | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.