You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# On-demand self-hosted EC2 runner for GitHub Actions
1
+
# On-demand self-hosted AWS EC2 runner for GitHub Actions
2
2
3
-
Using this GitHub action, you can start a new EC2 instance and register it as a [self-hosted runner in GitHub](https://docs.github.com/en/free-pro-team@latest/actions/hosting-your-own-runners) right before you need it. Then run all the required jobs on it and stop it when you don't need it anymore.
3
+
Start your EC2 [self-hosted runner](https://docs.github.com/en/free-pro-team@latest/actions/hosting-your-own-runners) right before you need it.
-[Self-hosted runner security with public repositories](self-hosted-runner-security-with-public-repositories)
12
18
-[License Summary](#license-summary)
13
19
14
20
## Usage
15
21
22
+
### How to start
23
+
24
+
Use the following steps to prepare your workflow for running on your EC2 self-hosted runner:
25
+
26
+
**1. Prepare AWS access keys**
27
+
28
+
1. Create new AWS access keys with the following least-privilege permissions.
29
+
The action will use the keys for EC2 instance management in the AWS account.
30
+
31
+
```
32
+
{
33
+
"Version": "2012-10-17",
34
+
"Statement": [
35
+
{
36
+
"Effect": "Allow",
37
+
"Action": [
38
+
"ec2:RunInstances",
39
+
"ec2:TerminateInstances",
40
+
"ec2:DescribeInstances",
41
+
"ec2:DescribeInstanceStatus"
42
+
],
43
+
"Resource": "*"
44
+
}
45
+
]
46
+
}
47
+
```
48
+
49
+
2. Add the keys to GitHub secrets.
50
+
3. Use the [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) action to put the keys into environment variables.
51
+
52
+
**2. Prepare GitHub personal access token**
53
+
54
+
1. Create a new GitHub personal access token with the `repo` scope.
55
+
The action will use the token for self-hosted runners management in the GitHub account on the repository level.
56
+
2. Add the token to GitHub secrets.
57
+
58
+
**3. Prepare EC2 image**
59
+
60
+
1. Create a new EC2 image (AMI) from the Linux distribution you need.
61
+
You don't need to install anything special beforehand into the AMI.
62
+
The action will install all the necessary tools during the EC2 instance creation.
63
+
64
+
**4. Configure the GitHub workflow**
65
+
66
+
1. Create a new GitHub Actions workflow or edit the existing one.
67
+
2. Use the documentation and example below to configure your workflow.
68
+
3. Please don't forget to set up a job for removing the EC2 instance at the end of the workflow execution.
69
+
Otherwise, the EC2 instance won't be removed and continue to run even after the workflow execution is finished.
|`mode`| Always.| Specify here which mode you want to use:<br>- `start` - to start a new runner;<br>- `stop` - to stop the previously created runner. |
21
-
|`github-token`| Always.|GitHub Personal Access Token with a`repo` scope assigned.|
22
-
|`ec2-image-id`| Required if you use the `start` mode. | EC2 AMI Id. <br><br> The new runner will be launched from this image. The action is compatible only with Linux images.|
23
-
|`ec2-instance-type`| Required if you use the `start` mode. | EC2 Instance Type. |
24
-
|`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. |
25
-
|`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. <br><br> The runner doesn't require any inbound traffic. However, outbound traffic should be allowed. |
26
-
|`label`| Required if you use the `stop` mode. | Name of the unique label assigned to the runner. <br><br> The label is used to remove the runner from GitHub when the runner is not needed anymore. |
27
-
|`ec2-instance-id`| Required if you use the `stop` mode. | EC2 Instance Id of the created runner. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
|`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. |
78
+
|`github-token`| Always required. |GitHub Personal Access Token with the`repo` scope assigned. |
79
+
|`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. |
80
+
|`ec2-instance-type`| Required if you use the `start` mode. | EC2 Instance Type. |
81
+
|`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. |
82
+
|`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. <br><br> The runner doesn't require any inbound traffic. However, outbound traffic should be allowed. |
83
+
|`label`| Required if you use the `stop` mode. | Name of the unique label assigned to the runner. <br><br> The label is used to remove the runner from GitHub when the runner is not needed anymore. |
84
+
|`ec2-instance-id`| Required if you use the `stop` mode. | EC2 Instance Id of the created runner. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
28
85
29
86
### Environment variables
30
87
@@ -39,18 +96,14 @@ We recommend using [aws-actions/configure-aws-credentials](https://github.com/aw
|`label`| Name of the unique label assigned to the runner. <br><br> The label is used in two cases: <br> - to use as the input of `runs-on` property for the following jobs; <br> - to remove the runner from GitHub when it is not needed anymore. |
45
-
|`ec2-instance-id`| EC2 Instance Id of the created runner. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
|`label`| Name of the unique label assigned to the runner. <br><br> The label is used in two cases: <br> - to use as the input of `runs-on` property for the following jobs; <br> - to remove the runner from GitHub when it is not needed anymore. |
102
+
|`ec2-instance-id`| EC2 Instance Id of the created runner. <br><br> The id is used to terminate the EC2 instance when the runner is not needed anymore. |
46
103
47
104
### Example
48
105
49
-
In the following example, you can see how to start your EC2 self-hosted runner right before the job should be done, run the job on it, and then stop it at the end when you finish:
## Self-hosted runner security with public repositories
165
+
166
+
We recommend that you do not use self-hosted runners with public repositories.
167
+
168
+
Forks of your public repository can potentially run dangerous code on your self-hosted runner machine by creating a pull request that executes the code in a workflow.
169
+
170
+
Please find more details about this security note on [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/actions/hosting-your-own-runners/about-self-hosted-runners#self-hosted-runner-security-with-public-repositories).
171
+
111
172
## License Summary
112
173
113
-
This code is made available under the MIT license.
174
+
This code is made available under the [MIT license](LICENSE).
0 commit comments