Ir al contenido principal

Zero Ops on Mac Mini M4: Native CI/CD for C# APIs

Advanced DevOps Guide

Zero Ops on Mac Mini M4: Native CI/CD for C# APIs

Launchd Agents Automated Deploy Git-Driven
Automated deployment flow for Mac Mini

Transforming your Mac Mini into a self-healing, auto-deploying production server.

"The goal is simple: Git Push and forget. No manual terminals, no complex Docker layers—just pure macOS native resilience."

1 The Core: Deployment Script

We create a dedicated deploy.sh script. This "heart" of the system handles compiling the ARM64 binary and restarting the service.

Script Location: ~/code/csharp/be-real-doctor-api/deploy.sh
#!/bin/bash

# 1. Explicitly define PATH so Launchd can find git and dotnet
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet"

PROJECT_DIR="/Users/ismael/code/csharp/repo-name"
PUBLISH_DIR="$PROJECT_DIR/src/publish"
PLIST_PATH="$HOME/Library/LaunchAgents/com.appname.api.plist"

# 2. Use the absolute path for dotnet (adjusted based on 'which dotnet' output)
DOTNET_BIN="/usr/local/share/dotnet/dotnet"

echo "馃殌 Starting automatic deployment..."
cd "$PROJECT_DIR/src"

# Execute publish using the absolute path
$DOTNET_BIN publish -c Release -r osx-arm64 --self-contained false -o "$PUBLISH_DIR"

if [ $? -eq 0 ]; then
    # 3. Restart the service
    launchctl unload "$PLIST_PATH" 2>/dev/null
    launchctl load "$PLIST_PATH"
    echo "✅ AppName updated and running."
else
    echo "❌ Build failed. Check for missing SDK or code errors."
    exit 1
fi

Don't forget to run: chmod +x deploy.sh

2 Resilience: The .plist Agent

Instead of using .zshrc, we use a Launch Agent. This ensures the API runs 24/7, restarts on crashes, and boots automatically with the Mac.

File: ~/Library/LaunchAgents/com.berealdoctor.api.plist

Set ASPNETCORE_URLS to http://0.0.0.0:5000 to allow external access within your network, and set KeepAlive to true for 100% uptime.

Initialize with: launchctl load [path_to_plist]

3 The Brain: Auto-Git Watcher

To achieve true Zero Ops, we set up a second agent that monitors your repository every 60 seconds. If it detects a change on GitHub, it pulls and triggers the deploy script.

CI/CD Logic:

git fetch origin && [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ] && git pull && ./deploy.sh

This command compares your local HEAD with the remote. It only triggers a build when new code is actually present.

4 Why This is Superior

  • Zero Terminal Dependency: No need to keep a terminal window open or use tools like fswatch.
  • Git-Driven: Your only action is git push from your development laptop.
  • Native Resilience: If the Mac Mini restarts after a power outage, the agents boot up automatically.

Zero Ops Achieved

Your Mac Mini M4 is now a professional-grade automated server.

PUSH CODE. STAY CALM.

Comentarios

Entradas populares de este blog

How to Use the Tab Key to Accept Github Copilot Suggestions

How to Use the Tab Key to Accept Github Copilot Suggestions After installing Copilot in Visual Code, I've installed the following extensions: GitHub Copilot, GitHub Copilot Chat, and GitHub Copilot Tool Pack, as shown in the attached screenshot. The Problem: After installing and configuring it with my Copilot account, when a completion suggestion appears, pressing Tab doesn't autocomplete it. To accept Copilot suggestions with the Tab key in VS Code, follow these steps: Step 1: Open Keyboard Shortcuts JSON Press Ctrl + Shift + P and type "Open Keyboard Shortcuts (JSON)" to open the keybindings.json file. Step 2: Add the Tab Key Binding Add the following code to the keybindings.json file: [ { "key": "tab", "command": "editor.action.inlineSuggest.commit", "when": "textInputFocus && inlineSuggestionHasIndentationLessThanTabSize && inlineSuggestion...

Bye GitHub Copilot: Setup Your Own Local AI

Next-Gen Development Bye GitHub Copilot: Setup Your Own Local AI C# Software Development 6 min read Coding at 30,000 feet: Independent, private, and powerful. "Picture this: You’re on a flight to Mallorca . You open your laptop, the cabin is quiet, and inspiration strikes. But there is no Wi-Fi, and your cloud-based AI tools are useless. By hosting your own LLM, you don't just gain privacy: you gain operational freedom ." Worried about code privacy or rising subscription costs? In 2026, the era of local LLMs has arrived. Setting up a local environment allows you to use specialized models like DeepSeek or Qwen which, in many cases, outperform generic models in specific programming tasks, offering a precision that cloud-based Copilot simply cannot match offline. 1 Step 1: The Brain (LM Studio) Model Selection Search ...

Context Engineering: Making AI Actually Useful

AI Strategy & Implementation Context Engineering: Making AI Actually Useful Workflow Optimization 5 Min Read Coding at 30,000 feet: Independent, private, and powerful. "Everyone is talking about AI agents, but they often feel like a brilliant new hire who doesn't know how things work internally. They have the potential, but lack the context. The fix isn't a better model—it's better context engineering. " Think of context as the ultimate instruction manual. Without it, the AI is guessing; with it, it becomes a specialist integrated into your real-world workflow. 1 The 4 Pillars of Context 馃搵 Operational Rules The "How-To" of your company. Define approval processes and hard limits. Example: "Never approve expenses >$500 without manager review." 馃 Domai...