Skip to content

Commit

Permalink
Add 'key-name' and 'block-device-mapping' options (machulav#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
garbas committed Sep 28, 2023
1 parent 67a0119 commit 1449492
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br><br> This field is a stringified JSON array of tag objects, each containing a `Key` and `Value` field (see example below). <br><br> 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.<br><br> |
| `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:<pre> - name: Start EC2 runner<br> with:<br> mode: start<br> ...<br> pre-runner-script: \|<br> sudo yum update -y && \ <br> sudo yum install docker git libicu -y<br> sudo systemctl enable docker</pre>
<br><br> |
`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.<br><br> |
| `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:<pre> block-device-mapper: \|<br> [<br> {"DeviceName" : "/dev/sda1", "Ebs" : { "VolumeType": "gp2", "VolumeSize": 34 }},<br> {"DeviceName" : "/dev/sdb", "VirtualName": "ephemeral0" }<br> ]
</pre>|

### Environment variables

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'));
Expand Down
2 changes: 2 additions & 0 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 {
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 1449492

Please sign in to comment.