Skip to content

Commit

Permalink
Add ability to specify user
Browse files Browse the repository at this point in the history
  • Loading branch information
kpturner authored and esteve committed Jul 12, 2023
1 parent caa5421 commit 04c5c53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ inputs:
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
9 changes: 7 additions & 2 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function buildUserDataScript(githubRegistrationToken, label) {
// to be pre-installed in the AMI, so we simply cd into that directory and then start the runner
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',
Expand All @@ -19,6 +20,7 @@ function buildUserDataScript(githubRegistrationToken, label) {
} else {
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 @@ -29,11 +31,14 @@ function buildUserDataScript(githubRegistrationToken, label) {
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
];
}
if (config.input.runAsUser) {
userData.push(`chown -R ${config.input.runAsUser} ${config.input.runnerHomeDir}`);
}
if (config.input.runAsService) {
userData.push('./svc.sh install');
userData.push(`./svc.sh install ${config.input.runAsUser || ''}`);
userData.push('./svc.sh start');
} else {
userData.push('./run.sh');
userData.push(`${config.input.runAsUser ? `su ${config.input.runAsUser} -c` : ''} ./run.sh`);
}
return userData;
}
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Config {
iamRoleName: core.getInput('iam-role-name'),
runnerHomeDir: core.getInput('runner-home-dir'),
preRunnerScript: core.getInput('pre-runner-script'),
runAsService: core.getInput('run-runner-as-service')
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

0 comments on commit 04c5c53

Please sign in to comment.