bosh-gen 0.16.2 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +13 -5
  2. data/.rspec +3 -0
  3. data/.travis.yml +16 -0
  4. data/ChangeLog.md +110 -89
  5. data/Gemfile +7 -1
  6. data/Guardfile +4 -8
  7. data/README.md +52 -22
  8. data/Rakefile +10 -0
  9. data/bosh-gen.gemspec +7 -5
  10. data/lib/bosh/gen/cli.rb +20 -28
  11. data/lib/bosh/gen/generators/job_generator.rb +9 -10
  12. data/lib/bosh/gen/generators/job_generator/templates/jobs/%job_name%_simple/templates/bin/%job_name%_ctl.tt +5 -5
  13. data/lib/bosh/gen/generators/new_release_generator.rb +63 -68
  14. data/lib/bosh/gen/generators/new_release_generator/templates/jobs/%project_name_hyphenated%/templates/bin/%job_name%_ctl.tt +5 -5
  15. data/lib/bosh/gen/generators/new_release_generator/templates/jobs/%project_name_hyphenated%/templates/data/properties.sh.erb +6 -0
  16. data/lib/bosh/gen/generators/new_release_generator/templates/templates/infrastructure-aws-ec2.yml.tt +7 -5
  17. data/lib/bosh/gen/generators/new_release_generator/templates/templates/infrastructure-warden.yml.tt +3 -4
  18. data/lib/bosh/gen/generators/new_release_generator/templates/templates/jobs.yml.tt +3 -0
  19. data/lib/bosh/gen/generators/new_release_generator/templates/templates/make_manifest.tt +18 -2
  20. data/lib/bosh/gen/generators/new_release_generator/templates/templates/stub.yml.tt +2 -1
  21. data/lib/bosh/gen/settings.rb +61 -0
  22. data/lib/bosh/gen/version.rb +1 -1
  23. data/spec/fixtures/deployment_manifests/2_jobs_1_ip_8196_disk_with_numeric.yml +64 -0
  24. data/spec/fixtures/releases/s3test-boshrelease/.gitignore +18 -0
  25. data/spec/fixtures/releases/s3test-boshrelease/README.md +51 -0
  26. data/spec/fixtures/releases/s3test-boshrelease/Rakefile +15 -0
  27. data/spec/fixtures/releases/s3test-boshrelease/config/blobs.yml +1 -0
  28. data/spec/fixtures/releases/s3test-boshrelease/config/final.yml +5 -0
  29. data/spec/fixtures/releases/s3test-boshrelease/jobs/.gitkeep +0 -0
  30. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/monit +5 -0
  31. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/spec +13 -0
  32. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/bin/monit_debugger +13 -0
  33. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/bin/s3test_ctl +36 -0
  34. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/config/.gitkeep +0 -0
  35. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/config/s3test.conf.erb +5 -0
  36. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/data/properties.sh.erb +10 -0
  37. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/helpers/ctl_setup.sh +81 -0
  38. data/spec/fixtures/releases/s3test-boshrelease/jobs/s3test/templates/helpers/ctl_utils.sh +156 -0
  39. data/spec/fixtures/releases/s3test-boshrelease/packages/.gitkeep +0 -0
  40. data/spec/fixtures/releases/s3test-boshrelease/src/.gitkeep +0 -0
  41. data/spec/fixtures/releases/s3test-boshrelease/templates/deployment.yml +35 -0
  42. data/spec/fixtures/releases/s3test-boshrelease/templates/infrastructure-aws-ec2.yml +40 -0
  43. data/spec/fixtures/releases/s3test-boshrelease/templates/infrastructure-warden.yml +107 -0
  44. data/spec/fixtures/releases/s3test-boshrelease/templates/jobs.yml +30 -0
  45. data/spec/fixtures/releases/s3test-boshrelease/templates/make_manifest +54 -0
  46. data/spec/fixtures/releases/s3test-boshrelease/templates/stub.yml +13 -0
  47. data/spec/generators/deployment_manifest_generator_spec.rb +19 -14
  48. data/spec/generators/{jobs/webapp_job_generator_spec.rb → job_generator_spec.rb} +8 -13
  49. data/spec/generators/new_release_generator_spec.rb +70 -0
  50. data/spec/models/bosh_config_spec.rb +3 -3
  51. data/spec/models/deployment_manifest_spec.rb +16 -6
  52. data/spec/models/release_detection_spec.rb +6 -6
  53. data/spec/spec_helper.rb +27 -7
  54. data/spec/support/fog.rb +3 -0
  55. data/spec/{generators → support}/generator_spec_helper.rb +47 -6
  56. metadata +105 -36
  57. data/spec/models/extract_spec.rb +0 -10
