Create MacOS gitlab-runner

From Jwiki
Revision as of 12:15, 17 July 2025 by Gyurci08 (talk | contribs) (Created page with "Category:MacOS h1. MacOS Gitlab-runner h2. MacOS services (launchctl) h3. Description LaunchAgents: Invoked only when the user logs into a graphical session LaunchDaemons: Invoked when the system boots and runs outside of a specific user session. h3. Namespaces h4. System /Library/LaunchAgents: Per-user agents provided by the administrator. /Library/LaunchDaemons: System-wide daemons provided by the administrator. h4. Use...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


h1. MacOS Gitlab-runner

h2. MacOS services (launchctl)

h3. Description

LaunchAgents: Invoked only when the user logs into a graphical session LaunchDaemons: Invoked when the system boots and runs outside of a specific user session.

h3. Namespaces

h4. System

/Library/LaunchAgents: Per-user agents provided by the administrator. /Library/LaunchDaemons: System-wide daemons provided by the administrator.

h4. User

~/Library/LaunchAgents: Per-user agents provided by the user.

h3. Examples

h2. Gitlab-runner (homebrew)

<code class="bash">
su runner
</code>
<code class="bash">
nano ~/Library/LaunchAgents/homebrew.mxcl.gitlab-runner-custom.plist
</code>
<code class="xml">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>homebrew.mxcl.gitlab-runner</string>
        <key>LegacyTimers</key>
        <true/>
        <key>LimitLoadToSessionType</key>
        <array>
                <string>Aqua</string>
                <string>Background</string>
                <string>LoginWindow</string>
                <string>StandardIO</string>
                <string>System</string>
        </array>
        <key>ProcessType</key>
        <string>Interactive</string>
        <key>ProgramArguments</key>
        <array>
                <string>/opt/homebrew/opt/gitlab-runner/bin/gitlab-runner</string>
                <string>run</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>/Users/runner</string>
        <key>StandardErrorPath</key>
        <string>/Users/runner/gitlab-runner.err.log</string>
        <key>StandardOutPath</key>
        <string>/Users/runner/gitlab-runner.out.log</string>
</dict>
</plist>
</code>
<code class="bash">
nano ~/.gitlab-runner/config.toml
</code>

Gitlab-runner does not support zsh as shell!

<code class="toml">
concurrent = 3
check_interval = 30

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Mac-mini-runner"
  limit = 1
  url = "https://gitlab.com/"
  token = "masked"
  executor = "shell"
  shell="bash"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
</code>

We need to create .bashrc

<code class="bash">
nano ~/.bashrc
</code>
<code class="bash">
### Brew ###
## Silicon
eval $(/opt/homebrew/bin/brew shellenv)

### Ruby ###
eval "$(rbenv init -)"

### Extra environments ###
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# Android
export ANDROID_HOME="/Users/runner/Library/Android/sdk"

# Java
export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"

# Path
export PATH=/Users/runner/.rbenv/shims:/Users/runner/Downloads/flutter/bin:/opt/homebrew/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:/Users/runner/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/flutter/bin:/Library/flutter/.pub-cache/bin:/Users/runner/.pub-cache/bin:/Users/runner/Library/Android/sdk/bundle-tool/:/Users/runner/Library/Android/sdk/platform-tools/:/Users/runner/Library/Android/sdk/cmdline-tools/latest/bin/:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin

# FASTLANE
export FASTLANE_SESSION=masked
export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD="masked"
export FASTLANE_USER="mobil@example.com"
export FASTLANE_PASSWORD="masked"
export SPACESHIP_ONLY_ALLOW_INTERACTIVE_2FA=true
export SUPPLY_UPLOAD_MAX_RETRIES=5
</code>

We need to create .bash_profile too

<code class="bash">
nano ~/.bash_profile
</code>
<code class="bash">
#####
# USE "~/.bashrc" for configuration!
#####

### Import .bashrc ###
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
</code>

Enable and run:

<code class="bash">
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.gitlab-runner-custom.plist
</code>

Disable and stop:

<code class="bash">
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.gitlab-runner-custom.plist
</code>