SP: GitHub runner as service and able to toggle via developer panel (#494)

* Add support for GitHub Actions runner management

Introduce a new process and configuration to manage a GitHub Actions runner. Added a persistent "EnableGithubRunner" parameter and a script to control the runner service. Integrated the feature into the system's process manager logic.

* Restrict GitHub runner usage on metered networks.

This update modifies the `use_github_runner` function to include a check for metered networks using `HARDWARE.get_network_metered()`. This ensures the GitHub runner is not enabled when the network is metered, improving network usage efficiency.

* Add GitHub runner service toggle to developer panel

Introduces a new toggle in the developer panel to enable or disable the GitHub runner service. This provides developers with a convenient way to control the service from the UI.

* translations

* Refactor network condition check for GitHub runner.

Updated `use_github_runner` to include network type in metered network checks. This ensures more accurate validation by considering specific network types when determining metered status.

* Mark as executable

* Update paths and shebangs for consistency across scripts

Modified file paths to align with the new directory structure under `/data/media/0/github` and updated the shebang in `github_runner.sh` for better environment compatibility. Adjusted the `BUILD_DIR` in the GitHub workflow to reflect the new path.

* Fix string translation for GitHub runner parameter text

Added translation support for the GitHub runner service description text. This ensures consistent localization across the UI.

* Remove gitlab_runner.sh from Sunnypilot blacklist.

The script is no longer required to be blacklisted, likely due to updates or changes in its usage. This improves the maintainability of the blacklist by removing unnecessary entries.

* lang stuff

* Update BASE_DIR determination based on mount point

Refactored scripts to dynamically set BASE_DIR depending on whether /data/media is a valid mount point. This ensures compatibility with different environments and improves robustness of path resolution.

* Refactor GitHub runner logic in process_config.

Simplified enabling conditions for the GitHub runner by removing dependency on hardware network checks and adding a logical combination of offroad and runner-related functions. This improves code readability and reduces hardware coupling.
This commit is contained in:
DevTekVE
2024-12-23 09:19:26 +01:00
committed by GitHub
parent cd73feec57
commit 0bfa9fca88
19 changed files with 153 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
name: Build Model from Upstream
env:
BUILD_DIR: "/data/github/openpilot"
BUILD_DIR: "/data/openpilot"
OUTPUT_DIR: ${{ github.workspace }}/output
SCONS_CACHE_DIR: ${{ github.workspace }}/release/ci/scons_cache
UPSTREAM_REPO: "commaai/openpilot"

View File

@@ -200,6 +200,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"UpdaterTargetBranch", CLEAR_ON_MANAGER_START},
{"UpdaterLastFetchTime", PERSISTENT},
{"Version", PERSISTENT},
{"EnableGithubRunner", PERSISTENT},
};
} // namespace

View File

@@ -44,10 +44,16 @@ fi
# Set repository URL if not provided
REPO_URL="${REPO_URL:-$DEFAULT_REPO_URL}"
# Determine BASE_DIR based on mount point
if mountpoint -q /data/media; then
BASE_DIR="/data/media/0/github"
else
BASE_DIR="/data/github"
fi
# Constants
RUNNER_USER="github-runner"
USER_GROUPS="comma,gpu,gpio,sudo"
BASE_DIR="/data/github"
RUNNER_DIR="${BASE_DIR}/runner"
BUILDS_DIR="${BASE_DIR}/builds"
LOGS_DIR="${BASE_DIR}/logs"

View File

@@ -1,6 +1,12 @@
#!/usr/bin/env bash
# Determine BASE_DIR based on mount point
if mountpoint -q /data/media; then
GITHUB_BASE_DIR="/data/media/0/github"
else
GITHUB_BASE_DIR="/data/github"
fi
# Define directories and user
GITHUB_BASE_DIR="/data/github"
BIN_DIR="$GITHUB_BASE_DIR/bin"
BUILDS_DIR="$GITHUB_BASE_DIR/builds"
OPENPILOT_DIR="$GITHUB_BASE_DIR/openpilot"

View File

@@ -51,7 +51,6 @@ blacklist = [
# Sunnypilot blacklist
sunnypilot_blacklist = [
"system/loggerd/sunnylink_uploader.py", # Temporarily, until we are ready to roll it out widely
"system/manager/gitlab_runner.sh",
".idea/",
".run/",
".*__pycache__/.*",

View File

@@ -24,6 +24,9 @@ DeveloperPanel::DeveloperPanel(SettingsWindow *parent) : ListWidget(parent) {
});
addItem(longManeuverToggle);
auto enableGithubRunner = new ParamControl("EnableGithubRunner", tr("Enable GitHub runner service"), tr("Enables or disables the github runner service."), "");
addItem(enableGithubRunner);
// Joystick and longitudinal maneuvers should be hidden on release branches
is_release = params.getBool("IsReleaseBranch");

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation>وضع المناورة الطولية</translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation>Modo de maniobra longitudinal</translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation> </translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation>Modo Longitudinal Maneuver</translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

View File

@@ -123,6 +123,14 @@
<source>Longitudinal Maneuver Mode</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable GitHub runner service</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enables or disables the github runner service.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DevicePanel</name>

40
system/manager/github_runner.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Define the service name
SERVICE_NAME="actions.runner.sunnypilot.$(uname -n)"
# Function to control the service
control_service() {
local action=$1 # Store the function argument in a local variable
sudo systemctl $action ${SERVICE_NAME}
}
service_exists_and_is_loaded() {
sudo systemctl status ${SERVICE_NAME} &>/dev/null
if [[ $? -ne 4 ]]; then
return 0 # Service is known to systemd (i.e., loaded)
else
return 1 # Service is unknown to systemd (i.e., not loaded)
fi
}
# Check for required argument
if [[ -z $1 ]] || { [[ $1 != "start" ]] && [[ $1 != "stop" ]]; }; then
echo "Usage: $0 {start|stop}"
exit 1
fi
# Store the script argument in a descriptive variable
ACTION=$1
# Trap EXIT signal (Ctrl+C) and stop the service
trap 'control_service stop ; exit' SIGINT SIGKILL EXIT
# Enter the main loop
while true; do
# Check if the service is actually present on the system
if service_exists_and_is_loaded; then
control_service $ACTION # Call the function with the specified action
fi
sleep 1 # Pause before the next iteration
done

View File

@@ -54,6 +54,9 @@ def only_onroad(started: bool, params: Params, CP: car.CarParams) -> bool:
def only_offroad(started: bool, params: Params, CP: car.CarParams) -> bool:
return not started
def use_github_runner(started, params, CP: car.CarParams) -> bool:
return not PC and params.get_bool("EnableGithubRunner") and not params.get_bool("NetworkMetered")
def or_(*fns):
return lambda *args: operator.or_(*(fn(*args) for fn in fns))
@@ -111,4 +114,7 @@ procs = [
PythonProcess("joystick", "tools.joystick.joystick_control", and_(joystick, iscar)),
]
if os.path.exists("./github_runner.sh"):
procs += [NativeProcess("github_runner_start", "system/manager", ["./github_runner.sh", "start"], and_(only_offroad, use_github_runner), sigkill=False)]
managed_processes = {p.name: p for p in procs}