-
Notifications
You must be signed in to change notification settings - Fork 0
/
interroman
executable file
·91 lines (72 loc) · 3.09 KB
/
interroman
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
#!/bin/bash
# Exit on error
set -e
# Display Commands/dev-mode
# set -x
# Take app name as an argument:
NAME=$1
ORG=$2
SPACE=$3
# Set CF to use a seperate config file
export CF_HOME=~/tmp/interrogator/
# Get target and login information from environment.
USERNAME=$CF_USERNAME
PASSWORD=$CF_PASSWORD
API=$CF_API
# Login and target the app's space (and discard cf's chattiness)
cf api $API > /dev/null
cf auth $USERNAME $PASSWORD > /dev/null
cf target -o $ORG -s $SPACE > /dev/null
# Get the app's name, instances, quota, and routes
# and store them as json
CF_TRACE=true cf app $NAME | grep ',"name":' > ~/tmp/interrogator/app.json
# Assign them to env vars
# Core Maifest Attributes:
INTERROGATOR_APP_NAME=$(jq -r '.name' ~/tmp/interrogator/app.json)
# Saved for posterity so you can see how insane this was before going after the JSON:
# INTERROGATOR_INSTANCES=$(grep instances: ~/tmp/interrogator/interrogator_cf_app_with_trace.txt | awk '{print substr ($0,length,1)}')
# Now the sane way:
INTERROGATOR_INSTANCES=$(jq '.instances' ~/tmp/interrogator/app.json)
INTERROGATOR_MEMORY=$(jq '.memory' ~/tmp/interrogator/app.json)
INTERROGATOR_DISK=$(jq '.disk_quota' ~/tmp/interrogator/app.json)
INTERROGATOR_HOST=$(jq '.routes' ~/tmp/interrogator/app.json | jq '.[0] | .host')
INTERROGATOR_DOMAIN=$(jq '.routes' ~/tmp/interrogator/app.json | jq '.[0] | .domain.name')
# Optional Manifest Attributes:
INTERROGATOR_COMMAND=$(jq '.command' ~/tmp/interrogator/app.json)
INTERROGATOR_BUILDPACK=$(jq '.buildpack' ~/tmp/interrogator/app.json)
INTERROGATOR_TIMEOUT=$(jq '.health_check_timeout' ~/tmp/interrogator/app.json)
INTERROGATOR_SERVICES=$(jq '.services' ~/tmp/interrogator/app.json | jq '.[0] | .name')
# Initialize a manifest file and write the app details to it
INTERROGATOR_MANIFEST=~/tmp/interrogator/$INTERROGATOR_APP_NAME-manifest.yml
#Core manifest attributes:
echo '---' > $INTERROGATOR_MANIFEST
echo 'applications:' >> $INTERROGATOR_MANIFEST
echo "- name: $INTERROGATOR_APP_NAME" >> $INTERROGATOR_MANIFEST
echo " instances: $INTERROGATOR_INSTANCES" >> $INTERROGATOR_MANIFEST
echo " memory: ${INTERROGATOR_MEMORY}M" >> $INTERROGATOR_MANIFEST
echo " disk_quota: ${INTERROGATOR_DISK}M" >> $INTERROGATOR_MANIFEST
#Optional manifest attributes:
if [[ $INTERROGATOR_HOST != null ]]; then
echo " timeout: $INTERROGATOR_HOST" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_DOMAIN != null ]]; then
echo " timeout: $INTERROGATOR_DOMAIN" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_DOMAIN = null ]]; then
echo " no-route: true" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_COMMAND != null ]]; then
echo " command: $INTERROGATOR_COMMAND" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_BUILDPACK != null ]]; then
echo " buildpack: $INTERROGATOR_BUILDPACK" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_TIMEOUT != null ]]; then
echo " timeout: $INTERROGATOR_TIMEOUT" >> $INTERROGATOR_MANIFEST
fi
if [[ $INTERROGATOR_SERVICES != null ]]; then
echo " services:" >> $INTERROGATOR_MANIFEST
echo " - $INTERROGATOR_SERVICES" >> $INTERROGATOR_MANIFEST
fi
# Output created manifest
cat $INTERROGATOR_MANIFEST