1. Mac पर सेल्फ-होस्टेड GitLab Runners क्यों?
GitLab, Linux पर शेयर्ड runners प्रदान करता है, लेकिन iOS ऐप्स बनाने के लिए Apple हार्डवेयर पर चलने वाले macOS की आवश्यकता होती है। GitLab के अपने macOS शेयर्ड runners सीमित और महंगे हैं। एक सेल्फ-होस्टेड Mac Mini M4 runner आपको देता है:
GitLab के फ्री टियर में शेयर्ड runners पर 400 CI/CD मिनट शामिल हैं। सेल्फ-होस्टेड पर, कोई सीमा नहीं है।
उसी M4 चिप पर बिल्ड करें जिस पर आपके उपयोगकर्ताओं के डिवाइस चलते हैं। कोई Rosetta ट्रांसलेशन ओवरहेड नहीं।
अपनी आवश्यकता के अनुसार कोई भी Xcode वर्शन, सिम्युलेटर, टूल्स और डिपेंडेंसीज़ इंस्टॉल करें।
DerivedData, SPM पैकेज और CocoaPods कैश पाइपलाइन रन के बीच बने रहते हैं।
2. GitLab Runner इंस्टॉल करें
अपने Mac Mini M4 में SSH करें और Homebrew का उपयोग करके GitLab Runner इंस्टॉल करें:
# Connect to your Mac Mini M4
ssh admin@your-server-ip
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
# Install GitLab Runner
brew install gitlab-runner
# Verify installation
gitlab-runner --version
# Version: 17.7.0
# Git revision: ...
# Git branch: 17-7-stable
# GO version: go1.22.10
# Built: ...
# OS/Arch: darwin/arm64
macOS सर्विस के रूप में इंस्टॉल करें
# Install the runner as a launchd service
# This ensures it starts automatically on boot
brew services start gitlab-runner
# Verify the service is running
brew services list | grep gitlab-runner
# gitlab-runner started admin ~/Library/LaunchAgents/homebrew.mxcl.gitlab-runner.plist
# Check runner status
gitlab-runner status
# gitlab-runner: Service is running
3. Runner रजिस्टर करें
अपने GitLab प्रोजेक्ट (या ग्रुप) पर जाएं और Settings > CI/CD > Runners > New project runner पर नेविगेट करें। रजिस्ट्रेशन टोकन कॉपी करें।
नए Runner रजिस्ट्रेशन फ्लो के साथ रजिस्टर करें (GitLab 16+)
# Register the runner using the authentication token from GitLab UI
# (GitLab 16+ uses authentication tokens instead of registration tokens)
gitlab-runner register \
--non-interactive \
--url "https://gitlab.com/" \
--token "YOUR_RUNNER_AUTHENTICATION_TOKEN" \
--executor "shell" \
--description "mac-mini-m4-runner" \
--tag-list "macos,apple-silicon,m4,ios,xcode"
लेगेसी रजिस्ट्रेशन टोकन के साथ रजिस्टर करें (GitLab 15 और उससे पहले)
# For older GitLab instances using registration tokens
gitlab-runner register \
--non-interactive \
--url "https://gitlab.com/" \
--registration-token "YOUR_REGISTRATION_TOKEN" \
--executor "shell" \
--description "mac-mini-m4-runner" \
--tag-list "macos,apple-silicon,m4,ios,xcode" \
--run-untagged="false"
Runner कॉन्फ़िगरेशन सत्यापित करें
# View the runner config file
cat ~/.gitlab-runner/config.toml
# Expected output:
# concurrent = 2
# check_interval = 0
#
# [session_server]
# session_timeout = 1800
#
# [[runners]]
# name = "mac-mini-m4-runner"
# url = "https://gitlab.com/"
# token = "..."
# executor = "shell"
# [runners.cache]
# MaxUploadedArchiveSize = 0
# Adjust concurrency based on your hardware:
# Mac Mini M4 (16GB): concurrent = 2
# Mac Mini M4 Pro (24GB): concurrent = 3
# Mac Mini M4 Pro (48GB): concurrent = 4
समवर्तीता (concurrency) समायोजित करने के लिए ~/.gitlab-runner/config.toml संपादित करें:
# Edit the config
nano ~/.gitlab-runner/config.toml
# Set concurrent to match your hardware capacity
concurrent = 2
# Restart the runner to apply changes
gitlab-runner restart
अब runner आपके GitLab प्रोजेक्ट में Settings > CI/CD > Runners के अंतर्गत Online के रूप में दिखना चाहिए।
4. iOS के लिए .gitlab-ci.yml बनाएं
अपने रिपॉजिटरी रूट में एक .gitlab-ci.yml फ़ाइल बनाएं। यह संपूर्ण पाइपलाइन आपके iOS ऐप को बनाती, टेस्ट करती और डिप्लॉय करती है:
# .gitlab-ci.yml
stages:
- setup
- build
- test
- deploy
variables:
SCHEME: "MyApp"
WORKSPACE: "MyApp.xcworkspace"
DESTINATION: "platform=iOS Simulator,name=iPhone 16 Pro,OS=18.2"
DERIVED_DATA: "${CI_PROJECT_DIR}/DerivedData"
# Only run on our Mac runner
default:
tags:
- macos
- m4
# ---- SETUP ----
setup:
stage: setup
script:
- sudo xcode-select -s /Applications/Xcode-16.2.app/Contents/Developer
- xcodebuild -version
- swift --version
# Install CocoaPods if using Podfile
- |
if [ -f "Podfile" ]; then
pod install --repo-update
fi
cache:
key: pods-${CI_COMMIT_REF_SLUG}
paths:
- Pods/
- .spm-cache/
# ---- BUILD ----
build:
stage: build
needs: ["setup"]
script:
- |
xcodebuild build \
-workspace "${WORKSPACE}" \
-scheme "${SCHEME}" \
-destination "${DESTINATION}" \
-derivedDataPath "${DERIVED_DATA}" \
-clonedSourcePackagesDirPath ".spm-cache" \
CODE_SIGNING_ALLOWED=NO \
| xcbeautify
cache:
key: derived-data-${CI_COMMIT_REF_SLUG}
paths:
- DerivedData/
- .spm-cache/
artifacts:
paths:
- DerivedData/
expire_in: 1 hour
# ---- TEST ----
unit_tests:
stage: test
needs: ["build"]
script:
- |
xcodebuild test \
-workspace "${WORKSPACE}" \
-scheme "${SCHEME}" \
-destination "${DESTINATION}" \
-derivedDataPath "${DERIVED_DATA}" \
-resultBundlePath "TestResults.xcresult" \
-parallel-testing-enabled YES \
| xcbeautify
artifacts:
when: always
paths:
- TestResults.xcresult/
reports:
junit: TestResults.xcresult/report.junit
expire_in: 7 days
after_script:
- xcrun simctl shutdown all 2>/dev/null || true
# ---- DEPLOY ----
deploy_testflight:
stage: deploy
needs: ["unit_tests"]
only:
- main
script:
- |
# Install or update Fastlane
which fastlane || brew install fastlane
# Run Fastlane beta lane
fastlane beta
environment:
name: testflight
variables:
MATCH_PASSWORD: ${MATCH_PASSWORD}
APP_STORE_CONNECT_API_KEY_ID: ${APP_STORE_KEY_ID}
APP_STORE_CONNECT_API_ISSUER_ID: ${APP_STORE_ISSUER_ID}
APP_STORE_CONNECT_API_KEY_CONTENT: ${APP_STORE_KEY_CONTENT}
GitLab में CI/CD वेरिएबल्स जोड़ें
अपने GitLab प्रोजेक्ट में Settings > CI/CD > Variables पर नेविगेट करें और इन वेरिएबल्स को "Masked" और "Protected" के रूप में जोड़ें:
-
MATCH_PASSWORD- Fastlane Match एन्क्रिप्शन के लिए पासवर्ड -
APP_STORE_KEY_ID- App Store Connect API Key ID -
APP_STORE_ISSUER_ID- App Store Connect Issuer ID -
APP_STORE_KEY_CONTENT- .p8 key फ़ाइल की सामग्री
5. प्रदर्शन ऑप्टिमाइज़ करें
GitLab कैश कॉन्फ़िगरेशन
GitLab Runner, shell executors के लिए लोकल कैशिंग का समर्थन करता है। चूंकि आपका runner स्थायी है, लोकल कैश अत्यंत कुशल हैं:
# In .gitlab-ci.yml, configure cache per branch:
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
- DerivedData/
- .spm-cache/
- Pods/
policy: pull-push
# For test jobs that don't modify cache, use pull-only:
unit_tests:
cache:
key: "${CI_COMMIT_REF_SLUG}"
paths:
- DerivedData/
policy: pull
इंटर-स्टेज डेटा के लिए आर्टिफैक्ट्स का उपयोग करें
# Pass build artifacts between stages efficiently
build:
artifacts:
paths:
- DerivedData/Build/Products/
expire_in: 2 hours
# The test stage receives the built products without rebuilding
test:
needs: ["build"] # only download artifacts from the build job
script:
- xcodebuild test-without-building \
-scheme "${SCHEME}" \
-destination "${DESTINATION}" \
-derivedDataPath "${DERIVED_DATA}"
समानांतर टेस्ट निष्पादन
# Split tests across parallel jobs using GitLab's parallel keyword
unit_tests:
stage: test
parallel: 2
script:
- |
# Use test plan partitioning or custom splitting
xcodebuild test \
-workspace "${WORKSPACE}" \
-scheme "${SCHEME}" \
-destination "${DESTINATION}" \
-derivedDataPath "${DERIVED_DATA}" \
-parallel-testing-enabled YES \
-maximum-parallel-testing-workers 4
अनुसूचित कैश क्लीनअप
# On the Mac Mini, set up a weekly cleanup cron job
crontab -e
# Add these lines:
# Clean DerivedData older than 7 days every Sunday at 3 AM
0 3 * * 0 find ~/builds/*/DerivedData -maxdepth 0 -mtime +7 -exec rm -rf {} + 2>/dev/null
# Clean old GitLab Runner builds older than 14 days
0 4 * * 0 find ~/builds -maxdepth 2 -mtime +14 -type d -exec rm -rf {} + 2>/dev/null
# Clean Homebrew cache monthly
0 5 1 * * /opt/homebrew/bin/brew cleanup --prune=30 2>/dev/null
6. समस्या निवारण
GitLab में runner "offline" दिखाता है
runner सर्विस की स्थिति और लॉग जांचें:
# Check service status
brew services list | grep gitlab-runner
# View logs
cat /usr/local/var/log/gitlab-runner.log
# Restart the service
brew services restart gitlab-runner
# Verify connectivity to GitLab
gitlab-runner verify
बिल्ड के दौरान परमिशन डिनाइड त्रुटियां
runner को Xcode डेवलपर डायरेक्टरी तक पहुंच की आवश्यकता हो सकती है:
# Ensure the runner user has Xcode access
sudo xcode-select -s /Applications/Xcode-16.2.app/Contents/Developer
sudo xcodebuild -license accept
# If using simulators, ensure the user can access them
xcrun simctl list devices
कैश पुनर्स्थापित नहीं हो रहा
सुनिश्चित करें कि कैश कीज़ सुसंगत हैं और पाथ मौजूद हैं:
# Check cache directory permissions
ls -la ~/builds/
# The shell executor stores caches locally by default
# Verify the cache directory in config.toml:
cat ~/.gitlab-runner/config.toml
# Ensure [runners.cache] section has the right settings
# For local caching (most efficient for persistent runners):
# [runners.cache]
# Type = "" # empty = local cache
Xcode बिल्ड अटक जाता है या टाइम आउट हो जाता है
यह अक्सर कीचेन एक्सेस प्रॉम्प्ट या सिम्युलेटर समस्याओं के कारण होता है:
# Unlock the keychain before builds
security unlock-keychain -p "YOUR_PASSWORD" ~/Library/Keychains/login.keychain-db
# Kill stuck simulators
xcrun simctl shutdown all
pkill -f "Simulator.app" 2>/dev/null || true
# Set a build timeout in .gitlab-ci.yml
build:
timeout: 30 minutes
7. सामान्य प्रश्न
क्या मैं macOS पर Docker executor का उपयोग कर सकता हूं?
macOS पर Docker, एक VM में Linux कंटेनर चलाता है, जो macOS APIs, Xcode या iOS सिम्युलेटर तक पहुंच नहीं सकता। iOS बिल्ड के लिए, आपको shell executor का उपयोग करना होगा। Docker सर्वर-साइड Swift या आपके Mac runner के साथ चलने वाले अन्य Linux-आधारित कार्यों के लिए ठीक है।
मैं GitLab ग्रुप के लिए runner कैसे रजिस्टर करूं?
अपने GitLab ग्रुप के Settings > CI/CD > Runners > New group runner पर जाएं। प्रोजेक्ट टोकन के बजाय ग्रुप runner टोकन का उपयोग करें। इससे runner ग्रुप के सभी प्रोजेक्ट्स के लिए उपलब्ध हो जाता है।
क्या मुझे shell executor का उपयोग करना चाहिए या SSH executor का?
shell executor का उपयोग करें। यह कमांड सीधे Mac पर चलाता है, जो Xcode, सिम्युलेटर और कीचेन तक पूर्ण पहुंच देता है। SSH executor रिमोट मशीनों के लिए है, जो तब अनावश्यक है जब runner पहले से ही Mac पर है।
क्या मैं एक ही Mac पर GitLab और GitHub Actions दोनों runners चला सकता हूं?
हां। दोनों runners हल्के हैं और एक ही Mac Mini M4 पर साथ-साथ रह सकते हैं। बस प्रत्येक runner के लिए समवर्तीता स्तर सेट करते समय संयुक्त संसाधन उपयोग का ध्यान रखें।
मैं GitLab Runner को कैसे अपडेट करूं?
# Update via Homebrew
brew upgrade gitlab-runner
# Restart the service
brew services restart gitlab-runner
# Verify the new version
gitlab-runner --version
पूरी तरह से मैनेज्ड GitLab Runner की तलाश में हैं? Cloud-Runner आज़माएं
पूरी तरह से सेटअप छोड़ दें। Cloud-Runner, Mac हार्डवेयर पर पूर्व-कॉन्फ़िगर, समर्पित GitLab Runners प्रदान करता है — किसी इंस्टॉलेशन या रखरखाव की आवश्यकता नहीं।