Skip to content

Commit 5d84fa5

Browse files
committed
testing
1 parent 08ea391 commit 5d84fa5

File tree

1 file changed

+37
-43
lines changed

1 file changed

+37
-43
lines changed

github-runner/node-runner.sh

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,83 @@
11
#!/usr/bin/env bash
22

3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
#
7+
# OpenCRVS is also distributed under the terms of the Civil Registration
8+
# & Healthcare Disclaimer located at http://opencrvs.org/license.
9+
#
10+
# Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11+
312
printf """
413
-----------------------------------
514
▶️ Running Node runner setup script
615
-----------------------------------
7-
816
"""
917

10-
1118
set -o errexit # Stop on error (like `-e`)
1219
set -o nounset # Stop on unset vars (like `-u`)
1320
set -o pipefail # Fail on first failed command in a pipeline
1421
set -o errtrace # Trap ERR in functions and subshells
1522

1623
trap 'echo "❌ Script failed on line $LINENO with exit code $?"' ERR
1724

18-
# --- DEFAULTS ---
19-
RUNNER_DIR="/opt/github-runner"
20-
RUNAS_USER="provision"
21-
RUNAS_GROUP="application"
2225
# --- USAGE ---
2326
usage() {
24-
echo "Usage: $0 [OPTIONS]"
25-
echo ""
26-
echo "Options:"
27-
echo " --owner GitHub org or username (required)"
28-
echo " --repo GitHub repository name (optional for org-level runner)"
29-
echo " --token GitHub PAT or registration token (required)"
30-
echo " --scope 'repo' or 'org' (default: repo)"
31-
echo " --name Runner name (default: <hostname>-runner)"
32-
echo " --labels Comma-separated list of runner labels"
33-
echo " --dir Runner install directory (default: /opt/github-runner)"
34-
echo " --env infrastructure environment name"
35-
echo " -h, --help Show this help message"
36-
echo ""
27+
echo """
28+
Usage: $0 [OPTIONS]
29+
30+
Options:
31+
--owner GitHub org or username (required)
32+
--repo GitHub repository name (required)
33+
--env Infrastructure environment name(s) comma-separated (required)
34+
Runner will be used to provision infrastructure for these envs
35+
For example: dev,qa,staging or prod
36+
--token GitHub PAT or registration token (required)
37+
--name Runner name (default: <hostname>-runner)
38+
--dir Runner install directory (default: /opt/github-runner)
39+
-h, --help Show this help message
40+
"""
3741
exit 1
3842
}
3943

4044
# --- PARSE OPTIONS ---
41-
SCOPE="repo"
4245
while [[ $# -gt 0 ]]; do
4346
case "$1" in
4447
--owner) GITHUB_OWNER="$2"; shift 2 ;;
4548
--repo) REPO_NAME="$2"; shift 2 ;;
4649
--token) GITHUB_TOKEN="$2"; shift 2 ;;
47-
--scope) SCOPE="$2"; shift 2 ;;
48-
--name) RUNNER_NAME="$2"; shift 2 ;;
49-
--labels) LABELS="$2"; shift 2 ;;
5050
--dir) RUNNER_DIR="$2"; shift 2 ;;
5151
--env) ENV="$2"; shift 2 ;;
5252
--runas-user) RUNAS_USER="$2"; shift 2 ;;
5353
--runas-group) RUNAS_GROUP="$2"; shift 2 ;;
54+
--name) RUNNER_NAME="$2"; shift 2 ;;
5455
-h|--help) usage ;;
5556
*) echo "Unknown option: $1"; usage ;;
5657
esac
5758
done
5859

5960
# --- INTERACTIVE PROMPTS (IF NOT SET) ---
60-
[[ -z "${ENV:-}" ]] && read -rp "Infrastructure environment name: " ENV
6161
[[ -z "${GITHUB_OWNER:-}" ]] && read -rp "GitHub owner (or org): " GITHUB_OWNER
62-
[[ "${SCOPE}" == "repo" && -z "${REPO_NAME:-}" ]] && read -rp "Repository name: " REPO_NAME
62+
[[ -z "${REPO_NAME:-}" ]] && read -rp "Repository name: " REPO_NAME
63+
[[ -z "${ENV:-}" ]] && read -rp "Infrastructure environment name(s): " ENV
6364
[[ -z "${GITHUB_TOKEN:-}" ]] && read -rsp "GitHub token (no echo): " GITHUB_TOKEN && echo
64-
[[ -z "${SCOPE:-}" ]] && read -rp "Scope (repo|org) [repo]: " SCOPE && SCOPE="${SCOPE:-repo}"
65-
[[ -z "${RUNNER_NAME:-}" ]] && RUNNER_NAME="$(hostname)-runner"
6665

67-
# --- Add runner labels ---
66+
# --- OPTIONAL DETERMINE (IF NOT SET) ---
67+
# Runner install directory
68+
RUNNER_DIR=${RUNNER_DIR:-"/opt/github-runner"}
69+
# Runner name
70+
[[ -z "${RUNNER_NAME:-}" ]] && RUNNER_NAME="$(hostname)-runner"
71+
# Runner labels
6872
LABELS="self-hosted,linux,node,${ENV}"
69-
70-
# --- DETERMINE USER/GROUP TO RUN AS ---
73+
# Runner user and group
7174
RUNAS_USER="${RUNAS_USER:-provision}"
7275
RUNAS_GROUP="${RUNAS_GROUP:-application}"
7376

77+
7478
# --- DETERMINE REGISTRATION URL ---
75-
if [[ "$SCOPE" == "org" ]]; then
76-
REG_URL="https://api.github.com/orgs/${GITHUB_OWNER}/actions/runners/registration-token"
77-
RUNNER_SCOPE="https://github.com/${GITHUB_OWNER}"
78-
elif [[ "$SCOPE" == "repo" ]]; then
79-
REG_URL="https://api.github.com/repos/${GITHUB_OWNER}/${REPO_NAME}/actions/runners/registration-token"
80-
RUNNER_SCOPE="https://github.com/${GITHUB_OWNER}/${REPO_NAME}"
81-
else
82-
echo "Invalid SCOPE value. Must be 'repo' or 'org'."
83-
exit 1
84-
fi
79+
REG_URL="https://api.github.com/repos/${GITHUB_OWNER}/${REPO_NAME}/actions/runners/registration-token"
80+
RUNNER_SCOPE="https://github.com/${GITHUB_OWNER}/${REPO_NAME}"
8581

8682
# --- INSTALL DEPENDENCIES ---
8783
echo "[+] Installing dependencies..."
@@ -139,9 +135,8 @@ echo "[+] Installing systemd service..."
139135

140136
sudo ./svc.sh install
141137

142-
# Detect the systemd service name
138+
# Fix service to run as specific user/group
143139
SERVICE_FILE_PATH=$(ls /etc/systemd/system/actions.runner.*.service 2>/dev/null | head -n1)
144-
145140
if [[ -n "$SERVICE_FILE_PATH" ]]; then
146141
echo "[+] Updating systemd unit to run as ${RUNAS_USER}:${RUNAS_GROUP}..."
147142
sudo sed -i "s/^User=.*/User=${RUNAS_USER}/" "$SERVICE_FILE_PATH"
@@ -151,7 +146,6 @@ else
151146
echo "⚠️ Could not find service file automatically — please verify installation."
152147
fi
153148

154-
155149
sudo ./svc.sh start
156150

157151
echo "✅ Runner '${RUNNER_NAME}' is installed and started!"

0 commit comments

Comments
 (0)