AZURE : WINDOWS SELF HOSTED AGENT - From Your Laptop to Live Azure App Service

 

Self Hosted Agent Windows

From Your Laptop to Live Azure App Service

End-to-End Flow Visualization

text
[YOUR LAPTOP] → [AZURE DEVOPS] → [SELF-HOSTED AGENT] → [AZURE APP SERVICE] → [INTERNET USERS]

Phase 1: Code Creation on Your Laptop

Step 1.1: Local Development

On Your Laptop:

text
C:\Projects\propel-pro-2025\
├── app.py
├── requirements.txt
└── azure-pipelines.yml

What Happens:

  • You write Flask code in app.py on your Windows laptop

  • You define dependencies in requirements.txt

  • You create the YAML pipeline configuration

Technical Details:

  • Your laptop has Python, Flask, and git installed

  • Code is stored locally in your file system


Phase 2: Code Commit & Push

Step 2.1: Git Operations

On Your Laptop:

bash
git add .
git commit -m "Update Flask API"
git push origin master

What Happens:

  1. Local Repository: Your code is committed to local git history

  2. Push to Remote: Code is sent to Azure Repos in the cloud

  3. Trigger Detection: Azure DevOps detects push to master branch

Data Flow:

text
Your Laptop → Internet → Azure DevOps Servers
     ↓
Code files transferred via HTTPS/SSH
     ↓
Stored in Azure Repos Git repository

Phase 3: Pipeline Trigger in Azure DevOps

Step 3.1: Automation Kick-off

In Azure DevOps Cloud:

yaml
trigger:
- master  # 👈 THIS LINE DETECTS THE PUSH

What Happens:

  1. Webhook Trigger: Azure DevOps sees the push to master branch

  2. Queue Build: Pipeline execution is queued

  3. Agent Selection: Looks for available agent matching requirements

System Flow:

text
Azure Repos → Azure Pipelines Orchestrator
     ↓
"New code in master branch detected!"
     ↓
"Find agent that matches: name = FAITH"

Phase 4: Self-Hosted Agent Execution

Step 4.1: Agent Assignment

Between Azure DevOps and Your Network:

yaml
pool:
  name: Default
  demands: agent.name -equals FAITH  # 👈 TARGETS YOUR MACHINE

What Happens:

  1. Agent Communication: Your self-hosted agent FAITH regularly polls Azure DevOps

  2. Job Assignment: "Hey FAITH, I have a pipeline job for you!"

  3. Code Download: Agent downloads your repository code

Network Flow:

text
Azure DevOps Cloud → Internet → Your Corporate Network → Windows Machine "FAITH"
     ↓
Pipeline job instructions + your code files
     ↓
Stored in: D:\Agents\_work\1\s\ (or similar agent workspace)

Step 4.2: File Verification on Your Windows Agent

yaml
- powershell: |
    Write-Host "Files to be deployed:" -ForegroundColor Cyan
    Get-ChildItem

What Happens on Your Windows Machine:

  1. PowerShell Execution: Runs the script in agent workspace

  2. Directory Listing: Shows all files that were downloaded

  3. Visual Confirmation: You see in Azure DevOps logs:

text
Files to be deployed:
app.py
requirements.txt
azure-pipelines.yml

Physical Location:

text
D:\Agents\_work\1\s\app.py
D:\Agents\_work\1\s\requirements.txt
D:\Agents\_work\1\s\azure-pipelines.yml

Step 4.3: ZIP Package Creation on Your Windows Agent

yaml
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    archiveFile: '$(Build.ArtifactStagingDirectory)/app.zip'

What Happens on Your Windows Machine:

  1. File Collection: Gathers all files from workspace directory

  2. ZIP Creation: Uses Windows compression libraries

  3. Output: Creates app.zip in staging directory

File System Operations:

text
D:\Agents\_work\1\s\          D:\Agents\_work\1\a\
├── app.py                    └── app.zip (contains:)
├── requirements.txt              ├── app.py
└── azure-pipelines.yml          ├── requirements.txt
                                 └── azure-pipelines.yml

Step 4.4: Artifact Storage

yaml
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'

What Happens:

  1. Upload Preparation: ZIP file read from local disk

  2. Network Transfer: File uploaded to Azure DevOps cloud storage

  3. Storage: Saved as build artifact for historical reference

Data Flow:

text
Your Windows Agent → Internet → Azure DevOps Artifact Storage
     ↓
app.zip uploaded and stored
     ↓
Available for download or rollback

Phase 5: Azure App Service Deployment

Step 5.1: Deployment Authentication

yaml
- task: AzureWebApp@1
  inputs:
    azureSubscription: $(azureServiceConnection)

