-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (92 loc) · 3.55 KB
/
install-java-batched.yml
File metadata and controls
100 lines (92 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: 3. Install Java Agent
on:
workflow_dispatch:
inputs:
batch_size:
description: 'Number of hosts per batch'
required: false
default: '256'
type: string
jobs:
prepare:
runs-on: self-hosted
outputs:
batches: ${{ steps.create-batches.outputs.batches }}
total_hosts: ${{ steps.create-batches.outputs.total_hosts }}
total_batches: ${{ steps.create-batches.outputs.total_batches }}
steps:
- id: create-batches
run: |
HOSTS=$(echo "${{ vars.DEPLOYMENT_HOSTS }}" | tr -d '\r' | grep -v '^$')
TOTAL=$(echo "$HOSTS" | wc -l | xargs)
echo "total_hosts=$TOTAL" >> $GITHUB_OUTPUT
BATCH_SIZE=${{ github.event.inputs.batch_size || '256' }}
TOTAL_BATCHES=$(( (TOTAL + BATCH_SIZE - 1) / BATCH_SIZE ))
echo "total_batches=$TOTAL_BATCHES" >> $GITHUB_OUTPUT
BATCHES=$(echo "$HOSTS" | awk -v batch_size=$BATCH_SIZE '
BEGIN { batch=0; print "[" }
{
if (NR % batch_size == 1) {
if (NR > 1) { print "]" }
if (NR > 1) { print "," }
print "["
printf "\"%s\"", $0
} else {
printf ",\"%s\"", $0
}
}
END { if (NR > 0) { print "]" }; print "]" }
' | jq -c .)
echo "batches=$BATCHES" >> $GITHUB_OUTPUT
echo "📊 Installing Java agent on $TOTAL hosts across $TOTAL_BATCHES batches"
install-batch:
needs: prepare
runs-on: self-hosted
strategy:
max-parallel: 1
matrix:
batch: ${{ fromJson(needs.prepare.outputs.batches) }}
steps:
- name: Install java agent on batch hosts
run: |
BATCH_HOSTS='${{ toJson(matrix.batch) }}'
BATCH_SIZE=$(echo "$BATCH_HOSTS" | jq '. | length')
SSH_USER="${{ vars.SSH_USER || 'ubuntu' }}"
echo "🚀 Installing Java agent on batch of $BATCH_SIZE hosts"
echo "$BATCH_HOSTS" | jq -r '.[]' | while read HOST; do
(
echo "📡 Installing Java agent on $HOST"
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa_$HOST
chmod 600 ~/.ssh/id_rsa_$HOST
ssh -i ~/.ssh/id_rsa_$HOST -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=30 "${SSH_USER}@${HOST}" 'cd /opt/appdynamics/appdsmartagent && sudo ./smartagentctl install java'
if [ $? -eq 0 ]
then
echo "✅ Completed Java agent installation on $HOST"
else
echo "❌ Failed to install Java agent on $HOST" >&2
echo "$HOST" >> /tmp/failed_hosts_$$
fi
rm -f ~/.ssh/id_rsa_$HOST
) &
done
wait
if [ -f /tmp/failed_hosts_$$ ]; then
echo "❌ Some hosts failed:"
cat /tmp/failed_hosts_$$
rm -f /tmp/failed_hosts_$$
exit 1
fi
echo "✅ Batch installation complete"
summary:
needs: [prepare, install-batch]
runs-on: self-hosted
if: always()
steps:
- name: Installation Summary
run: |
echo "📊 Java Agent Installation Summary"
echo "=================================="
echo "Total hosts: ${{ needs.prepare.outputs.total_hosts }}"
echo "Total batches: ${{ needs.prepare.outputs.total_batches }}"
echo "Status: ${{ needs.install-batch.result }}"