This script automates the process of setting up an environment with Nginx, Docker, and a GitHub Actions Runner. Below are the steps and explanations for each variable used in the script.
Before running the script, ensure that you have:
- A GitHub account
- Access to a Ubuntu-based server
- Sufficient permissions to execute scripts and install packages
To run the script, use the following command format:
Usage: ./gh-runner.sh --username USERNAME --password PASSWORD --repo-url REPO_URL --folder-name FOLDER_NAME --github-pat GITHUB_PAT --repo-owner REPO_OWNER --repo-name REPO_NAME
--username
: GitHub username--password
: User password--repo-url
: GitHub repository URL--folder-name
: Name of the folder for the project--github-pat
: GitHub Personal Access Token--repo-owner
: Owner of the GitHub repository--repo-name
: Name of the GitHub repository
-
USERNAME
- Description: The username for the new user to be created on the server.
- How to Create: Choose a username that does not already exist on your system.
-
PASSWORD
- Description: The password for the new user.
- How to Create: Create a strong password.
-
REPO_URL
- Description: The URL of your GitHub repository.
- How to Create: Copy the URL from your GitHub repository. It should look like
https://github.com/[username]/[repository]
.
-
FOLDER_NAME
- Description: The name of the folder where the project will be located.
- How to Create: Choose a name for your project directory.
-
GITHUB_PAT
- Description: GitHub Personal Access Token.
- How to Create: Follow the detailed steps provided in the next section.
-
REPO_OWNER
- Description: The owner of the GitHub repository.
- How to Create: This is typically your GitHub username or the organization name that owns the repository.
-
REPO_NAME
- Description: The name of the GitHub repository.
- How to Create: This is the name of your repository on GitHub.
- Log in to your GitHub account.
- Click on your profile picture in the top-right corner of any GitHub page.
- Select Settings from the dropdown menu.
- In the left sidebar of the Settings page, scroll down and click on Developer settings.
- Under Developer settings, select Personal access tokens.
- Click on the Generate new token button.
- Note: Enter a description for your token.
- Expiration: Choose the duration for which the token is valid.
- Select scopes: Scopes control the level of access your token has.
- After selecting the appropriate options, click the Generate token button.
- Copy this token and store it securely.
- Use this token in place of a password when authenticating to GitHub via HTTPS.
- Keep your token confidential and treat it like a password.
- Nginx Installation: Installs the Nginx web server and configures it to start on boot.
- User Creation: Creates a new user with the provided username and password.
- Directory Setup: Creates a project directory and sets appropriate permissions.
- GitHub Actions Runner Setup: Downloads and configures the GitHub Actions Runner for the specified repository.
- Docker Installation: Installs Docker and Docker Compose on the system.
- User Permissions: Adds the new user to the Docker group and configures sudoers for Nginx management.
After running the script, verify that all services are running correctly. You can check the status of Nginx and Docker with the following commands:
sudo systemctl status nginx
sudo systemctl status docker
Ensure that the GitHub Actions Runner appears in your repository's settings under Actions > Runners.