GitHub actions- GitHub runners and self hosted runners on AWS EC2

GitHub actions- GitHub runners and self hosted runners on AWS EC2

Introduction

GitHub Actions is a powerful automation platform that simplifies CI/CD workflows. While GitHub-hosted runners are convenient for most scenarios, there are times when you need more control and customization. In such cases, self-hosted runners come to the rescue. In this blog, we'll walk you through setting up self-hosted GitHub Actions runners on an EC2 instance.

Prerequisites

Before getting started, ensure you have the following in place:

  • An AWS account with access to create EC2 instances.

  • A GitHub repository for which you want to set up self-hosted runners.

  • Basic knowledge of GitHub Actions and AWS EC2.

Configuring the Self-Hosted Runner

With the EC2 instance up and running, it's time to configure the self-hosted runner:

  1. SSH into the Instance: Use the key pair you created to SSH into the EC2 instance.

  2. Generate Runner Token: Go to your GitHub repository, navigate to "Settings" > "Actions" > "Self-hosted runners," and click on "Add runner." Follow the instructions to generate a runner token.

  3. Register the Runner: On the EC2 instance, run all the commands.

  4. Start the Runner: After registration, start the runner service to make it available for GitHub Actions.

Using the Self-Hosted Runner

Now that the self-hosted runner is set up, you can use it in your GitHub Actions workflows:

  1. In your repository, create or update your GitHub Actions workflow YAML file to specify the runner you want to use. For example:
jobs:
  build:
    runs-on: [self-hosted]
  1. Push the changes to your repository, and the workflow will use the self-hosted runner you configured on the EC2 instance.

    check this repo - https://github.com/krishkprawat/github-action-self-hosted-runners-

    Thanks for reading..