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

PLT-186: Debugging #18

Merged
merged 41 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9927272
add id-token permission
gfreeman-navapbc Nov 2, 2023
221de6c
add runner version variable
gfreeman-navapbc Nov 2, 2023
6ec79ac
add stashed changes
gfreeman-navapbc Nov 2, 2023
8df2618
add ami_account and ami_filter variables
gfreeman-navapbc Nov 2, 2023
214b924
fix var flag
gfreeman-navapbc Nov 2, 2023
94c64c7
add quotes
gfreeman-navapbc Nov 2, 2023
3c5119e
build entire directory
gfreeman-navapbc Nov 2, 2023
a134de7
attempt to populate ami account and filter
gfreeman-navapbc Nov 2, 2023
d26ac98
add vars to environment and validate with vars
gfreeman-navapbc Nov 2, 2023
fe58704
add datasources in validation
gfreeman-navapbc Nov 2, 2023
085a5cb
add most_recent flag
gfreeman-navapbc Nov 2, 2023
853fa78
move to correct spot
gfreeman-navapbc Nov 2, 2023
e856fa1
grab vpc id from data
gfreeman-navapbc Nov 14, 2023
3de8a8e
attempt to filter for vpc_id
gfreeman-navapbc Nov 14, 2023
d0b6a88
use correct tag
gfreeman-navapbc Nov 14, 2023
87d5c61
change var name to match repo vars
gfreeman-navapbc Nov 14, 2023
0247b49
add security group to setup
gfreeman-navapbc Nov 16, 2023
282b28c
spelling
gfreeman-navapbc Nov 16, 2023
ee6a52a
multiline command fix
gfreeman-navapbc Nov 16, 2023
aca19e2
security_group instead of subnet
gfreeman-navapbc Nov 16, 2023
803aa2e
specify subnet
gfreeman-navapbc Nov 16, 2023
8db0fa3
layer is a tag
gfreeman-navapbc Nov 16, 2023
b2d9030
convert to old style substitution
gfreeman-navapbc Nov 16, 2023
b27307d
missing backslash
gfreeman-navapbc Nov 16, 2023
4201c1b
set ssh_interface to session manager
gfreeman-navapbc Nov 16, 2023
4762081
try private_ip before setting up ssm
gfreeman-navapbc Nov 16, 2023
2e6bea2
add instance profile, go back to ssm
gfreeman-navapbc Nov 16, 2023
cee197e
fix hyphen
gfreeman-navapbc Nov 16, 2023
d728fb6
bump timeout
gfreeman-navapbc Nov 16, 2023
e4517f9
remove session_manager
gfreeman-navapbc Nov 16, 2023
891a6ff
self-hosted
gfreeman-navapbc Nov 28, 2023
7378e22
checkout to v3 from v4, node issue
gfreeman-navapbc Nov 28, 2023
1451c0f
move to session manager
gfreeman-navapbc Nov 28, 2023
460da10
build over private ip, ssm isnt connecting
gfreeman-navapbc Nov 28, 2023
644b08e
add tags and name to image
gfreeman-navapbc Nov 29, 2023
dbfadcb
remove management sg
gfreeman-navapbc Nov 30, 2023
5547761
add debug flag
gfreeman-navapbc Nov 30, 2023
22c1e47
add verbose logging
gfreeman-navapbc Nov 30, 2023
53b25a7
switch to dnf over yum
gfreeman-navapbc Dec 1, 2023
e28f162
remove dnf, just use yum for docker
gfreeman-navapbc Dec 6, 2023
0230a47
remove curl command with error
gfreeman-navapbc Dec 7, 2023
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
45 changes: 40 additions & 5 deletions .github/workflows/build-runner-images.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build Runner EC2 Images

