-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
369 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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,24 @@ | ||
name: StepSecurity images | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
images: | ||
type: string | ||
required: true | ||
description: 'Distribution(s) to build' | ||
default: '["ubuntu22-stepsecurity-x64", "ubuntu24-stepsecurity-x64"]' | ||
schedule: | ||
- cron: '0 20 */15 * *' | ||
|
||
jobs: | ||
build-test-release: | ||
name: Build/Test/Release ${{ matrix.image_id }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
image_id: ${{ fromJSON(github.event.inputs.images || '["ubuntu22-stepsecurity-x64", "ubuntu24-stepsecurity-x64"]') }} | ||
uses: ./.github/workflows/build-test-release.yml | ||
secrets: inherit | ||
with: | ||
image_id: ${{ matrix.image_id }} |
This file contains 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ ec2-boot-bench | |
.trash | ||
*.pem | ||
/releases/**/*.hcl | ||
/integrations |
This file contains 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 |
---|---|---|
|
@@ -47,8 +47,16 @@ packer_template_path = "#{release_dir}/images/#{packer_template_relative_path}" | |
# Copy template to destination | ||
FileUtils.cp("patches/#{packer_template_relative_path}", packer_template_path) | ||
|
||
FileUtils.rm_rf("integrations") && Dir.mkdir("integrations") | ||
{ | ||
"runs-on/runner-images-for-stepsecurity" => "integrations/stepsecurity" | ||
}.each do |repo, path| | ||
system("git clone [email protected]:#{repo}.git #{path}") | ||
end | ||
|
||
at_exit do | ||
FileUtils.rm_rf(packer_template_path) | ||
FileUtils.rm_rf("integrations") | ||
end | ||
|
||
packer_init_cmd = [ | ||
|
@@ -72,11 +80,11 @@ packer_build_cmd = [ | |
].compact | ||
|
||
puts "Running Packer init command: #{packer_init_cmd.join(' ')}" | ||
system({ "PACKER_LOG" => "1" }, *packer_init_cmd) or fail("Packer init failed") | ||
system({ "PACKER_LOG" => "0" }, *packer_init_cmd) or fail("Packer init failed") | ||
|
||
puts "Running Packer build command: #{packer_build_cmd.join(' ')}" | ||
|
||
unless system(*packer_build_cmd) | ||
unless system({ "PROJECT_ROOT" => File.expand_path("..", __dir__) }, *packer_build_cmd) | ||
# Cleanup any dangling EC2 instances | ||
ec2_client = Aws::EC2::Client.new(region: 'us-east-1') | ||
instances = ec2_client.describe_instances( | ||
|
This file contains 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
150 changes: 150 additions & 0 deletions
150
patches/ubuntu/templates/ubuntu22-stepsecurity-x64.pkr.hcl
This file contains 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,150 @@ | ||
packer { | ||
required_plugins { | ||
amazon = { | ||
source = "github.com/hashicorp/amazon" | ||
version = "~> 1" | ||
} | ||
} | ||
} | ||
|
||
variable "project_root" { | ||
type = string | ||
default = "${env("PROJECT_ROOT")}" | ||
} | ||
|
||
variable "ami_name" { | ||
type = string | ||
default = "${env("AMI_NAME")}" | ||
} | ||
|
||
variable "ami_description" { | ||
type = string | ||
} | ||
|
||
variable "ami_regions" { | ||
type = list(string) | ||
} | ||
|
||
variable "image_os" { | ||
type = string | ||
// ex: ubuntu22 | ||
default = "${env("IMAGE_OS")}" | ||
} | ||
|
||
variable "image_version" { | ||
type = string | ||
default = "${env("IMAGE_VERSION")}" | ||
} | ||
|
||
variable "subnet_id" { | ||
type = string | ||
} | ||
|
||
variable "volume_size" { | ||
type = number | ||
default = 30 | ||
} | ||
|
||
variable "volume_type" { | ||
type = string | ||
default = "gp3" | ||
} | ||
|
||
variable "region" { | ||
type = string | ||
} | ||
|
||
variable "source_ami_owner" { | ||
type = string | ||
} | ||
|
||
variable "source_ami_name" { | ||
type = string | ||
} | ||
|
||
data "amazon-ami" "runs-on-ami" { | ||
filters = { | ||
name = "${var.source_ami_name}" | ||
root-device-type = "ebs" | ||
virtualization-type = "hvm" | ||
} | ||
most_recent = true | ||
owners = ["${var.source_ami_owner}"] | ||
region = "${var.region}" | ||
} | ||
|
||
source "amazon-ebs" "build_ebs" { | ||
aws_polling { | ||
delay_seconds = 30 | ||
max_attempts = 300 | ||
} | ||
|
||
temporary_security_group_source_public_ip = true | ||
ami_name = "${var.ami_name}" | ||
ami_description = "${var.ami_description}" | ||
ami_virtualization_type = "hvm" | ||
# make AMIs publicly accessible | ||
ami_groups = ["all"] | ||
ebs_optimized = true | ||
spot_instance_types = ["m7a.xlarge", "c7a.xlarge", "c7i.xlarge", "m7i.xlarge", "m7i-flex.xlarge"] | ||
spot_price = "auto" | ||
region = "${var.region}" | ||
ssh_username = "ubuntu" | ||
subnet_id = "${var.subnet_id}" | ||
associate_public_ip_address = "true" | ||
force_deregister = "true" | ||
force_delete_snapshot = "true" | ||
|
||
ami_regions = "${var.ami_regions}" | ||
|
||
// make underlying snapshot public | ||
snapshot_groups = ["all"] | ||
|
||
launch_block_device_mappings { | ||
device_name = "/dev/sda1" | ||
volume_type = "${var.volume_type}" | ||
volume_size = "${var.volume_size}" | ||
delete_on_termination = "true" | ||
encrypted = "false" | ||
} | ||
|
||
run_tags = { | ||
creator = "RunsOn" | ||
contact = "[email protected]" | ||
ami_name = "${var.ami_name}" | ||
} | ||
|
||
tags = { | ||
creator = "RunsOn" | ||
contact = "[email protected]" | ||
} | ||
|
||
snapshot_tags = { | ||
creator = "RunsOn" | ||
contact = "[email protected]" | ||
} | ||
|
||
source_ami_filter { | ||
filters = { | ||
virtualization-type = "hvm" | ||
name = "${var.source_ami_name}" | ||
root-device-type = "ebs" | ||
} | ||
owners = ["${var.source_ami_owner}"] | ||
most_recent = true | ||
} | ||
|
||
user_data = <<EOF | ||
#!/bin/bash | ||
systemctl start ssh | ||
EOF | ||
} | ||
|
||
build { | ||
sources = ["source.amazon-ebs.build_ebs"] | ||
|
||
provisioner "shell" { | ||
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'" | ||
scripts = ["${var.project_root}/integrations/stepsecurity/packer/install-linux.sh"] | ||
} | ||
} |
Oops, something went wrong.