From d87ceb8a1133db2c0ff740d44b3d8d9808188d81 Mon Sep 17 00:00:00 2001 From: Tony Hutter Date: Thu, 22 Jun 2023 13:53:59 -0700 Subject: [PATCH] Add 'key-name' and 'block-device-mapping' options Add two new options to workflow file: key-name: Specifies SSH key-pair name to assign to an instance. This is useful for SSHing into an instance for debugging. block-device-mapping: JSON string specifying the BlockDeviceMapping for an instance. Signed-off-by: Tony Hutter --- README.md | 10 +++++++++- action.yml | 9 +++++++++ dist/index.js | 4 ++++ src/aws.js | 2 ++ src/config.js | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3b4e890..ceca1557 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,9 @@ Now you're ready to go! | `aws-resource-tags` | Optional. Used only with the `start` mode. | Specifies tags to add to the EC2 instance and any attached storage.

This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below).

Setting this requires additional AWS permissions for the role launching the instance (see above). | | `runner-home-dir` | Optional. Used only with the `start` mode. | Specifies a directory where pre-installed actions-runner software and scripts are located.

| | `pre-runner-script` | Optional. Used only with the `start` mode. | Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc. For example:
          - name: Start EC2 runner
with:
mode: start
...
pre-runner-script: \|
sudo yum update -y && \
sudo yum install docker git libicu -y
sudo systemctl enable docker
-

| +`key-name` | Optional. Used only with the `start` mode. | Specifies SSH key-pair name to assign to an instance. This is useful for SSHing into an instance for debugging.

| +| `block-device-mapping` | Optional. Used only with the `start` mode. | JSON string specifying the [BlockDeviceMapping](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-blockdev-mapping.html). For example:
 block-device-mapper: \|
[
{"DeviceName" : "/dev/sda1", "Ebs" : { "VolumeType": "gp2", "VolumeSize": 34 }},
{"DeviceName" : "/dev/sdb", "VirtualName": "ephemeral0" }
] +
| ### Environment variables @@ -263,6 +265,12 @@ jobs: {"Key": "Name", "Value": "ec2-github-runner"}, {"Key": "GitHubRepository", "Value": "${{ github.repository }}"} ] + key-name: my-ssh-key # optional + block-device-mapper: | # optional + [ + {"DeviceName" : "/dev/sda1", "Ebs" : { "VolumeType": "gp2", "VolumeSize": 34 }}, + {"DeviceName" : "/dev/sdb", "VirtualName": "ephemeral0" } + ] do-the-job: name: Do the job on the runner needs: start-runner # required to start the main job when the runner is ready diff --git a/action.yml b/action.yml index 09fa9591..218783e4 100644 --- a/action.yml +++ b/action.yml @@ -69,6 +69,15 @@ inputs: description: >- Specifies bash commands to run before the runner starts. It's useful for installing dependencies with apt-get, yum, dnf, etc. required: false + block-device-mapping: + description: >- + JSON string of EC2 BlockDeviceMapping (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-blockdev-mapping.html). + required: false + default: '[]' + key-name: + description: >- + Assign SSH key-pair name to an instance. This can be useful for SSHing into an instance for debugging. + required: false outputs: label: diff --git a/dist/index.js b/dist/index.js index 409180d4..43706a3d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -62847,6 +62847,8 @@ async function startEc2Instance(label, githubRegistrationToken) { SecurityGroupIds: [config.input.securityGroupId], IamInstanceProfile: { Name: config.input.iamRoleName }, TagSpecifications: config.tagSpecifications, + BlockDeviceMappings: config.input.blockDeviceMappings, + KeyName: config.input.keyName, }; try { @@ -62923,6 +62925,8 @@ class Config { iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), preRunnerScript: core.getInput('pre-runner-script'), + blockDeviceMappings: JSON.parse(core.getInput('block-device-mapping')), + keyName: core.getInput('key-name'), }; const tags = JSON.parse(core.getInput('aws-resource-tags')); diff --git a/src/aws.js b/src/aws.js index bcf53646..89f97eca 100644 --- a/src/aws.js +++ b/src/aws.js @@ -47,6 +47,8 @@ async function startEc2Instance(label, githubRegistrationToken) { SecurityGroupIds: [config.input.securityGroupId], IamInstanceProfile: { Name: config.input.iamRoleName }, TagSpecifications: config.tagSpecifications, + BlockDeviceMappings: config.input.blockDeviceMappings, + KeyName: config.input.keyName, }; try { diff --git a/src/config.js b/src/config.js index 1100f51e..cb636a62 100644 --- a/src/config.js +++ b/src/config.js @@ -15,6 +15,8 @@ class Config { iamRoleName: core.getInput('iam-role-name'), runnerHomeDir: core.getInput('runner-home-dir'), preRunnerScript: core.getInput('pre-runner-script'), + blockDeviceMappings: JSON.parse(core.getInput('block-device-mapping')), + keyName: core.getInput('key-name'), }; const tags = JSON.parse(core.getInput('aws-resource-tags'));