Setting Up A Self-Hosted GitHub Action Runner For Python Applications On EC2 Instance
Setting Up A Self-Hosted GitHub Action Runner For Python Applications On EC2 Instance
DeployToCloud
Follow
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 1/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
TABLE OF CONTENTS
📍 Introduction:
📍 GitHub Hosted Runner vs Self-Hosted Runner
📍 Benefits of Self-Hosted Runner for Python Applications
🔹GitHub Repository to follow along:
🔹 Setting up a Self-Hosted Runner using EC2 Instance
🔹 Detailed Configurations for Self-hosted Instance:
🔹 Example of self-hosted runner:
📍 Interview Question related to GitHub Actions:
🔹Why did you choose GitHub Actions over other CI/CD solutions li…
🔹 How do you manage your credentials in GitHub?
🔹 How do you create CI files for GitHub Actions? Explain the steps…
⚜ To create CI files for GitHub Actions, I follow these steps:
🔹 Compare GitHub Actions vs. Jenkins.
📍 Conclusion
📍 Resources:
📍 Introduction:
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 2/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 3/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
Here are some benefits of using self-hosted runners for Python applications:
1. Customization: You can customize the runner environment to match your
application's requirements. For example, you can install specific Python
versions, libraries, and tools.
2. Scalability: You can scale the runner resources, such as CPU, memory, and
storage, to handle large and complex Python applications.
3. Security: You have full control over the runner's security, such as network
access, firewall rules, and encryption.
4. On-premises resources: You can access and use on-premises resources, such
as databases, storage, and services, from your runner.
5. Cost-effective: You can save on costs by using your existing infrastructure and
resources for the runner.
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 4/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
https://github.com/sumanprasad007/gitHub-actions-setup-for-python-app.git
COPY
Replace <USERNAME> and <REPOSITORY> with your GitHub username and repository
name, respectively. Replace <TOKEN> with a personal access token that has the
repo scope.
1. In your repository, go to Settings > Actions > Runners and click on the "Add
new runner" button.
2. Enter a name for the runner and select the operating system, architecture, and
runtime environment that matches your EC2 instance.
3. Copy the registration token and paste it into the EC2 instance terminal when
prompted.
4. Run the ./ run.sh command again to start the runner service.
Now, your self-hosted runner is connected to your repository and ready to run
workflows.
In short, we discussed the benefits of using self-hosted runners for Python
applications and how to set them up using an EC2 instance. By using Configuring
the self-hosted runner is relatively easy and can be done by following the below
steps:
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 6/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
Once the self-hosted runner is set up, you can use it to run your workflows on your
EC2 instance. In the workflow file, you can specify the runs-on parameter as the
name of the self-hosted runner.
For example, if you have named your runner "my-runner", you can specify it in your
workflow file like this:
on: [push]
jobs:
build:
runs-on: self-hosted
# runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 8/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
This will ensure that your workflow runs on the self-hosted runner instead of the
GitHub-hosted runner i.e. self-hosted-runner.yml.
GitHub Actions and Jenkins are both popular CI/CD tools that can be used for
building, testing, and deploying software applications. However, GitHub Actions is
a newer tool and provides tighter integration with GitHub, while Jenkins is a more
mature tool with a larger ecosystem of plugins and integrations. GitHub Actions
also provides a more intuitive and user-friendly interface, while Jenkins requires
more configuration and setup. Additionally, GitHub Actions provides the ability to
set up self-hosted runners for better customization and control, while Jenkins
requires the setup of additional infrastructure.
📍 Conclusion
In conclusion, self-hosted runners provide a lot of flexibility and customization
options for building and testing your applications. Using an EC2 instance to set up
a self-hosted runner is a great way to get started with GitHub Actions. With this
guide and the code snippets provided, you should be able to easily set up and use
self-hosted runners for your Python applications.
📍 Resources:
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 11/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
GITHUB ACTIONS SELF HOSTED RUNNERS | ADD THIS PROJECT TO YOUR RESU
#
Join the community of learners and be a part of the conversation! Your
feedback is valuable to us, so please share your thoughts in the comments
section. Help us make this blog even better for everyone. And if you found
this post helpful, spread the word! Share it with those who could benefit
from the information. And don't forget to follow along and subscribe to our
newsletter for instant updates on our latest content. Thank you for taking the
time to read and engage with us!
Subscribe to my newsletter
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 12/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
Read articles from DeployToCloud directly inside your inbox. Subscribe to the
newsletter, and don't miss out.
Enter your email address SUBSCRIBE
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 13/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
WRITTEN BY
Suman Prasad
Follow
MORE ARTICLES
Suman Prasad
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 14/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
Suman Prasad
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 15/16
5/7/23, 9:08 PM Setting up a Self-Hosted GitHub Action Runner for Python Applications on EC2 Instance
https://sumanprasad.hashnode.dev/setting-up-a-self-hosted-github-action-runner-for-python-applications-on-ec2-instance 16/16