Skip to content

Commit cd07fa6

Browse files
estevekpturnerlifeisafractal
authored
Parameterise execution of runner (update) (#152)
* Parameterise execution of runner * Add new parm to config * Add ability to specify user * Run npm run package. Fix ownership of the directory where actions are installed. * try to repackage (#1) --------- Co-authored-by: Kevin <[email protected]> Co-authored-by: Matthew Campbell <[email protected]>
1 parent ebb2e33 commit cd07fa6

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ inputs:
8686
startup-timeout-seconds:
8787
description: >-
8888
Specifies the timeout in seconds to register the runner after the quiet period.
89+
run-runner-as-service:
90+
type: boolean
91+
description: >-
92+
Start the runner as a service rather than using ./run.sh as root.
8993
required: false
94+
run-runner-as-user:
95+
description: >-
96+
Specify user under whom the runner service should run
9097
outputs:
9198
label:
9299
description: >-

dist/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145013,21 +145013,23 @@ const config = __nccwpck_require__(4570);
145013145013

145014145014
// User data scripts are run as the root user
145015145015
function buildUserDataScript(githubRegistrationToken, label) {
145016+
let userData;
145016145017
if (config.input.runnerHomeDir) {
145017145018
// If runner home directory is specified, we expect the actions-runner software (and dependencies)
145018145019
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
145019-
return [
145020+
userData = [
145020145021
'#!/bin/bash',
145022+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
145021145023
`cd "${config.input.runnerHomeDir}"`,
145022145024
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
145023145025
'source pre-runner-script.sh',
145024145026
'export RUNNER_ALLOW_RUNASROOT=1',
145025145027
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
145026-
'./run.sh',
145027145028
];
145028145029
} else {
145029-
return [
145030+
userData = [
145030145031
'#!/bin/bash',
145032+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
145031145033
'mkdir actions-runner && cd actions-runner',
145032145034
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
145033145035
'source pre-runner-script.sh',
@@ -145036,9 +145038,18 @@ function buildUserDataScript(githubRegistrationToken, label) {
145036145038
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz',
145037145039
'export RUNNER_ALLOW_RUNASROOT=1',
145038145040
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
145039-
'./run.sh',
145040145041
];
145041145042
}
145043+
if (config.input.runAsUser) {
145044+
userData.push(`chown -R ${config.input.runAsUser} .`);
145045+
}
145046+
if (config.input.runAsService) {
145047+
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
145048+
userData.push('./svc.sh start');
145049+
} else {
145050+
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
145051+
}
145052+
return userData;
145042145053
}
145043145054

145044145055
function buildMarketOptions() {
@@ -145160,6 +145171,8 @@ class Config {
145160145171
startupRetryIntervalSeconds: core.getInput('startup-retry-interval-seconds'),
145161145172
startupTimeoutMinutes: core.getInput('startup-timeout-minutes'),
145162145173
subnetId: core.getInput('subnet-id'),
145174+
runAsService: core.getInput('run-runner-as-service') === 'true',
145175+
runAsUser: core.getInput('run-runner-as-user')
145163145176
};
145164145177

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
"dotenv": "^8.6.0",
2828
"eslint": "^7.32.0"
2929
}
30-
}
30+
}

src/aws.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ const config = require('./config');
55

66
// User data scripts are run as the root user
77
function buildUserDataScript(githubRegistrationToken, label) {
8+
let userData;
89
if (config.input.runnerHomeDir) {
910
// If runner home directory is specified, we expect the actions-runner software (and dependencies)
1011
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
11-
return [
12+
userData = [
1213
'#!/bin/bash',
14+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
1315
`cd "${config.input.runnerHomeDir}"`,
1416
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
1517
'source pre-runner-script.sh',
1618
'export RUNNER_ALLOW_RUNASROOT=1',
1719
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
18-
'./run.sh',
1920
];
2021
} else {
21-
return [
22+
userData = [
2223
'#!/bin/bash',
24+
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
2325
'mkdir actions-runner && cd actions-runner',
2426
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
2527
'source pre-runner-script.sh',
@@ -28,9 +30,18 @@ function buildUserDataScript(githubRegistrationToken, label) {
2830
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz',
2931
'export RUNNER_ALLOW_RUNASROOT=1',
3032
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
31-
'./run.sh',
3233
];
3334
}
35+
if (config.input.runAsUser) {
36+
userData.push(`chown -R ${config.input.runAsUser} .`);
37+
}
38+
if (config.input.runAsService) {
39+
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
40+
userData.push('./svc.sh start');
41+
} else {
42+
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
43+
}
44+
return userData;
3445
}
3546

3647
function buildMarketOptions() {

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Config {
1919
startupRetryIntervalSeconds: core.getInput('startup-retry-interval-seconds'),
2020
startupTimeoutMinutes: core.getInput('startup-timeout-minutes'),
2121
subnetId: core.getInput('subnet-id'),
22+
runAsService: core.getInput('run-runner-as-service') === 'true',
23+
runAsUser: core.getInput('run-runner-as-user')
2224
};
2325

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

0 commit comments

Comments
 (0)