Skip to content

Commit 0998728

Browse files
committed
feature: Add hostname if INSTANCE_ID not set and update README.md
1 parent 8c455bd commit 0998728

File tree

4 files changed

+87
-14
lines changed

4 files changed

+87
-14
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Azure DevOps Docker Agent
22

3+
**GitHub Repository**: [https://github.com/hypolas/azure-devops-agent](https://github.com/hypolas/azure-devops-agent)
4+
**Docker Hub Image**: [https://hub.docker.com/r/hypolas/azure-devops-agent](https://hub.docker.com/r/hypolas/azure-devops-agent)
5+
36
[![Docker](https://img.shields.io/badge/docker-supported-blue.svg)](https://www.docker.com/)
47
[![Azure DevOps](https://img.shields.io/badge/azure--devops-agent-blue.svg)](https://azure.microsoft.com/services/devops/)
58
[![AWS](https://img.shields.io/badge/aws-secrets--manager-orange.svg)](https://aws.amazon.com/secrets-manager/)
@@ -182,11 +185,12 @@ docker run -d --name azure-agent-3 -e AGENT_NUMBER="3" [other options] azure-age
182185

183186
### Multi-Agent Deployment Script Example
184187

185-
For a server with 8 vCPUs, following the rule of **2 vCPUs per agent**, you can deploy **4 agents** using this script:
188+
For a server with 8 vCPUs, following the rule of **2 vCPUs per agent** (this is a subjective recommendation - adjust based on your workload requirements and performance monitoring), you can deploy **4 agents** using this script:
186189

187190
Create a file `deploy-agents.sh`:
188191

189192
```bash
193+
190194
#!/bin/bash
191195
# Multi-agent deployment script
192196
# Rule: 2 vCPUs per agent
@@ -196,7 +200,7 @@ set -e
196200
197201
# Configuration
198202
TOTAL_VCPUS=$(nproc)
199-
VCPUS_PER_AGENT=2
203+
VCPUS_PER_AGENT=2 # Adjust this value based on your workload needs
200204
MAX_AGENTS=$((TOTAL_VCPUS / VCPUS_PER_AGENT))
201205
202206
echo "Detected $TOTAL_VCPUS vCPUs on this server"
@@ -222,7 +226,7 @@ echo "=========================================="
222226
223227
# Deploy agents in a loop
224228
for i in $(seq 1 $MAX_AGENTS); do
225-
AGENT_NAME="azure-agent-${i}"
229+
AGENT_NAME="azure-agent-$i"
226230
227231
echo "Starting agent $i/$MAX_AGENTS: $AGENT_NAME"
228232
@@ -240,17 +244,10 @@ for i in $(seq 1 $MAX_AGENTS); do
240244
-e DEFAULT_CONTAINER_IMAGE="${DEFAULT_CONTAINER_IMAGE:-ubuntu:22.04}" \
241245
-e DEFAULT_VOLUMES="${DEFAULT_VOLUMES:-/var/run/docker.sock:/var/run/docker.sock,/cache:/cache,/data:/data}" \
242246
--restart unless-stopped \
243-
azure-agent
247+
hypolas/azure-devops-agent:latest
244248
245249
echo "✅ Agent $i started: $AGENT_NAME"
246250
done
247-
248-
echo "=========================================="
249-
echo "✅ All $MAX_AGENTS agents deployed successfully"
250-
echo "=========================================="
251-
252-
# Show running agents
253-
docker ps --filter "name=azure-agent-" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
254251
```
255252

256253
**Usage:**
@@ -360,4 +357,17 @@ The image uses IMDSv2 (Instance Metadata Service v2) to securely retrieve AWS in
360357

361358
---
362359

363-
*Docker image for Azure DevOps agents with AWS Secrets Manager integration - Optimized for modern CI/CD pipelines and DevOps automation.*
360+
*Docker image for Azure DevOps agents with AWS Secrets Manager integration - Optimized for modern CI/CD pipelines and DevOps automation.*
361+
362+
## Disclaimer
363+
364+
**This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.**
365+
366+
The developer cannot be held responsible for any problems, data loss, security issues, or any other consequences that may arise from the use of this software. Users are solely responsible for:
367+
- Proper configuration and deployment
368+
- Security of credentials and tokens
369+
- Resource allocation and monitoring
370+
- Compliance with Azure DevOps and AWS terms of service
371+
- Any costs incurred from cloud service usage
372+
373+
Use at your own risk.

deploy-agents.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
#!/bin/bash
3+
# Multi-agent deployment script
4+
# Rule: 2 vCPUs per agent
5+
# Automatically detects available CPUs
6+
7+
set -e
8+
9+
# Configuration
10+
TOTAL_VCPUS=$(nproc)
11+
VCPUS_PER_AGENT=2
12+
MAX_AGENTS=$((TOTAL_VCPUS / VCPUS_PER_AGENT))
13+
14+
echo "Detected $TOTAL_VCPUS vCPUs on this server"
15+
echo "Deploying $MAX_AGENTS agents with $VCPUS_PER_AGENT vCPUs each"
16+
17+
# Load environment variables from .env
18+
if [ -f .env ]; then
19+
export $(grep -v '^#' .env | xargs)
20+
else
21+
echo "Error: .env file not found"
22+
exit 1
23+
fi
24+
25+
# Check required variables
26+
if [ -z "$AZP_URL" ] || [ -z "$AZP_POOL" ] || [ -z "$AZP_AGENT_NAME" ] || [ -z "$INSTALL_FOLDER" ]; then
27+
echo "Error: Required variables not set in .env (AZP_URL, AZP_POOL, AZP_AGENT_NAME, INSTALL_FOLDER)"
28+
exit 1
29+
fi
30+
31+
echo "=========================================="
32+
echo "Deploying $MAX_AGENTS agents (${VCPUS_PER_AGENT} vCPUs each)"
33+
echo "=========================================="
34+
35+
# Deploy agents in a loop
36+
for i in $(seq 1 $MAX_AGENTS); do
37+
AGENT_NAME="azure-agent-$i"
38+
39+
echo "Starting agent $i/$MAX_AGENTS: $AGENT_NAME"
40+
41+
docker run -d \
42+
--name "$AGENT_NAME" \
43+
-v /var/run/docker.sock:/var/run/docker.sock \
44+
-v "${INSTALL_FOLDER}:${INSTALL_FOLDER}" \
45+
-e AZP_URL="$AZP_URL" \
46+
-e AZP_TOKEN="$AZP_TOKEN" \
47+
-e AZP_POOL="$AZP_POOL" \
48+
-e AZP_AGENT_NAME="$AZP_AGENT_NAME" \
49+
-e AGENT_NUMBER="$i" \
50+
-e INSTALL_FOLDER="${INSTALL_FOLDER}" \
51+
-e AWS_REGION="$AWS_REGION" \
52+
-e DEFAULT_CONTAINER_IMAGE="${DEFAULT_CONTAINER_IMAGE:-ubuntu:22.04}" \
53+
-e DEFAULT_VOLUMES="${DEFAULT_VOLUMES:-/var/run/docker.sock:/var/run/docker.sock,/cache:/cache,/data:/data}" \
54+
--restart unless-stopped \
55+
hypolas/azure-devops-agent:latest
56+
57+
echo "✅ Agent $i started: $AGENT_NAME"
58+
done

entrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ if [ -z "$INSTANCE_ID" ]; then
8585
# Retrieve IMDSv2 token to secure metadata access
8686
IMDS_TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
8787
-H "X-aws-ec2-metadata-token-ttl-seconds: 21600" \
88-
-s 2>/dev/null)
88+
-s 2>/dev/null) || true
8989

9090
if [ -n "$IMDS_TOKEN" ]; then
9191
# Use token to retrieve instance ID
9292
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $IMDS_TOKEN" \
93-
-s "http://169.254.169.254/latest/meta-data/instance-id" 2>/dev/null)
93+
-s "http://169.254.169.254/latest/meta-data/instance-id" 2>/dev/null) || true
9494
fi
9595

96+
echo "INSTANCE_ID from IMDSv2: $INSTANCE_ID"
97+
9698
if [ -z "$INSTANCE_ID" ] || [ "$INSTANCE_ID" = "" ]; then
9799
echo "Warning: Unable to retrieve AWS INSTANCE_ID, using hostname"
98100
INSTANCE_ID=$(hostname)

scripts/configure-agent.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ cp -r "/opt/dl/"* "$INSTALL_FOLDER/$AGENT_NUMBER/"
2424
# Go to agent directory
2525
cd "$INSTALL_FOLDER/$AGENT_NUMBER"
2626

27+
./config.sh remove --unattended --auth pat --token "$AZP_TOKEN"
28+
sleep 5
29+
2730
# Configure the agent
2831
./config.sh \
2932
--unattended \

0 commit comments

Comments
 (0)