Skip to content

Parameterise execution of runner (update) #152

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

Merged
merged 5 commits into from
Mar 26, 2025
Merged
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
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ inputs:
startup-timeout-seconds:
description: >-
Specifies the timeout in seconds to register the runner after the quiet period.
run-runner-as-service:
type: boolean
description: >-
Start the runner as a service rather than using ./run.sh as root.
required: false
run-runner-as-user:
description: >-
Specify user under whom the runner service should run
outputs:
label:
description: >-
Expand Down
21 changes: 17 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145013,21 +145013,23 @@ const config = __nccwpck_require__(4570);

// User data scripts are run as the root user
function buildUserDataScript(githubRegistrationToken, label) {
let userData;
if (config.input.runnerHomeDir) {
// If runner home directory is specified, we expect the actions-runner software (and dependencies)
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
return [
userData = [
'#!/bin/bash',
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
`cd "${config.input.runnerHomeDir}"`,
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
'source pre-runner-script.sh',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];
} else {
return [
userData = [
'#!/bin/bash',
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
'mkdir actions-runner && cd actions-runner',
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
'source pre-runner-script.sh',
Expand All @@ -145036,9 +145038,18 @@ function buildUserDataScript(githubRegistrationToken, label) {
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];
}
if (config.input.runAsUser) {
userData.push(`chown -R ${config.input.runAsUser} .`);
}
if (config.input.runAsService) {
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
userData.push('./svc.sh start');
} else {
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
}
return userData;
}

function buildMarketOptions() {
Expand Down Expand Up @@ -145160,6 +145171,8 @@ class Config {
startupRetryIntervalSeconds: core.getInput('startup-retry-interval-seconds'),
startupTimeoutMinutes: core.getInput('startup-timeout-minutes'),
subnetId: core.getInput('subnet-id'),
runAsService: core.getInput('run-runner-as-service') === 'true',
runAsUser: core.getInput('run-runner-as-user')
};

const tags = JSON.parse(core.getInput('aws-resource-tags'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"dotenv": "^8.6.0",
"eslint": "^7.32.0"
}
}
}
19 changes: 15 additions & 4 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ const config = require('./config');

// User data scripts are run as the root user
function buildUserDataScript(githubRegistrationToken, label) {
let userData;
if (config.input.runnerHomeDir) {
// If runner home directory is specified, we expect the actions-runner software (and dependencies)
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
return [
userData = [
'#!/bin/bash',
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
`cd "${config.input.runnerHomeDir}"`,
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
'source pre-runner-script.sh',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];
} else {
return [
userData = [
'#!/bin/bash',
'exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1',
'mkdir actions-runner && cd actions-runner',
`echo "${config.input.preRunnerScript}" > pre-runner-script.sh`,
'source pre-runner-script.sh',
Expand All @@ -28,9 +30,18 @@ function buildUserDataScript(githubRegistrationToken, label) {
'tar xzf ./actions-runner-linux-${RUNNER_ARCH}-2.313.0.tar.gz',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];
}
if (config.input.runAsUser) {
userData.push(`chown -R ${config.input.runAsUser} .`);
}
if (config.input.runAsService) {
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
userData.push('./svc.sh start');
} else {
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if run.sh supports only running as root then why do we run it under regular user? and if it supported the description of run-runner-as-user parameter should be updated.

and if this is possible why do we need to run it as a service?

also, won't it better to create the user within this script? also add it to sudoers to be closer to github environment?

}
return userData;
}

function buildMarketOptions() {
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Config {
startupRetryIntervalSeconds: core.getInput('startup-retry-interval-seconds'),
startupTimeoutMinutes: core.getInput('startup-timeout-minutes'),
subnetId: core.getInput('subnet-id'),
runAsService: core.getInput('run-runner-as-service') === 'true',
runAsUser: core.getInput('run-runner-as-user')
};

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