What Happens:

  1. Authentication: Uses the service connection to get Azure access token

  2. Authorization: Verifies permissions to deploy to the App Service

  3. API Preparation: Sets up REST API calls to Azure

Security Flow:

text
Azure DevOps → Azure Active Directory
     ↓
Service Principal Authentication
     ↓
Access Token for App Service Management

Step 5.2: ZIP Deployment to Azure

yaml
inputs:
  appName: $(webAppName)
  package: '$(Build.ArtifactStagingDirectory)/app.zip'

What Happens:

  1. File Read: Reads app.zip from local agent storage

  2. API Call: Makes HTTPS PUT request to Azure App Service deployment API

  3. File Extraction: Azure automatically extracts ZIP to wwwroot

Deployment Flow:

text
Your Windows Agent → Internet → Azure App Service
     ↓
ZIP file transmitted via HTTPS
     ↓
Azure extracts to: D:\home\site\wwwroot\
     ↓
Files now available at: 
D:\home\site\wwwroot\app.py
D:\home\site\wwwroot\requirements.txt

Phase 6: Application Startup in Azure

Step 6.1: Python Environment Setup

In Azure App Service:

  1. Python Detection: Azure sees requirements.txt and Python files

  2. Dependency Installation: Automatically runs pip install -r requirements.txt

  3. Virtual Environment: Creates isolated Python environment

Azure Internal Process:

text
D:\home\site\wwwroot\requirements.txt
     ↓
pip install Flask==2.3.3 gunicorn==21.2.0
     ↓
D:\home\site\wwwroot\env\Lib\site-packages\

Step 6.2: Web Server Startup

In Azure App Service:

  1. Process Startup: Azure starts Python process

  2. Gunicorn Execution: Runs your Flask app via Gunicorn WSGI server

  3. Port Binding: Listens on assigned HTTP port

Application Startup:

text
python.exe → gunicorn → app:app
     ↓
Listening on: http://0.0.0.0:80
     ↓
Ready to accept incoming requests

Phase 7: Success Notification & Live Application

Step 7.1: Final Status Update

yaml
- script: |
    echo "✅ Deployment successful!"
    echo "🌐 URL: https://$(webAppName).azurewebsites.net"

What Happens:

  1. Script Execution: Runs on your Windows agent

  2. Log Output: Messages appear in Azure DevOps pipeline logs

  3. Completion: Pipeline marks as successful

User Visibility:

text
Azure DevOps Pipeline Logs:
✅ Deployment successful!
🌐 URL: https://webapp-flask-yaml-app-2025.azurewebsites.net

Step 7.2: Live Application Access

Internet Traffic Flow:

text
User's Browser → Internet → Azure Load Balancer → Your App Service → Python/Flask
     ↓
https://webapp-flask-yaml-app-2025.azurewebsites.net/
     ↓
Azure routes to your specific App Service instance
     ↓
Gunicorn handles request → Flask processes → JSON response

Complete Data Journey Summary

File Journey: app.py

text
Your Laptop (C:\) 
     → Azure Repos (Git) 
     → Your Windows Agent (D:\Agents\_work\1\s\) 
     → ZIP Package (D:\Agents\_work\1\a\app.zip)
     → Azure App Service (D:\home\site\wwwroot\)
     → Internet Users (via HTTPS)

Network Connections:

  1. Your Laptop → Azure DevOps: Git push (HTTPS)

  2. Azure DevOps → Your Agent: Job instructions + code (HTTPS)

  3. Your Agent → Azure DevOps: Logs + artifacts (HTTPS)

  4. Your Agent → Azure App Service: ZIP deployment (HTTPS)

  5. Internet Users → Azure App Service: Web traffic (HTTPS)

Authentication Flow:

  1. You → Azure DevOps: Personal access token or Azure AD

  2. Azure DevOps → Azure: Service Principal (Service Connection)

  3. App Service → Python: No authentication required (public web app)


Key Infrastructure Components

On Your Windows Machine (FAITH agent):

  • Azure DevOps Agent Service: Runs pipeline jobs

  • PowerShell: Executes scripts and commands

  • File System: Temporary workspace for build process

  • Network: Outbound internet access to Azure services

In Azure Cloud:

  • Azure DevOps: Pipeline orchestration, repository, artifact storage

  • Azure App Service: Web hosting, automatic Python environment

  • Azure Active Directory: Authentication and authorization

  • Azure Networking: Load balancing, DNS, SSL termination


Comments

Popular posts from this blog

Interview Tips: Dot NET Framework vs Net CORE

FREE Webinar: Run Your Own Independent DeepSeek LLM

Delegates and Events