Skip to content

Commit

Permalink
init runner as ec2-user
Browse files Browse the repository at this point in the history
add pre script to setup tools before running the runner
  • Loading branch information
arielly-parussulo committed May 30, 2023
1 parent 26e9e1e commit 548f106
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 114 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/package.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/pr.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ inputs:
description: >-
The host id to provide a dedicated host in your account. It is necessary for macos instances.
required: false
pre-script:
description: >-
A script that will be executed before starting the Github Runner.
required: false
timeout:
description:
The time (in minutes) that this actions will wait the the runner be created. The default value is 5 minutes.
Expand Down
53 changes: 31 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62807,28 +62807,36 @@ function buildUserDataScript(githubRegistrationToken, label) {
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 [
'#!/bin/bash',
`cd "${config.input.runnerHomeDir}"`,
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work "${config.input.runnerHomeDir}" --replace`,
'./run.sh',
];
return ```
#!/bin/bash

${config.input.preScript}

su ec2-user -c 'echo "export RUNNER_ALLOW_RUNASROOT=1" >> $HOME/.zshrc'
su ec2-user -c '${config.input.runnerHomeDir}/./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work "${config.input.runnerHomeDir}" --replace'
su ec2-user -c '${config.input.runnerHomeDir}/./run.sh'
```
} else {
return [
'#!/bin/bash',
'cd /opt && mkdir actions-runner && cd actions-runner',
'case $(uname -m) in aarch64|arm64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}',
'case $(uname -a) in Darwin*) OS="osx" ;; Linux*) OS="linux" ;; esac && export RUNNER_OS=${OS}',
'export VERSION="2.303.0"',
'curl -O -L https://github.com/actions/runner/releases/download/v${VERSION}/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz',
'export LC_ALL=en_US.UTF-8',
'export LANG=en_EN.UTF-8',
'tar xzf ./actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work $(pwd) --replace`,
'./run.sh',
];
return ```
#!/bin/bash

${config.input.preScript}

case $(uname -m) in aarch64|arm64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}
case $(uname -a) in Darwin*) OS="osx" ;; Linux*) OS="linux" ;; esac && export RUNNER_OS=${OS}
export VERSION="2.303.0"

su ec2-user -c "curl -O -L https://github.com/actions/runner/releases/download/v${VERSION}/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz -o /tmp/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz"
su ec2-user -c 'echo "export LC_ALL=en_US.UTF-8" >> $HOME/.zshrc'
su ec2-user -c 'echo "export LANG=en_US.UTF-8" >> $HOME/.zshrc'
su ec2-user -c 'echo "export RUNNER_ALLOW_RUNASROOT=1" >> $HOME/.zshrc'
su ec2-user -c 'mkdir /tmp/actions-runner'
su ec2-user -c "tar xzf /tmp/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz -C /tmp/actions-runner --strip-components=1"
su ec2-user -c 'mv /tmp/actions-runner $HOME/actions-runner'
tar xzf ./actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz
su ec2-user -c '$HOME/actions-runner/./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work $(pwd) --replace'
su ec2-user -c '$HOME/actions-runner/./run.sh &'
```;
}
}

Expand All @@ -62843,7 +62851,7 @@ async function startEc2Instance(label, githubRegistrationToken) {
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
UserData: Buffer.from(userData).toString('base64'),
SubnetId: config.input.subnetId,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
Expand Down Expand Up @@ -62932,6 +62940,7 @@ class Config {
runnerHomeDir: core.getInput('runner-home-dir'),
scope: core.getInput('scope'),
hostId: core.getInput('host-id'),
preScript: core.getInput('pre-script') || '',
};

this.GITHUB_SCOPES = {
Expand Down
52 changes: 30 additions & 22 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@ function buildUserDataScript(githubRegistrationToken, label) {
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 [
'#!/bin/bash',
`cd "${config.input.runnerHomeDir}"`,
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work "${config.input.runnerHomeDir}" --replace`,
'./run.sh',
];
return ```
#!/bin/bash
${config.input.preScript}
su ec2-user -c 'echo "export RUNNER_ALLOW_RUNASROOT=1" >> $HOME/.zshrc'
su ec2-user -c '${config.input.runnerHomeDir}/./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work "${config.input.runnerHomeDir}" --replace'
su ec2-user -c '${config.input.runnerHomeDir}/./run.sh'
```
} else {
return [
'#!/bin/bash',
'cd /opt && mkdir actions-runner && cd actions-runner',
'case $(uname -m) in aarch64|arm64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}',
'case $(uname -a) in Darwin*) OS="osx" ;; Linux*) OS="linux" ;; esac && export RUNNER_OS=${OS}',
'export VERSION="2.303.0"',
'curl -O -L https://github.com/actions/runner/releases/download/v${VERSION}/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz',
'export LC_ALL=en_US.UTF-8',
'export LANG=en_EN.UTF-8',
'tar xzf ./actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work $(pwd) --replace`,
'./run.sh',
];
return ```
#!/bin/bash
${config.input.preScript}
case $(uname -m) in aarch64|arm64) ARCH="arm64" ;; amd64|x86_64) ARCH="x64" ;; esac && export RUNNER_ARCH=${ARCH}
case $(uname -a) in Darwin*) OS="osx" ;; Linux*) OS="linux" ;; esac && export RUNNER_OS=${OS}
export VERSION="2.303.0"
su ec2-user -c "curl -O -L https://github.com/actions/runner/releases/download/v${VERSION}/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz -o /tmp/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz"
su ec2-user -c 'echo "export LC_ALL=en_US.UTF-8" >> $HOME/.zshrc'
su ec2-user -c 'echo "export LANG=en_US.UTF-8" >> $HOME/.zshrc'
su ec2-user -c 'echo "export RUNNER_ALLOW_RUNASROOT=1" >> $HOME/.zshrc'
su ec2-user -c 'mkdir /tmp/actions-runner'
su ec2-user -c "tar xzf /tmp/actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz -C /tmp/actions-runner --strip-components=1"
su ec2-user -c 'mv /tmp/actions-runner $HOME/actions-runner'
tar xzf ./actions-runner-${RUNNER_OS}-${RUNNER_ARCH}-${VERSION}.tar.gz
su ec2-user -c '$HOME/actions-runner/./config.sh --url ${config.github.url} --token ${githubRegistrationToken} --labels ${label} --name ${label} --runnergroup default --work $(pwd) --replace'
su ec2-user -c '$HOME/actions-runner/./run.sh &'
```;
}
}

Expand All @@ -43,7 +51,7 @@ async function startEc2Instance(label, githubRegistrationToken) {
InstanceType: config.input.ec2InstanceType,
MinCount: 1,
MaxCount: 1,
UserData: Buffer.from(userData.join('\n')).toString('base64'),
UserData: Buffer.from(userData).toString('base64'),
SubnetId: config.input.subnetId,
SecurityGroupIds: [config.input.securityGroupId],
IamInstanceProfile: { Name: config.input.iamRoleName },
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Config {
runnerHomeDir: core.getInput('runner-home-dir'),
scope: core.getInput('scope'),
hostId: core.getInput('host-id'),
preScript: core.getInput('pre-script') || '',
};

this.GITHUB_SCOPES = {
Expand Down

0 comments on commit 548f106

Please sign in to comment.