@@ -0,0 +1,36 @@
1
+ #!/bin/bash
2
+
3
+ set -e # exit immediately if a simple command exits with a non-zero status
4
+ set -u # report the usage of uninitialized variables
5
+
6
+ # Setup env vars and folders for the webapp_ctl script
7
+ source /var/vcap/jobs/s3test/helpers/ctl_setup.sh 's3test'
8
+
9
+ export PORT=${PORT:-5000}
10
+ export LANG=en_US.UTF-8
11
+
12
+ case $1 in
13
+
14
+ start)
15
+ pid_guard $PIDFILE $JOB_NAME
16
+
17
+ # TODO: Run some process
18
+ exec chpst -u vcap:vcap TODO \
19
+ >>$LOG_DIR/$JOB_NAME.stdout.log \
20
+ 2>>$LOG_DIR/$JOB_NAME.stderr.log
21
+
22
+ # store pid in $PIDFILE
23
+ echo $! > $PIDFILE
24
+ ;;
25
+
26
+ stop)
27
+ kill_and_wait $PIDFILE
28
+
29
+ ;;
30
+ *)
31
+ echo "Usage: s3test_ctl {start|stop}"
32
+
33
+ ;;
34
+
35
+ esac
36
+ exit 0
@@ -0,0 +1,5 @@
1
+ # Example of how to do one thing when job is master/leader, and another thing if its follower/slave
2
+ # See templates/infrastructure-warden.yml & templates/jobs.yml for where this value originates
3
+ <% if_p("s3test.leader_address") do |leader_address| %>
4
+ leader: <%= leader_address %>
5
+ <% end %>
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # job template binding variables
4
+
5
+ # job name & index of this VM within cluster
6
+ # e.g. JOB_NAME=redis, JOB_INDEX=0
7
+ export NAME='<%= name %>'
8
+ export JOB_INDEX=<%= index %>
9
+ # full job name, like redis/0 or webapp/3
10
+ export JOB_FULL="$NAME/$JOB_INDEX"
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Setup env vars and folders for the ctl script
4
+ # This helps keep the ctl script as readable
5
+ # as possible
6
+
7
+ # Usage options:
8
+ # source /var/vcap/jobs/foobar/helpers/ctl_setup.sh JOB_NAME OUTPUT_LABEL
9
+ # source /var/vcap/jobs/foobar/helpers/ctl_setup.sh foobar
10
+ # source /var/vcap/jobs/foobar/helpers/ctl_setup.sh foobar foobar
11
+ # source /var/vcap/jobs/foobar/helpers/ctl_setup.sh foobar nginx
12
+
13
+ set -e # exit immediately if a simple command exits with a non-zero status
14
+ set -u # report the usage of uninitialized variables
15
+
16
+ JOB_NAME=$1
17
+ output_label=${1:-JOB_NAME}
18
+
19
+ export JOB_DIR=/var/vcap/jobs/$JOB_NAME
20
+ chmod 755 $JOB_DIR # to access file via symlink
21
+
22
+ # Load some bosh deployment properties into env vars
23
+ # Try to put all ERb into data/properties.sh.erb
24
+ # incl $NAME, $JOB_INDEX, $WEBAPP_DIR
25
+ source $JOB_DIR/data/properties.sh
26
+
27
+ source $JOB_DIR/helpers/ctl_utils.sh
28
+ redirect_output ${output_label}
29
+
30
+ export HOME=${HOME:-/home/vcap}
31
+
32
+ # Add all packages' /bin & /sbin into $PATH
33
+ for package_bin_dir in $(ls -d /var/vcap/packages/*/*bin)
34
+ do
35
+ export PATH=${package_bin_dir}:$PATH
36
+ done
37
+
38
+ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-''} # default to empty
39
+ for package_bin_dir in $(ls -d /var/vcap/packages/*/lib)
40
+ do
41
+ export LD_LIBRARY_PATH=${package_bin_dir}:$LD_LIBRARY_PATH
42
+ done
43
+
44
+ # Setup log, run and tmp folders
45
+
46
+ export RUN_DIR=/var/vcap/sys/run/$JOB_NAME
47
+ export LOG_DIR=/var/vcap/sys/log/$JOB_NAME
48
+ export TMP_DIR=/var/vcap/sys/tmp/$JOB_NAME
49
+ export STORE_DIR=/var/vcap/store/$JOB_NAME
50
+ for dir in $RUN_DIR $LOG_DIR $TMP_DIR $STORE_DIR
51
+ do
52
+ mkdir -p ${dir}
53
+ chown vcap:vcap ${dir}
54
+ chmod 775 ${dir}
55
+ done
56
+ export TMPDIR=$TMP_DIR
57
+
58
+ export C_INCLUDE_PATH=/var/vcap/packages/mysqlclient/include/mysql:/var/vcap/packages/sqlite/include:/var/vcap/packages/libpq/include
59
+ export LIBRARY_PATH=/var/vcap/packages/mysqlclient/lib/mysql:/var/vcap/packages/sqlite/lib:/var/vcap/packages/libpq/lib
60
+
61
+ # consistent place for vendoring python libraries within package
62
+ if [[ -d ${WEBAPP_DIR:-/xxxx} ]]
63
+ then
64
+ export PYTHONPATH=$WEBAPP_DIR/vendor/lib/python
65
+ fi
66
+
67
+ if [[ -d /var/vcap/packages/java7 ]]
68
+ then
69
+ export JAVA_HOME="/var/vcap/packages/java7"
70
+ fi
71
+
72
+ # setup CLASSPATH for all jars/ folders within packages
73
+ export CLASSPATH=${CLASSPATH:-''} # default to empty
74
+ for java_jar in $(ls -d /var/vcap/packages/*/*/*.jar)
75
+ do
76
+ export CLASSPATH=${java_jar}:$CLASSPATH
77
+ done
78
+
79
+ PIDFILE=$RUN_DIR/$JOB_NAME.pid
80
+
81
+ echo '$PATH' $PATH
@@ -0,0 +1,156 @@
1
+ # Helper functions used by ctl scripts
2
+
3
+ # links a job file (probably a config file) into a package
4
+ # Example usage:
5
+ # link_job_file_to_package config/redis.yml [config/redis.yml]
6
+ # link_job_file_to_package config/wp-config.php wp-config.php
7
+ link_job_file_to_package() {
8
+ source_job_file=$1
9
+ target_package_file=${2:-$source_job_file}
10
+ full_package_file=$WEBAPP_DIR/${target_package_file}
11
+
12
+ link_job_file ${source_job_file} ${full_package_file}
13
+ }
14
+
15
+ # links a job file (probably a config file) somewhere
16
+ # Example usage:
17
+ # link_job_file config/bashrc /home/vcap/.bashrc
18
+ link_job_file() {
19
+ source_job_file=$1
20
+ target_file=$2
21
+ full_job_file=$JOB_DIR/${source_job_file}
22
+
23
+ echo link_job_file ${full_job_file} ${target_file}
24
+ if [[ ! -f ${full_job_file} ]]
25
+ then
26
+ echo "file to link ${full_job_file} does not exist"
27
+ else
28
+ # Create/recreate the symlink to current job file
29
+ # If another process is using the file, it won't be
30
+ # deleted, so don't attempt to create the symlink
31
+ mkdir -p $(dirname ${target_file})
32
+ ln -nfs ${full_job_file} ${target_file}
33
+ fi
34
+ }
35
+
36
+ # If loaded within monit ctl scripts then pipe output
37
+ # If loaded from 'source ../utils.sh' then normal STDOUT
38
+ redirect_output() {
39
+ SCRIPT=$1
40
+ mkdir -p /var/vcap/sys/log/monit
41
+ exec 1>> /var/vcap/sys/log/monit/$SCRIPT.log
42
+ exec 2>> /var/vcap/sys/log/monit/$SCRIPT.err.log
43
+ }
44
+
45
+ pid_guard() {
46
+ pidfile=$1
47
+ name=$2
48
+
49
+ if [ -f "$pidfile" ]; then
50
+ pid=$(head -1 "$pidfile")
51
+
52
+ if [ -n "$pid" ] && [ -e /proc/$pid ]; then
53
+ echo "$name is already running, please stop it first"
54
+ exit 1
55
+ fi
56
+
57
+ echo "Removing stale pidfile..."
58
+ rm $pidfile
59
+ fi
60
+ }
61
+
62
+ wait_pid() {
63
+ pid=$1
64
+ try_kill=$2
65
+ timeout=${3:-0}
66
+ force=${4:-0}
67
+ countdown=$(( $timeout * 10 ))
68
+
69
+ echo wait_pid $pid $try_kill $timeout $force $countdown
70
+ if [ -e /proc/$pid ]; then
71
+ if [ "$try_kill" = "1" ]; then
72
+ echo "Killing $pidfile: $pid "
73
+ kill $pid
74
+ fi
75
+ while [ -e /proc/$pid ]; do
76
+ sleep 0.1
77
+ [ "$countdown" != '0' -a $(( $countdown % 10 )) = '0' ] && echo -n .
78
+ if [ $timeout -gt 0 ]; then
79
+ if [ $countdown -eq 0 ]; then
80
+ if [ "$force" = "1" ]; then
81
+ echo -ne "\nKill timed out, using kill -9 on $pid... "
82
+ kill -9 $pid
83
+ sleep 0.5
84
+ fi
85
+ break
86
+ else
87
+ countdown=$(( $countdown - 1 ))
88
+ fi
89
+ fi
90
+ done
91
+ if [ -e /proc/$pid ]; then
92
+ echo "Timed Out"
93
+ else
94
+ echo "Stopped"
95
+ fi
96
+ else
97
+ echo "Process $pid is not running"
98
+ echo "Attempting to kill pid anyway..."
99
+ kill $pid
100
+ fi
101
+ }
102
+
103
+ wait_pidfile() {
104
+ pidfile=$1
105
+ try_kill=$2
106
+ timeout=${3:-0}
107
+ force=${4:-0}
108
+ countdown=$(( $timeout * 10 ))
109
+
110
+ if [ -f "$pidfile" ]; then
111
+ pid=$(head -1 "$pidfile")
112
+ if [ -z "$pid" ]; then
113
+ echo "Unable to get pid from $pidfile"
114
+ exit 1
115
+ fi
116
+
117
+ wait_pid $pid $try_kill $timeout $force
118
+
119
+ rm -f $pidfile
120
+ else
121
+ echo "Pidfile $pidfile doesn't exist"
122
+ fi
123
+ }
124
+
125
+ kill_and_wait() {
126
+ pidfile=$1
127
+ # Monit default timeout for start/stop is 30s
128
+ # Append 'with timeout {n} seconds' to monit start/stop program configs
129
+ timeout=${2:-25}
130
+ force=${3:-1}
131
+ if [[ -f ${pidfile} ]]
132
+ then
133
+ wait_pidfile $pidfile 1 $timeout $force
134
+ else
135
+ # TODO assume $1 is something to grep from 'ps ax'
136
+ pid="$(ps auwwx | grep "$1" | awk '{print $2}')"
137
+ wait_pid $pid 1 $timeout $force
138
+ fi
139
+ }
140
+
141
+ check_nfs_mount() {
142
+ opts=$1
143
+ exports=$2
144
+ mount_point=$3
145
+
146
+ if grep -qs $mount_point /proc/mounts; then
147
+ echo "Found NFS mount $mount_point"
148
+ else
149
+ echo "Mounting NFS..."
150
+ mount $opts $exports $mount_point
151
+ if [ $? != 0 ]; then
152
+ echo "Cannot mount NFS from $exports to $mount_point, exiting..."
153
+ exit 1
154
+ fi
155
+ fi
156
+ }
@@ -0,0 +1,35 @@
1
+ meta:
2
+ environment: (( merge ))
3
+ stemcell: (( merge ))
4
+
5
+ name: (( meta.environment ))
6
+
7
+ director_uuid: (( merge ))
8
+
9
+ releases: (( merge ))
10
+
11
+ networks: (( merge ))
12
+
13
+ jobs: (( merge ))
14
+
15
+ properties: (( merge ))
16
+
17
+ compilation:
18
+ workers: 6
19
+ network: s3test1
20
+ reuse_compilation_vms: true
21
+ cloud_properties: (( merge ))
22
+
23
+ update:
24
+ canaries: 1
25
+ max_in_flight: 1
26
+ canary_watch_time: 30000-60000
27
+ update_watch_time: 5000-60000
28
+ serial: false
29
+
30
+ resource_pools:
31
+ - name: small_z1
32
+ network: s3test1
33
+ size: (( auto ))
34
+ stemcell: (( meta.stemcell ))
35
+ cloud_properties: (( merge ))
@@ -0,0 +1,40 @@
1
+ meta:
2
+ environment: (( merge ))
3
+ dns_root: (( merge ))
4
+ security_groups: (( merge ))
5
+ network_name: (( merge ))
6
+
7
+ stemcell:
8
+ name: bosh-aws-xen-ubuntu
9
+ version: latest
10
+
11
+ jobs:
12
+ - name: s3test_leader_z1
13
+ instances: 1
14
+ networks:
15
+ - name: (( meta.network_name ))
16
+ - name: s3test_z1
17
+ instances: 2
18
+ networks:
19
+ - name: (( meta.network_name ))
20
+ properties:
21
+ s3test:
22
+ leader_address: (( "0.s3test-leader-z1.s3test1." meta.environment "." meta.dns_root ))
23
+
24
+ compilation:
25
+ cloud_properties:
26
+ instance_type: m1.small
27
+
28
+ resource_pools:
29
+ - name: small_z1
30
+ cloud_properties:
31
+ instance_type: m1.small
32
+
33
+ networks:
34
+ - name: floating
35
+ type: vip
36
+ cloud_properties: {}
37
+ - name: (( meta.network_name ))
38
+ type: dynamic
39
+ cloud_properties:
40
+ security_groups: (( meta.security_groups ))
@@ -0,0 +1,107 @@
1
+ meta:
2
+ environment: s3test-warden
3
+ network_name: (( merge ))
4
+
5
+ stemcell:
6
+ name: bosh-warden-boshlite-ubuntu
7
+ version: latest
8
+
9
+ update:
10
+ canaries: 1
11
+ max_in_flight: 50
12
+ canary_watch_time: 1000-30000
13
+ update_watch_time: 1000-30000
14
+
15
+ jobs:
16
+ - name: s3test_leader_z1
17
+ instances: 1
18
+ networks:
19
+ - name: (( meta.network_name ))
20
+ static_ips: (( static_ips(0) ))
21
+ - name: s3test_z1
22
+ instances: 2
23
+ networks:
24
+ - name: (( meta.network_name ))
25
+ static_ips: ~
26
+ properties:
27
+ s3test:
28
+ leader_address: (( jobs.s3test_leader_z1.networks.s3test1.static_ips.[0] ))
29
+
30
+ compilation:
31
+ cloud_properties:
32
+ name: random
33
+
34
+ resource_pools:
35
+ - name: small_z1
36
+ cloud_properties:
37
+ name: random
38
+
39
+ networks:
40
+ - name: (( meta.network_name ))
41
+ # Assumes up to 5 VMs, including 1 static and 4 dynamic.
42
+ # Plus 5 (double the size) unused IPs, due to BOSH bug/quirk.
43
+ subnets:
44
+ - cloud_properties:
45
+ name: random
46
+ range: 10.244.2.0/30
47
+ reserved:
48
+ - 10.244.2.1
49
+ static:
50
+ - 10.244.2.2
51
+
52
+ - cloud_properties:
53
+ name: random
54
+ range: 10.244.2.4/30
55
+ reserved:
56
+ - 10.244.2.5
57
+ static: []
58
+ - cloud_properties:
59
+ name: random
60
+ range: 10.244.2.8/30
61
+ reserved:
62
+ - 10.244.2.9
63
+ static: []
64
+ - cloud_properties:
65
+ name: random
66
+ range: 10.244.2.12/30
67
+ reserved:
68
+ - 10.244.2.13
69
+ static: []
70
+ - cloud_properties:
71
+ name: random
72
+ range: 10.244.2.16/30
73
+ reserved:
74
+ - 10.244.2.17
75
+ static: []
76
+
77
+ # Bonus double-sized network required due to BOSH oddity
78
+ - cloud_properties:
79
+ name: random
80
+ range: 10.244.2.20/30
81
+ reserved:
82
+ - 10.244.2.21
83
+ static: []
84
+ - cloud_properties:
85
+ name: random
86
+ range: 10.244.2.24/30
87
+ reserved:
88
+ - 10.244.2.25
89
+ static: []
90
+ - cloud_properties:
91
+ name: random
92
+ range: 10.244.2.28/30
93
+ reserved:
94
+ - 10.244.2.29
95
+ static: []
96
+ - cloud_properties:
97
+ name: random
98
+ range: 10.244.2.32/30
99
+ reserved:
100
+ - 10.244.2.33
101
+ static: []
102
+ - cloud_properties:
103
+ name: random
104
+ range: 10.244.2.36/30
105
+ reserved:
106
+ - 10.244.2.37
107
+ static: []