Skip to content

Commit

Permalink
Fix user data script for EC2 instance (machulav#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
machulav authored Jan 7, 2021
1 parent 6a59c21 commit 816e24c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Use the following steps to prepare your workflow for running on your EC2 self-ho

**3. Prepare EC2 image**

1. Create a new EC2 image (AMI) from the Linux distribution you need.
1. Create a new EC2 image (AMI) based on Amazon Linux 2.
You don't need to install anything special beforehand into the AMI.
The action will install all the necessary tools during the EC2 instance creation.

Expand Down Expand Up @@ -120,7 +120,7 @@ Now you're ready to go!
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode` | Always required. | Specify here which mode you want to use:<br>- `start` - to start a new runner;<br>- `stop` - to stop the previously created runner. |
| `github-token` | Always required. | GitHub Personal Access Token with the `repo` scope assigned. |
| `ec2-image-id` | Required if you use the `start` mode. | EC2 Image Id (AMI). <br><br> The new runner will be launched from this image. The action is compatible only with Linux images. |
| `ec2-image-id` | Required if you use the `start` mode. | EC2 Image Id (AMI). <br><br> The new runner will be launched from this image. The action is compatible with Amazon Linux 2 images. |
| `ec2-instance-type` | Required if you use the `start` mode. | EC2 Instance Type. |
| `subnet-id` | Required if you use the `start` mode. | VPC Subnet Id. The subnet should belong to the same VPC as the specified security group. |
| `security-group-id` | Required if you use the `start` mode. | EC2 Security Group Id. <br><br> The security group should belong to the same VPC as the specified subnet. |
Expand Down
15 changes: 10 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55088,16 +55088,21 @@ const config = __webpack_require__(34570);
async function startEc2Instance(label, githubRegistrationToken) {
const ec2 = new AWS.EC2();

// user data scripts are run as the root user
// Docker is required for running Docker container actions
const 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',
'yum update -y',
'yum install docker -y',
'yum install git -y',
'service docker start',
'mkdir actions-runner && cd actions-runner',
'curl -O -L https://github.com/actions/runner/releases/download/v2.274.2/actions-runner-linux-x64-2.274.2.tar.gz',
'tar xzf ./actions-runner-linux-x64-2.274.2.tar.gz',
'useradd github',
'chown -R github:github /actions-runner',
`su github -c "./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}"`,
'su github -c "./run.sh"',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];

const params = {
Expand Down
15 changes: 10 additions & 5 deletions src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ const config = require('./config');
async function startEc2Instance(label, githubRegistrationToken) {
const ec2 = new AWS.EC2();

// user data scripts are run as the root user
// Docker is required for running Docker container actions
const 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',
'yum update -y',
'yum install docker -y',
'yum install git -y',
'service docker start',
'mkdir actions-runner && cd actions-runner',
'curl -O -L https://github.com/actions/runner/releases/download/v2.274.2/actions-runner-linux-x64-2.274.2.tar.gz',
'tar xzf ./actions-runner-linux-x64-2.274.2.tar.gz',
'useradd github',
'chown -R github:github /actions-runner',
`su github -c "./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}"`,
'su github -c "./run.sh"',
'export RUNNER_ALLOW_RUNASROOT=1',
`./config.sh --url https://github.com/${config.githubContext.owner}/${config.githubContext.repo} --token ${githubRegistrationToken} --labels ${label}`,
'./run.sh',
];

const params = {
Expand Down

0 comments on commit 816e24c

Please sign in to comment.