|
| 1 | +--- |
| 2 | +title: Deploy GitHub Self-Hosted Runner on Google Axion C4A VM |
| 3 | +weight: 4 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +## Deploy GitHub Actions Self-Hosted Runner on Google Axion C4A VM and Automate NGINX Deployment. |
| 11 | + |
| 12 | +This Learning Path shows how to deploy a self-hosted GitHub Actions runner on a Google Cloud C4A Arm64 VM running Ubuntu. It covers installing Git and GitHub CLI, authenticating with GitHub, configuring the runner, and automating NGINX deployment using GitHub Actions—all on an Arm64 environment for optimized CI/CD workflows. |
| 13 | + |
| 14 | +### Install Git and GitHub CLI |
| 15 | +```console |
| 16 | +$ sudo apt update |
| 17 | +$ sudo apt install -y git gh |
| 18 | +``` |
| 19 | +Login to GitHub |
| 20 | +```console |
| 21 | +$ gh auth login |
| 22 | + ``` |
| 23 | +The command `gh auth login` is used to authenticate the GitHub CLI with your GitHub account. It allows you to securely log in using a web browser or token, enabling the CLI to interact with repositories, actions, and other GitHub features on your behalf. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +Below is the GitHub login UI: |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +### Test GitHub CLI and Git |
| 32 | +Create a test repo: |
| 33 | +```console |
| 34 | +$ gh repo create test-repo –public |
| 35 | +``` |
| 36 | +Output: |
| 37 | +```output |
| 38 | +✓ Created repository <your-github-account>/test-repo on GitHub |
| 39 | + https://github.com/<your-github-account>/test-repo |
| 40 | +``` |
| 41 | + |
| 42 | +The command `gh repo create test-repo --public` creates a new public GitHub repository named **test-repo** using the GitHub CLI. It sets the repository visibility to public, meaning anyone can view it |
| 43 | + |
| 44 | +### Configure the Self-Hosted Runner |
| 45 | +Go to your repository's **Settings > Actions**, and under the **Runners** section, click on **Add Runner** or view existing self-hosted runners. |
| 46 | +If the **Actions** tab is not visible, ensure Actions are enabled by navigating to **Settings > Actions > General**, and select **Allow all actions and reusable workflows**. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +Then, click on the **New runner** button, followed by **New self-hosted runner**. In the **Add new self-hosted runner** section, proceed as follows: |
| 51 | +- Select Linux for the operating system. |
| 52 | +- Choose ARM64 for the architecture |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +Next, execute the following instructions on your Google Axion C4A VM: |
| 57 | +```console |
| 58 | +$ mkdir actions-runner && cd actions-runner# Download the latest runner package |
| 59 | +$ curl -o actions-runner-linux-arm64-2.326.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.326.0/actions-runner-linux-arm64-2.326.0.tar.gz |
| 60 | +$ echo "ee7c229c979c5152e9f12be16ee9e83ff74c9d9b95c3c1aeb2e9b6d07157ec85 actions-runner-linux-arm64-2.326.0.tar.gz" | shasum -a 256 -c# Extract the installer |
| 61 | +$ tar xzf ./actions-runner-linux-arm64-2.326.0.tar.gz |
| 62 | +``` |
| 63 | +Then, configure the VM with the following command: |
| 64 | + |
| 65 | +```console |
| 66 | +$ ./config.sh --url https://github.com/<YOUR_USERNAME>/YOUR_REPO --token YOUR_TOKEN |
| 67 | +``` |
| 68 | +Replace `YOUR_USERNAME`, `YOUR_REPO`, and `YOUR_TOKEN` accordingly. |
| 69 | +This command links the runner to your GitHub repo using a one-time registration token. |
| 70 | + |
| 71 | +During the command’s execution, you will be prompted to provide the runner group, the name of the runner, and the work folder name. You can accept the defaults by pressing **Enter** at each step. The output will resemble as below: |
| 72 | + |
| 73 | +Output: |
| 74 | + |
| 75 | +```output |
| 76 | +-------------------------------------------------------------------------------- |
| 77 | +| ____ _ _ _ _ _ _ _ _ | |
| 78 | +| / ___(_) |_| | | |_ _| |__ / \ ___| |_(_) ___ _ __ ___ | |
| 79 | +| | | _| | __| |_| | | | | '_ \ / _ \ / __| __| |/ _ \| '_ \/ __| | |
| 80 | +| | |_| | | |_| _ | |_| | |_) | / ___ \ (__| |_| | (_) | | | \__ \ | |
| 81 | +| \____|_|\__|_| |_|\__,_|_.__/ /_/ \_\___|\__|_|\___/|_| |_|___/ | |
| 82 | +| | |
| 83 | +| Self-hosted runner registration | |
| 84 | +| | |
| 85 | +-------------------------------------------------------------------------------- |
| 86 | +
|
| 87 | +# Authentication |
| 88 | +
|
| 89 | +√ Connected to GitHub |
| 90 | +# Runner Registration |
| 91 | +Enter the name of the runner group to add this runner to: [press Enter for Default] |
| 92 | +Enter the name of runner: [press Enter for lpprojectubuntuarm64] |
| 93 | +This runner will have the following labels: 'self-hosted', 'Linux', 'ARM64' |
| 94 | +Enter any additional labels (ex. label-1,label-2): [press Enter to skip] |
| 95 | +√ Runner successfully added |
| 96 | +√ Runner connection is good |
| 97 | +``` |
| 98 | + |
| 99 | +Finally, start the runner by executing: |
| 100 | +```console |
| 101 | +$ ./run.sh |
| 102 | +``` |
| 103 | +Output: |
| 104 | + |
| 105 | +```output |
| 106 | +√ Connected to GitHub |
| 107 | +
|
| 108 | +Current runner version: '2.326.0' |
| 109 | +2025-07-15 05:51:13Z: Listening for Jobs |
| 110 | +``` |
| 111 | +The runner will now be visible in the GitHub actions: |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +## Deploy NGINX Using GitHub Actions |
| 116 | +This workflow installs and starts the NGINX web server on a self-hosted runner whenever code is pushed to the main branch. |
| 117 | + |
| 118 | +Create the Workflow: |
| 119 | +Create a workflow file at `.github/workflows/deploy-nginx.yaml` with the following content: |
| 120 | + |
| 121 | +```yaml |
| 122 | + |
| 123 | +name: Deploy NGINX |
| 124 | + |
| 125 | +on: |
| 126 | + push: |
| 127 | + branches: [ main ] |
| 128 | + |
| 129 | +jobs: |
| 130 | + deploy: |
| 131 | + runs-on: self-hosted |
| 132 | + steps: |
| 133 | + - name: Install NGINX |
| 134 | + run: | |
| 135 | + sudo apt update |
| 136 | + sudo apt install -y nginx |
| 137 | +
|
| 138 | + - name: Start NGINX |
| 139 | + run: sudo systemctl start nginx |
| 140 | +``` |
| 141 | +### commit and Push: |
| 142 | +
|
| 143 | + ```console |
| 144 | +$ git add . |
| 145 | +$ git commit -m "Add NGINX deploy workflow" |
| 146 | +$ git push origin main |
| 147 | +``` |
| 148 | +### Access the NGINX Server |
| 149 | +Once the workflow completes, open your browser and navigate to: |
| 150 | +``` |
| 151 | +http://<your-public-IP> |
| 152 | +``` |
| 153 | +You should see the NGINX welcome page confirming a successful deployment. |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
0 commit comments