-
Notifications
You must be signed in to change notification settings - Fork 6
/
make_manifest.sh
executable file
·97 lines (79 loc) · 2.99 KB
/
make_manifest.sh
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
#!/bin/bash
set -e
template_prefix="ecs-broker"
infrastructure=$1
STEMCELL_OS=${STEMCELL_OS:-ubuntu}
if [ "$infrastructure" != "aws-ec2" ] && \
[ "$infrastructure" != "vsphere" ] && \
# [ "$infrastructure" != "vcloud" ] && \
[ "$infrastructure" != "warden" ] ; then
# echo "usage: ./make_manifest <warden|aws-ec2|vsphere|vcloud> "
echo "usage: ./make_manifest <warden|aws-ec2|vsphere> "
exit 1
fi
shift
echo "Should set the bosh target before proceeding!!!"
echo "Also tweak the templates/*properties.yml to add/modify any attributes or properties before manifest generation"
echo ""
BOSH_STATUS=$(bosh status)
DIRECTOR_UUID=$(echo "$BOSH_STATUS" | grep UUID | awk '{print $2}')
DIRECTOR_CPI=$(echo "$BOSH_STATUS" | grep CPI | awk '{print $2}')
DIRECTOR_NAME=$(echo "$BOSH_STATUS" | grep Name | awk '{print $2}')
NAME=${NAME:-$template_prefix-$infrastructure}
if [[ $DIRECTOR_NAME = "warden" ]]; then
if [[ $infrastructure != "warden" ]]; then
echo "Not targeting bosh-lite with warden CPI. Please use 'bosh target' before running this script."
exit 1
fi
fi
if [[ $infrastructure = "aws-ec2" ]]; then
if [[ $DIRECTOR_CPI != "aws" ]]; then
echo "Not targeting an AWS BOSH. Please use 'bosh target' before running this script."
exit 1
fi
fi
if [[ $infrastructure = "vsphere" ]]; then
if [[ $DIRECTOR_CPI != "vsphere" ]]; then
echo "Not targeting an vSphere. Please use 'bosh target' before running this script."
exit 1
fi
fi
#if [[ $infrastructure = "vcloud" ]]; then
# if [[ $DIRECTOR_CPI != "vcloud" ]]; then
# echo "Not targeting an vCloud. Please use 'bosh target' before running this script."
# exit 1
# fi
#fi
function latest_uploaded_stemcell {
bosh stemcells | grep bosh | grep $STEMCELL_OS | awk -F'|' '{ print $2, $3 }' | sort -nr -k2 | head -n1 | awk '{ print $1 }'
}
STEMCELL=${STEMCELL:-$(latest_uploaded_stemcell)}
if [[ "${STEMCELL}X" == "X" ]]; then
echo
echo "Uploading latest $DIRECTOR_CPI/$STEMCELL_OS stemcell..."
STEMCELL_URL=$(bosh public stemcells --full | grep $DIRECTOR_CPI | grep $STEMCELL_OS | sort -nr | head -n1 | awk '{ print $4 }')
bosh upload stemcell $STEMCELL_URL
fi
STEMCELL=${STEMCELL:-$(latest_uploaded_stemcell)}
templates=$(dirname $0)/templates
release=$templates/..
tmpdir=$release/tmp
mkdir -p $tmpdir
cp $templates/stub-normal.yml $tmpdir/stub-with-uuid.yml
echo $DIRECTOR_NAME $DIRECTOR_CPI $DIRECTOR_UUID $STEMCELL
perl -pi -e "s/PLACEHOLDER-DIRECTOR-UUID/$DIRECTOR_UUID/g" $tmpdir/stub-with-uuid.yml
perl -pi -e "s/NAME/$NAME/g" $tmpdir/stub-with-uuid.yml
perl -pi -e "s/STEMCELL/$STEMCELL/g" $tmpdir/stub-with-uuid.yml
spiff merge \
$templates/deployment.yml \
$templates/jobs.yml \
$templates/ecs-broker-properties.yml \
$templates/infrastructure-${infrastructure}.yml \
$tmpdir/stub-with-uuid.yml \
$* > $tmpdir/$NAME-manifest.yml
mv $tmpdir/$NAME-manifest.yml .
rm -rf $tmpdir
echo ""
echo "Generated bosh deployment manifest for ${infrastructure}: $NAME-manifest.yml"
bosh deployment $NAME-manifest.yml
bosh status