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

EC2 launch template support #70

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Now you're ready to go!
| `iam-role-name` | Optional. Used only with the `start` mode. | IAM role name to attach to the created EC2 runner. <br><br> This allows the runner to have permissions to run additional actions within the AWS account, without having to manage additional GitHub secrets and AWS users. <br><br> Setting this requires additional AWS permissions for the role launching the instance (see above). |
| `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> |
| `ec2-launch-template` | Optional. Used only with the `start` mode. | Specifies an existing EC2 launch template (by name), which can be used to define image ID, instance type, subnet ID, security group IDs, spot options etc<br><br> |

### Environment variables

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ inputs:
description: >-
Directory that contains actions-runner software and scripts. E.g. /home/runner/actions-runner.
required: false
ec2-launch-template:
description: >-
EC2 launch template name. A launch template may be used to specify AMI, instance type etc parameters
required: false
outputs:
label:
description: >-
Expand Down
6 changes: 6 additions & 0 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ async function startEc2Instance(label, githubRegistrationToken) {
TagSpecifications: config.tagSpecifications,
};

if (config.input.ec2LaunchTemplate) {
params.LaunchTemplate = {
LaunchTemplateName: config.input.ec2LaunchTemplate
};
}

try {
const result = await ec2.runInstances(params).promise();
const ec2InstanceId = result.Instances[0].InstanceId;
Expand Down
5 changes: 4 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Config {
ec2InstanceId: core.getInput('ec2-instance-id'),
iamRoleName: core.getInput('iam-role-name'),
runnerHomeDir: core.getInput('runner-home-dir'),
ec2LaunchTemplate: core.getInput('ec2-launch-template'),
};

const tags = JSON.parse(core.getInput('aws-resource-tags'));
Expand Down Expand Up @@ -43,7 +44,9 @@ class Config {
}

if (this.input.mode === 'start') {
if (!this.input.ec2ImageId || !this.input.ec2InstanceType || !this.input.subnetId || !this.input.securityGroupId) {
const isSet = param => param;
const params = [this.input.ec2ImageId, this.input.ec2InstanceType, this.input.subnetId, this.input.securityGroupId];
if (!(this.input.ec2LaunchTemplate || params.every(isSet))) {
throw new Error(`Not all the required inputs are provided for the 'start' mode`);
}
} else if (this.input.mode === 'stop') {
Expand Down