on:
pull_request:
paths:
- .github/workflows/build-runner-images.yml
schedule:
# 00:00 on Monday each week
- cron: "0 0 * * 1"
Expand All @@ -9,20 +12,40 @@ on:
jobs:
build-image:
name: Build
runs-on: ubuntu-latest
runs-on: self-hosted
defaults:
run:
working-directory: packer/github-actions-runner
permissions:
id-token: write
contents: read
env:
AMI_ACCOUNT: ${{ vars.RUNNER_AMI_ACCOUNT }}
AMI_FILTER: ${{ vars.RUNNER_AMI_FILTER }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::${{ vars.RUNNER_ACCOUNT }}:role/github-to-aws-oidc
role-to-assume: ${{ vars.RUNNER_ACCOUNT_ROLE }}
aws-region: us-east-1

- name: Retrieve default VPC ID and subnet
id: vpc
run: |
VPC_ID=$(aws ec2 describe-vpcs --filters "Name=tag:Name, Values=bcda-managed-vpc" --query 'Vpcs[].VpcId' --output text)
echo "VPC_ID=$VPC_ID" >> "$GITHUB_ENV"

SUBNET_ID=$(aws ec2 describe-subnets \
--filters \
"Name=vpc-id,Values=$VPC_ID" \
"Name=tag:Layer,Values=app" \
--query 'Subnets[0].SubnetId' \
--output text)
echo "SUBNET_ID=$SUBNET_ID" >> "$GITHUB_ENV"
Copy link
Member

Choose a reason for hiding this comment

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

Is there no way to do this with data sources in the hcl file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it doesn't seem that way, Terraform includes the datasources for aws_vpc and aws_subnet, but those are mysteriously left out of the packer data sources documentation.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, another weird quirk of Packer! Thanks for checking.


- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
Expand All @@ -35,8 +58,20 @@ jobs:

- name: Run `packer validate`
id: validate
run: packer validate .
run: |
packer validate \
-var ami_account="$AMI_ACCOUNT" \
-var ami_filter="$AMI_FILTER" \
-var vpc_id="$VPC_ID" \
-var subnet_id="$SUBNET_ID" \
-evaluate-datasources .

- name: Packer Build
id: build
run: packer build -color=false -on-error=cleanup build.pkr.hcl
run: |
PACKER_LOG=1 packer build \
-var ami_account="$AMI_ACCOUNT" \
-var ami_filter="$AMI_FILTER" \
-var vpc_id="$VPC_ID" \
-var subnet_id="$SUBNET_ID" \
-color=false -on-error=cleanup .
6 changes: 3 additions & 3 deletions packer/github-actions-runner/build.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ build {
provisioner "shell" {
environment_vars = []
inline = concat([
"sudo yum update -y",
"sudo yum install -y amazon-cloudwatch-agent curl jq git",
"sudo amazon-linux-extras install docker",
"sudo yum -y upgrade-minimal",
"sudo yum -y install amazon-cloudwatch-agent jq git docker",
"sudo yum -y install curl",
"sudo systemctl enable docker.service",
"sudo systemctl enable containerd.service",
"sudo service docker start",
Expand Down
22 changes: 19 additions & 3 deletions packer/github-actions-runner/sources.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ source "amazon-ebs" "github-actions-runner" {
instance_type = var.instance_type
region = var.region
security_group_id = var.security_group_id
vpc_id = var.vpc_id
subnet_id = var.subnet_id
associate_public_ip_address = var.associate_public_ip_address
temporary_security_group_source_public_ip = var.temporary_security_group_source_public_ip

source_ami_filter {
ami_filter = { name = ["${ vars.AMI_FILTER }"] }
ami_owners = ["${ vars.AMI_ACCOUNT }"]
enable_userdata = false
filters = { name = "${var.ami_filter}" }
owners = ["${var.ami_account}"]
most_recent = true
}

security_group_filter {
filters = {
"tag:Name": "packer_sg"
}
}

communicator = "ssh"
ssh_username = "ec2-user"
ssh_timeout = "1h"
ssh_pty = true
iam_instance_profile = "bcda-packer"

tags = {
Name = "github-actions-runner-ami",
Base_AMI_Name = "{{ .SourceAMIName }}"
}
}
23 changes: 23 additions & 0 deletions packer/github-actions-runner/variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ variable "region" {
default = "us-east-1"
}

variable "ami_filter" {
description = "The filter for searching the AMI"
type = string
default = null
}

variable "ami_account" {
description = "The target AMI account"
type = string
default = null
}

variable "instance_type" {
description = "The instance type Packer will use for the builder"
type = string
Expand All @@ -16,6 +28,12 @@ variable "security_group_id" {
default = null
}

variable "vpc_id" {
description = "The name of the VPC where the instance will be launched"
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
Expand Down Expand Up @@ -58,6 +76,11 @@ variable "custom_shell_commands" {
default = []
}

variable "runner_version" {
description = "The version (no v prefix) of the runner software to install https://github.com/actions/runner/releases. The latest release will be fetched from GitHub if not provided."
default = null
}

data "http" github_runner_release_json {
url = "https://github.com/repos/actions/runner/releases/latest"
request_headers = {
Expand Down