Skip to content

Commit

Permalink
Fix user data script for EC2 instance (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
machulav committed 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

2 comments on commit 816e24c

@snussik
Copy link

@snussik snussik commented on 816e24c Jan 7, 2021

Choose a reason for hiding this comment

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

@machulav glad, that you continue maintaining this action!
In my opinion it's a bad idea to use some definite AMI. For example docker installation for Amazon Linux 2 according to their off.docs is following:
sudo yum update -y
sudo amazon-linux-extras install docker
sudo service docker start
sudo usermod -a -G docker ec2-user

As for my case I also need docker-compose -> it should be installed separately. And so on.

My idea is that its much more simpler to create ami and config it properly as I need with one command:
sudo amazon-linux-extras install -y docker && sudo service docker start && sudo usermod -a -G docker ec2-user && sudo chkconfig docker on && sudo yum install -y git && sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose && docker-compose version

and then just use it with your action.

@machulav
Copy link
Owner Author

Choose a reason for hiding this comment

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

@snussik, let's move the conversation to discussion #18 to make it easier to find.

Please sign in to comment.