bosh-bootstrap 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +318 -0
  5. data/Rakefile +1 -0
  6. data/bin/bosh-bootstrap +8 -0
  7. data/bosh-bootstrap.gemspec +34 -0
  8. data/lib/bosh-bootstrap.rb +10 -0
  9. data/lib/bosh-bootstrap/cli.rb +1024 -0
  10. data/lib/bosh-bootstrap/commander.rb +9 -0
  11. data/lib/bosh-bootstrap/commander/README.md +47 -0
  12. data/lib/bosh-bootstrap/commander/command.rb +25 -0
  13. data/lib/bosh-bootstrap/commander/commands.rb +80 -0
  14. data/lib/bosh-bootstrap/commander/local_server.rb +68 -0
  15. data/lib/bosh-bootstrap/commander/remote_script_command.rb +48 -0
  16. data/lib/bosh-bootstrap/commander/remote_server.rb +121 -0
  17. data/lib/bosh-bootstrap/commander/upload_command.rb +17 -0
  18. data/lib/bosh-bootstrap/helpers.rb +2 -0
  19. data/lib/bosh-bootstrap/helpers/fog_setup.rb +50 -0
  20. data/lib/bosh-bootstrap/helpers/settings.rb +36 -0
  21. data/lib/bosh-bootstrap/stages.rb +8 -0
  22. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete.rb +90 -0
  23. data/lib/bosh-bootstrap/stages/stage_micro_bosh_delete/bosh_micro_delete +19 -0
  24. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy.rb +135 -0
  25. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/bosh_micro_deploy +36 -0
  26. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/download_micro_bosh_stemcell +132 -0
  27. data/lib/bosh-bootstrap/stages/stage_micro_bosh_deploy/install_key_pair_for_user +23 -0
  28. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm.rb +52 -0
  29. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/convert_salted_password +9 -0
  30. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/create_vcap_user +79 -0
  31. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_base_packages +13 -0
  32. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_bosh +54 -0
  33. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_ruby +33 -0
  34. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/install_useful_gems +24 -0
  35. data/lib/bosh-bootstrap/stages/stage_prepare_inception_vm/validate_bosh_deployer +21 -0
  36. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh.rb +52 -0
  37. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh/cleanup_permissions +14 -0
  38. data/lib/bosh-bootstrap/stages/stage_setup_new_bosh/setup_bosh_user +29 -0
  39. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm.rb +39 -0
  40. data/lib/bosh-bootstrap/stages/stage_validate_inception_vm/validate_ubuntu +6 -0
  41. data/lib/bosh-bootstrap/version.rb +5 -0
  42. data/lib/bosh/providers.rb +21 -0
  43. data/lib/bosh/providers/README.md +5 -0
  44. data/lib/bosh/providers/aws.rb +77 -0
  45. data/lib/bosh/providers/base_provider.rb +20 -0
  46. data/lib/bosh/providers/openstack.rb +40 -0
  47. metadata +239 -0
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2012-2013 Stark & Wayne, LLC
2
+
3
+ require "settingslogic"
4
+ module Bosh; module Bootstrap; module Helpers; end; end; end
5
+
6
+ # Helper methods for loading/saving settings
7
+ module Bosh::Bootstrap::Helpers::Settings
8
+ # Previously selected settings are stored in a YAML manifest
9
+ # Protects the manifest file with user-only priveleges
10
+ def settings
11
+ @settings ||= begin
12
+ FileUtils.mkdir_p(File.dirname(settings_path))
13
+ unless File.exists?(settings_path)
14
+ File.open(settings_path, "w") do |file|
15
+ file << {}.to_yaml
16
+ end
17
+ end
18
+ FileUtils.chmod 0600, settings_path
19
+ Settingslogic.new(settings_path)
20
+ end
21
+ end
22
+
23
+ def save_settings!
24
+ File.open(settings_path, "w") do |file|
25
+ raw_settings_yaml = settings.to_yaml.gsub(" !ruby/hash:Settingslogic", "")
26
+ file << raw_settings_yaml
27
+ end
28
+ @settings = nil # force to reload & recreate helper methods
29
+ end
30
+
31
+ def settings_path
32
+ manifest_path = ENV["MANIFEST"] || "~/.bosh_bootstrap/manifest.yml"
33
+ File.expand_path(manifest_path)
34
+ end
35
+
36
+ end
@@ -0,0 +1,8 @@
1
+ module Bosh::Bootstrap::Stages
2
+ end
3
+
4
+ require "bosh-bootstrap/stages/stage_validate_inception_vm"
5
+ require "bosh-bootstrap/stages/stage_prepare_inception_vm"
6
+ require "bosh-bootstrap/stages/stage_micro_bosh_deploy"
7
+ require "bosh-bootstrap/stages/stage_setup_new_bosh"
8
+ require "bosh-bootstrap/stages/stage_micro_bosh_delete"
@@ -0,0 +1,90 @@
1
+ require "json" # for inline hashes within YAML
2
+
3
+ module Bosh::Bootstrap::Stages
4
+ class MicroBoshDelete
5
+ attr_reader :settings
6
+
7
+ def initialize(settings)
8
+ @settings = settings
9
+ end
10
+
11
+ def commands
12
+ @commands ||= Bosh::Bootstrap::Commander::Commands.new do |server|
13
+ server.delete "micro bosh", script("bosh_micro_delete",
14
+ "BOSH_NAME" => settings.bosh_name)
15
+ end
16
+ end
17
+
18
+ private
19
+ def stage_name
20
+ "stage_micro_bosh_delete"
21
+ end
22
+
23
+ # Loads local script
24
+ # If +variables+, then injects KEY=VALUE environment
25
+ # variables into bash scripts.
26
+ def script(segment_name, variables={})
27
+ path = File.expand_path("../#{stage_name}/#{segment_name}", __FILE__)
28
+ if File.exist?(path)
29
+ script = File.read(path)
30
+ if variables.keys.size > 0
31
+ # inject variables into script if its bash script
32
+ inline_variables = "#!/usr/bin/env bash\n\n"
33
+ variables.each { |name, value| inline_variables << "#{name}='#{value}'\n" }
34
+ script.gsub!("#!/usr/bin/env bash", inline_variables)
35
+
36
+ # inject variables into script if its ruby script
37
+ inline_variables = "#!/usr/bin/env ruby\n\n"
38
+ variables.each { |name, value| inline_variables << "ENV['#{name}'] = '#{value}'\n" }
39
+ script.gsub!("#!/usr/bin/env ruby", inline_variables)
40
+ end
41
+ script
42
+ else
43
+ Thor::Base.shell.new.say_status "error", "Missing script lib/bosh-bootstrap/stages/#{stage_name}/#{segment_name}", :red
44
+ exit 1
45
+ end
46
+ end
47
+
48
+ def micro_bosh_manifest
49
+ name = settings.bosh_name
50
+ salted_password = settings.bosh.salted_password
51
+ ipaddress = settings.bosh.ip_address
52
+ persistent_disk = settings.bosh.persistent_disk
53
+ resources_cloud_properties = settings.bosh_resources_cloud_properties
54
+ cloud_plugin = settings.bosh_provider
55
+
56
+ # aws:
57
+ # access_key_id: #{access_key}
58
+ # secret_access_key: #{secret_key}
59
+ # ec2_endpoint: ec2.#{region}.amazonaws.com
60
+ # default_key_name: #{key_name}
61
+ # default_security_groups: ["#{security_group}"]
62
+ # ec2_private_key: /home/vcap/.ssh/#{key_name}.pem
63
+ cloud_properties = settings.bosh_cloud_properties
64
+
65
+ {
66
+ "name" => name,
67
+ "env" => { "bosh" => {"password" => salted_password}},
68
+ "logging" => { "level" => "DEBUG" },
69
+ "network" => { "type" => "dynamic", "vip" => ipaddress },
70
+ "resources" => {
71
+ "persistent_disk" => persistent_disk,
72
+ "cloud_properties" => resources_cloud_properties
73
+ },
74
+ "cloud" => {
75
+ "plugin" => cloud_plugin,
76
+ "properties" => cloud_properties
77
+ },
78
+ "apply_spec" => {
79
+ "agent" => {
80
+ "blobstore" => { "address" => ipaddress },
81
+ "nats" => { "address" => ipaddress }
82
+ },
83
+ "properties" => {
84
+ "#{cloud_plugin.downcase}_registry" => { "address" => ipaddress }
85
+ }
86
+ }
87
+ }.to_yaml.gsub(" !ruby/hash:Settingslogic", "")
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Deletes a micro BOSH using "bosh micro delete"
4
+ #
5
+ # Required:
6
+ # * $BOSH_NAME - name of bosh deployment
7
+ # (thus /var/vcap/store/microboshes/deployments/$BOSH_NAME/micro_bosh.yml exists)
8
+
9
+ set -e # exit immediately if a simple command exits with a non-zero status
10
+ set -u # report the usage of uninitialized variables
11
+
12
+ # TODO in preparation for http://reviews.cloudfoundry.org/#/c/11976/
13
+ export COLUMNS=80 # force a small width for progress bar
14
+
15
+ cd /var/vcap/store/microboshes/deployments/
16
+ bosh -n micro deployment $BOSH_NAME
17
+
18
+ echo "Deleting deployment of micro BOSH $BOSH_NAME"
19
+ bosh -n micro delete
@@ -0,0 +1,135 @@
1
+ require "json" # for inline hashes within YAML
2
+
3
+ module Bosh::Bootstrap::Stages
4
+ class MicroBoshDeploy
5
+ attr_reader :settings
6
+
7
+ def initialize(settings)
8
+ @settings = settings
9
+ end
10
+
11
+ # TODO "aws_us_east_1" should come from settings.bosh_name
12
+ def commands
13
+ settings[:bosh_name] ||= "unnamed_bosh"
14
+
15
+ @commands ||= Bosh::Bootstrap::Commander::Commands.new do |server|
16
+ server.download "micro-bosh stemcell", script("download_micro_bosh_stemcell",
17
+ "MICRO_BOSH_STEMCELL_NAME" => settings.micro_bosh_stemcell_name,
18
+ "PROVIDER" => settings.bosh_provider,
19
+ :settings => settings, :save_output_to_settings_key => "micro_bosh_stemcell_name")
20
+ server.upload_file \
21
+ "/var/vcap/store/microboshes/deployments/#{settings.bosh_name}/micro_bosh.yml",
22
+ micro_bosh_manifest
23
+ server.install "key pair for user", script("install_key_pair_for_user",
24
+ "PRIVATE_KEY" => settings.bosh_key_pair.private_key,
25
+ "KEY_PAIR_NAME" => settings.bosh_key_pair.name)
26
+ server.deploy "micro bosh", script("bosh_micro_deploy",
27
+ "BOSH_NAME" => settings.bosh_name,
28
+ "MICRO_BOSH_STEMCELL_NAME" => settings.micro_bosh_stemcell_name,
29
+ "BOSH_HOST" => settings.bosh.ip_address,
30
+ "BOSH_USERNAME" => settings.bosh_username,
31
+ "BOSH_PASSWORD" => settings.bosh_password)
32
+ end
33
+ end
34
+
35
+ private
36
+ def stage_name
37
+ "stage_micro_bosh_deploy"
38
+ end
39
+
40
+ # Loads local script
41
+ # If +variables+, then injects KEY=VALUE environment
42
+ # variables into bash scripts.
43
+ def script(segment_name, variables={})
44
+ path = File.expand_path("../#{stage_name}/#{segment_name}", __FILE__)
45
+ if File.exist?(path)
46
+ script = File.read(path)
47
+ if variables.keys.size > 0
48
+ # inject variables into script if its bash script
49
+ inline_variables = "#!/usr/bin/env bash\n\n"
50
+ variables.each { |name, value| inline_variables << "#{name}='#{value}'\n" }
51
+ script.gsub!("#!/usr/bin/env bash", inline_variables)
52
+
53
+ # inject variables into script if its ruby script
54
+ inline_variables = "#!/usr/bin/env ruby\n\n"
55
+ variables.each { |name, value| inline_variables << "ENV['#{name}'] = '#{value}'\n" }
56
+ script.gsub!("#!/usr/bin/env ruby", inline_variables)
57
+ end
58
+ script
59
+ else
60
+ Thor::Base.shell.new.say_status "error", "Missing script lib/bosh-bootstrap/stages/#{stage_name}/#{segment_name}", :red
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ def micro_bosh_manifest
66
+ name = settings.bosh_name
67
+ salted_password = settings.bosh.salted_password
68
+ ipaddress = settings.bosh.ip_address
69
+ persistent_disk = settings.bosh.persistent_disk
70
+ resources_cloud_properties = settings.bosh_resources_cloud_properties
71
+ cloud_plugin = settings.bosh_provider
72
+
73
+ # aws:
74
+ # access_key_id: #{access_key}
75
+ # secret_access_key: #{secret_key}
76
+ # ec2_endpoint: ec2.#{region}.amazonaws.com
77
+ # default_key_name: #{key_name}
78
+ # default_security_groups: ["#{security_group}"]
79
+ # ec2_private_key: /home/vcap/.ssh/#{key_name}.pem
80
+ cloud_properties = settings.bosh_cloud_properties
81
+
82
+ {
83
+ "name" => name,
84
+ "env" => { "bosh" => {"password" => salted_password}},
85
+ "logging" => { "level" => "DEBUG" },
86
+ "network" => { "type" => "dynamic", "vip" => ipaddress },
87
+ "resources" => {
88
+ "persistent_disk" => persistent_disk,
89
+ "cloud_properties" => resources_cloud_properties
90
+ },
91
+ "cloud" => {
92
+ "plugin" => cloud_plugin,
93
+ "properties" => cloud_properties
94
+ },
95
+ "apply_spec" => {
96
+ "agent" => {
97
+ "blobstore" => { "address" => ipaddress },
98
+ "nats" => { "address" => ipaddress }
99
+ },
100
+ "properties" => {
101
+ "#{cloud_plugin.downcase}_registry" => { "address" => ipaddress }
102
+ }
103
+ }
104
+ }.to_yaml.gsub(/\s![^ ]+$/, '')
105
+
106
+ # /![^ ]+\s/ removes object notation from the YAML which appears to cause problems when being interpretted by the
107
+ # Ruby running on the inception vm. A before and after example would look like;
108
+ #
109
+ # properties: !map:Settingslogic
110
+ # openstack: !map:Settingslogic
111
+ # username: admin
112
+ # api_key: xxxxxxxxxxxxxxxxxxx
113
+ # tenant: CloudFoundry
114
+ # auth_url: http://192.168.1.2:5000/v2.0/tokens
115
+ # default_security_groups:
116
+ # - !str:HighLine::String microbosh-openstack
117
+ # default_key_name: !str:HighLine::String microbosh-openstack
118
+ # private_key: /home/vcap/.ssh/microbosh-openstack.pem
119
+ #
120
+ # The regex strips the !Module::ClassName notation out and the result looks as it should
121
+ #
122
+ # properties:
123
+ # openstack:
124
+ # username: admin
125
+ # api_key: xxxxxxxxxxxxxxxxxxx
126
+ # tenant: CloudFoundry
127
+ # auth_url: http://192.168.1.2:5000/v2.0/tokens
128
+ # default_security_groups:
129
+ # - microbosh-openstack
130
+ # default_key_name: microbosh-openstack
131
+ # private_key: /home/vcap/.ssh/microbosh-openstack.pem
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Deploys a micro BOSH using "bosh micro deploy"
4
+ #
5
+ # Required:
6
+ # * $BOSH_NAME - name of bosh deployment
7
+ # (thus /var/vcap/store/microboshes/deployments/$BOSH_NAME/micro_bosh.yml exists)
8
+ # * $MICRO_BOSH_STEMCELL_NAME - public stemcell name at
9
+ # /var/vcap/store/stemcells/$MICRO_BOSH_STEMCELL_NAME
10
+
11
+ set -e # exit immediately if a simple command exits with a non-zero status
12
+ set -u # report the usage of uninitialized variables
13
+
14
+ MICRO_BOSH_STEMCELL_PATH=/var/vcap/store/stemcells/$MICRO_BOSH_STEMCELL_NAME
15
+
16
+ export COLUMNS=80 # force a small width for progress bar
17
+ export TMPDIR=/var/vcap/store/tmp
18
+
19
+ cd /var/vcap/store/microboshes/deployments/
20
+ bosh -n micro deployment $BOSH_NAME
21
+
22
+ if [[ "${MICRO_BOSH_STEMCELL_NAME}" == "custom" ]]; then
23
+ MICRO_BOSH_STEMCELL_PATH=$(ls -t /var/tmp/bosh/agent-*/work/work/*.tgz | sort | tail -n 1)
24
+ echo "Custom stemcell path $MICRO_BOSH_STEMCELL_PATH"
25
+ else
26
+ echo "Downloaded stemcell path $MICRO_BOSH_STEMCELL_PATH"
27
+ fi
28
+
29
+ if [[ -f bosh-deployments.yml && "$(grep $BOSH_NAME bosh-deployments.yml)" != "" ]]; then
30
+ echo "Performing update deploy to micro BOSH $BOSH_NAME"
31
+ bosh -n micro deploy $MICRO_BOSH_STEMCELL_PATH --update
32
+ else
33
+ echo "Performing initial deploy of micro BOSH $BOSH_NAME"
34
+ bosh -n micro deploy $MICRO_BOSH_STEMCELL_PATH
35
+ touch $BOSH_NAME/new_bosh_deployed # to communicate with setup_bosh_user script
36
+ fi
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Downloads a public stemcell for CPI into /var/vcap/store/stemcells/
4
+ #
5
+ # Required:
6
+ # * $MICRO_BOSH_STEMCELL_NAME - public stemcell name to be downloaded
7
+ # - if 'custom' the create stemcell from BOSH source
8
+ #
9
+ # Optional:
10
+ # * $PROVIDER - required for 'custom' $MICRO_BOSH_STEMCELL_NAME; e.g. aws, openstack
11
+ # * $BOSH_RELEASE_REPO - defaults to https://github.com/cloudfoundry/bosh-release.git
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
+ if [[ $EUID -ne 0 ]]; then
17
+ echo "ERROR: This script must be run as root" 1>&2
18
+ exit 1
19
+ fi
20
+
21
+ if [[ "${MICRO_BOSH_STEMCELL_NAME}X" == "X" ]]; then
22
+ echo 'INTERNAL ERROR: Missing $MICRO_BOSH_STEMCELL_NAME environment variable'
23
+ exit 1
24
+ fi
25
+
26
+ if [[ "${MICRO_BOSH_STEMCELL_NAME}" == "custom" ]]; then
27
+
28
+ BOSH_RELEASE_REPO=${BOSH_RELEASE_REPO:-'https://github.com/cloudfoundry/bosh-release.git'}
29
+ BOSH_RELEASE_DIRNAME=${BOSH_RELEASE_DIRNAME:-'bosh-release'}
30
+ BOSH_RELEASE_DIR=/var/vcap/store/releases/$BOSH_RELEASE_DIRNAME
31
+
32
+ echo "Creating custom stemcell..."
33
+
34
+ if [[ -d /var/tmp/bosh/ ]]; then
35
+ echo "But first, cleaning out previous stemcell temporary files..."
36
+ rm -rf /var/tmp/bosh
37
+ fi
38
+
39
+
40
+ cd $(dirname $BOSH_RELEASE_DIR)
41
+ if [[ -d $BOSH_RELEASE_DIRNAME ]]; then
42
+ echo "Updating BOSH's own bosh-release for custom stemcell"
43
+ cd $BOSH_RELEASE_DIRNAME
44
+ git pull origin master
45
+ else
46
+ echo "Fetching BOSH's own bosh-release for custom stemcell"
47
+ git clone $BOSH_RELEASE_REPO
48
+ cd $BOSH_RELEASE_DIRNAME
49
+ fi
50
+
51
+ echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
52
+
53
+ echo "Rewriting all git:// & git@ to https:// to allow access if port 22 is blocked..."
54
+ # Snippet written by Mike Reeves <swampfoxmr@gmail.com> on bosh-users mailing list
55
+ # Date 2012-12-06
56
+ grep -rI "git[@:/]\{0,3\}github.com" * .gitmodules | awk 'BEGIN {FS=":"} { print($1) }' | while read file
57
+ do
58
+ echo "changing - $file"
59
+ sed -i 's/git\:\/\/github.com/https:\/\/github.com/g' $file
60
+ sed -i 's/git@github.com:/https:\/\/github.com\//g' $file
61
+ done
62
+
63
+ echo "Updating source submodules..."
64
+ git submodule update --init
65
+
66
+ echo "Within submodules, rewriting all git:// & git@ to https:// to allow access if port 22 is blocked..."
67
+ # Snippet written by Mike Reeves <swampfoxmr@gmail.com> on bosh-users mailing list
68
+ # Date 2012-12-06
69
+ grep -rI "git[@:/]\{0,3\}github.com" * .gitmodules | awk 'BEGIN {FS=":"} { print($1) }' | while read file
70
+ do
71
+ echo "changing - $file"
72
+ sed -i 's/git\:\/\/github.com/https:\/\/github.com/g' $file
73
+ sed -i 's/git@github.com:/https:\/\/github.com\//g' $file
74
+ done
75
+
76
+ echo "Creating bosh release (fetching any new blobs)..."
77
+ bosh -n create release --force --with-tarball
78
+
79
+ # dev_releases/index.yml contains the dev_releases
80
+ # and its last line contains the latest dev_release name
81
+ # For example:
82
+ # ---
83
+ # builds:
84
+ # 4800ad1226e2b673595a8646e8e11bc968ab6ab6:
85
+ # version: 119.1-dev
86
+ # 7e0318d711daf0a5fa2e65c0257cd3b6af2ec4e5:
87
+ # version: 119.2-dev
88
+ #
89
+ # So to get the latest dev_release name, grab the last line's 2nd token
90
+ # For example, above this would be "119.2-dev"
91
+ RELEASE_NAME="bosh-release"
92
+ LATEST_DEV_RELEASE_NAME=$(tail -n 1 dev_releases/index.yml | awk '{print $2}')
93
+ LATEST_BOSH_RELEASE_PATH=$BOSH_RELEASE_DIR/dev_releases/$RELEASE_NAME-$LATEST_DEV_RELEASE_NAME.tgz
94
+ MICRO_BOSH_MANIFEST_PATH=$BOSH_RELEASE_DIR/micro/$PROVIDER.yml
95
+
96
+ BOSH_DIR=/var/vcap/store/repos/bosh
97
+ cd $(dirname $BOSH_DIR)
98
+ if [[ -d bosh ]]; then
99
+ echo "Updating bosh source for agent/stemcell scripts"
100
+ cd bosh
101
+ git pull origin master
102
+ else
103
+ echo "Cloning bosh source for agent/stemcell scripts"
104
+ git clone https://github.com/cloudfoundry/bosh.git
105
+ cd bosh
106
+ fi
107
+
108
+ cd $BOSH_DIR
109
+ echo "Creating custom stemcell..."
110
+ bundle install --without test development
111
+ bundle exec rake stemcell:micro[$PROVIDER,$MICRO_BOSH_MANIFEST_PATH,$LATEST_BOSH_RELEASE_PATH]
112
+
113
+ echo "Copying to stemcells folder..."
114
+ MICRO_BOSH_STEMCELL_PATH=$(ls -t /var/tmp/bosh/agent-*/work/work/*.tgz | sort | tail -n 1)
115
+ mv $MICRO_BOSH_STEMCELL_PATH /var/vcap/store/stemcells
116
+ MICRO_BOSH_STEMCELL_NAME=$(basename $MICRO_BOSH_STEMCELL_PATH)
117
+
118
+ echo "Cleaning up..."
119
+ rm $(dirname $LATEST_BOSH_RELEASE_PATH)/*.tgz
120
+
121
+ elif [[ -f /var/vcap/store/stemcells/$MICRO_BOSH_STEMCELL_NAME ]]; then
122
+ echo "Stemcell $(pwd)/$MICRO_BOSH_STEMCELL_NAME already exists."
123
+
124
+ else
125
+ cd /var/vcap/store/stemcells
126
+ echo "Downloading public stemcell $MICRO_BOSH_STEMCELL_NAME"
127
+ # set $COLUMNS manually else progressbar runs `tput cols`.to_i which causes grief
128
+ COLUMNS=80 bosh -n download public stemcell $MICRO_BOSH_STEMCELL_NAME
129
+ fi
130
+
131
+ # print name of stemcell created/downloaded to be stored back in settings
132
+ echo $MICRO_BOSH_STEMCELL_NAME