Skip to content

Commit

Permalink
Templates for stepsecurity images
Browse files Browse the repository at this point in the history
  • Loading branch information
crohr committed Feb 7, 2025
1 parent b737f06 commit aca179f
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- uses: webfactory/ssh-agent@72c0bfd31ab22a2e11716951e3f107a9647dc97e
with:
ssh-private-key: ${{ secrets.PRIVATE_KEY_FOR_INTEGRATIONS }}
- run: git log --oneline -n 1
- uses: ruby/setup-ruby@v1
with:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/matrix-stepsecurity.yml
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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ec2-boot-bench
.trash
*.pem
/releases/**/*.hcl
/integrations
12 changes: 10 additions & 2 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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(
Expand Down
41 changes: 31 additions & 10 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,59 @@ regions:
- ap-southeast-1
- ap-southeast-2
images:
# Ubuntu22
- id: ubuntu22-full-x64
volume_size: 30
source_ami_name: ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*
source_ami_owner: 099720109477
description: RunsOn Ubuntu22 x64

- id: ubuntu22-full-arm64
volume_size: 30
source_ami_name: ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*
source_ami_owner: 099720109477
description: RunsOn Ubuntu22 arm64

- id: ubuntu22-gpu-x64
volume_size: 30
source_ami_name: runs-on-dev-ubuntu22-full-x64-*
source_ami_owner: 135269210855
description: RunsOn Ubuntu22 GPU optimized x64

- id: ubuntu22-stepsecurity-x64
volume_size: 30
source_ami_name: runs-on-dev-ubuntu22-full-x64-*
source_ami_owner: 135269210855
description: RunsOn Ubuntu22 + StepSecurity x64

# Ubuntu24
- id: ubuntu24-full-x64
volume_size: 30
source_ami_name: ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*
source_ami_owner: 099720109477
description: RunsOn Ubuntu24 x64

- id: ubuntu24-full-arm64
volume_size: 30
source_ami_name: ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-arm64-server-*
source_ami_owner: 099720109477
description: RunsOn Ubuntu24 arm64
- id: windows22-full-x64
volume_size: 120
source_ami_name: Windows_Server-2022-English-Full-Base-*
source_ami_owner: 801119661308
description: RunsOn Windows2022 x64
- id: ubuntu22-gpu-x64
volume_size: 30
source_ami_name: runs-on-dev-ubuntu22-full-x64-*
source_ami_owner: 135269210855
description: RunsOn Ubuntu22 GPU optimized x64

- id: ubuntu24-gpu-x64
volume_size: 30
source_ami_name: runs-on-dev-ubuntu24-full-x64-*
source_ami_owner: 135269210855
description: RunsOn Ubuntu24 GPU optimized x64

- id: ubuntu24-stepsecurity-x64
volume_size: 30
source_ami_name: runs-on-dev-ubuntu24-full-x64-*
source_ami_owner: 135269210855
description: RunsOn Ubuntu24 + StepSecurity x64

# Windows22
- id: windows22-full-x64
volume_size: 120
source_ami_name: Windows_Server-2022-English-Full-Base-*
source_ami_owner: 801119661308
description: RunsOn Windows2022 x64
150 changes: 150 additions & 0 deletions patches/ubuntu/templates/ubuntu22-stepsecurity-x64.pkr.hcl
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"]
}
}
Loading

0 comments on commit aca179f

Please sign in to comment.