Skip to content

Commit 17e4c97

Browse files
authored
Allow user to pass in a custom actions-runner directory (#56)
* Allow user to pass in a custom actions-runner directory which contains pre-installed runner software and scripts * Add comment * Fix input refs * Fix linter error
1 parent 8911518 commit 17e4c97

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ Now you're ready to go!
193193
| `ec2-instance-id` | Required if you use the `stop` mode. | EC2 Instance Id of the created runner. <br><br> The id is provided by the output of the action in the `start` mode. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
194194
| `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). |
195195
| `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). |
196+
| `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> |
196197

197198
### Environment variables
198199

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ inputs:
6161
for example: '[{"Key": "TagKey1", "Value": "TagValue1"}, {"Key": "TagKey2", "Value": "TagValue2"}]'
6262
required: false
6363
default: '[]'
64+
runner-home-dir:
65+
description: >-
66+
Directory that contains actions-runner software and scripts. E.g. /home/runner/actions-runner.
67+
required: false
6468
outputs:
6569
label:
6670
description: >-

src/aws.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,38 @@ const AWS = require('aws-sdk');
22
const core = require('@actions/core');
33
const config = require('./config');
44

5+
// User data scripts are run as the root user
6+
function buildUserDataScript(githubRegistrationToken, label) {
7+
if (config.input.runnerHomeDir) {
8+
// If runner home directory is specified, we expect the actions-runner software (and dependencies)
9+
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
10+
return [
11+
'#!/bin/bash',
12+
`cd "${config.input.runnerHomeDir}"`,
13+
'export RUNNER_ALLOW_RUNASROOT=1',
14+
'export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1',
15+
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
16+
'./run.sh',
17+
];
18+
} else {
19+
return [
20+
'#!/bin/bash',
21+
'mkdir actions-runner && cd actions-runner',
22+
'case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}',
23+
'curl -O -L https://github.com/actions/runner/releases/download/v2.278.0/actions-runner-linux-${RUNNER_ARCH}-2.278.0.tar.gz',
24+
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.278.0.tar.gz',
25+
'export RUNNER_ALLOW_RUNASROOT=1',
26+
'export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1',
27+
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
28+
'./run.sh',
29+
];
30+
}
31+
}
32+
533
async function startEc2Instance(label, githubRegistrationToken) {
634
const ec2 = new AWS.EC2();
735

8-
// User data scripts are run as the root user.
9-
// Docker and git are necessary for GitHub runner and should be pre-installed on the AMI.
10-
const userData = [
11-
'#!/bin/bash',
12-
'mkdir actions-runner && cd actions-runner',
13-
'case $(uname -m) in aarch64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}',
14-
'curl -O -L https://github.com/actions/runner/releases/download/v2.278.0/actions-runner-linux-${RUNNER_ARCH}-2.278.0.tar.gz',
15-
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.278.0.tar.gz',
16-
'export RUNNER_ALLOW_RUNASROOT=1',
17-
'export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1',
18-
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
19-
'./run.sh',
20-
];
36+
const userData = buildUserDataScript(githubRegistrationToken, label);
2137

2238
const params = {
2339
ImageId: config.input.ec2ImageId,

src/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Config {
1313
label: core.getInput('label'),
1414
ec2InstanceId: core.getInput('ec2-instance-id'),
1515
iamRoleName: core.getInput('iam-role-name'),
16+
runnerHomeDir: core.getInput('runner-home-dir'),
1617
};
1718

1819
const tags = JSON.parse(core.getInput('aws-resource-tags'));

0 commit comments

Comments
 (0)