bosh-bootstrap 0.6.0 → 0.7.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.
@@ -7,6 +7,26 @@ module Bosh; module Bootstrap; module Helpers; end; end; end
7
7
  #
8
8
  # Assumes +settings+ contains the settings
9
9
  module Bosh::Bootstrap::Helpers::SettingsSetter
10
+
11
+ # Let's you navigate to a nested setting, do something with it,
12
+ # and then saves any changes to settings.
13
+ # Usage:
14
+ # with_setting "inception" { |s| s["host"] = "1.2.3.4" }
15
+ # with_setting "a.b.c" { |s| s["value"] = "1.2.3.4" }
16
+ def with_setting(nested_key, &block)
17
+ target_settings_field = settings
18
+ settings_key_portions = nested_key.split(".")
19
+ parent_key_portions, final_key = settings_key_portions[0..-2], settings_key_portions[-1]
20
+ parent_key_portions.each do |key_portion|
21
+ target_settings_field[key_portion] ||= {}
22
+ target_settings_field = target_settings_field[key_portion]
23
+ end
24
+
25
+ target_settings_field[final_key] ||= {}
26
+ yield target_settings_field[final_key]
27
+ save_settings!
28
+ end
29
+
10
30
  def setting(nested_key, value)
11
31
  target_settings_field = settings
12
32
  settings_key_portions = nested_key.split(".")
@@ -17,4 +37,5 @@ module Bosh::Bootstrap::Helpers::SettingsSetter
17
37
  end
18
38
  target_settings_field[final_key] = value
19
39
  end
40
+
20
41
  end
@@ -20,17 +20,56 @@ cd /var/vcap/store/microboshes/deployments/
20
20
  bosh -n micro deployment $BOSH_NAME
21
21
 
22
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)
23
+ MICRO_BOSH_STEMCELL_PATH=$(ls -t /var/tmp/bosh/bosh_agent-*/work/work/*.tgz | sort | tail -n 1)
24
24
  echo "Custom stemcell path $MICRO_BOSH_STEMCELL_PATH"
25
25
  else
26
26
  echo "Downloaded stemcell path $MICRO_BOSH_STEMCELL_PATH"
27
27
  fi
28
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
29
+ if [[ -f bosh-deployments.yml ]]; then
30
+ deployment=$(cat bosh-deployments.yml | yaml get instances -j | jazor "find {|inst| inst['name'] == '$BOSH_NAME' }")
32
31
  else
32
+ deployment=""
33
+ fi
34
+
35
+ # if $BOSH_NAME has never been deployed before, then $deployment will be empty
36
+ # if $BOSH_NAME was previously deployed but deleted then $deployment will look like:
37
+ # {
38
+ # "id": 1,
39
+ # "name": "microbosh-aws-us-east-1",
40
+ # "uuid": "bm-096bc437-b531-4260-a57f-8ea54db2f8d2",
41
+ # "stemcell_cid": null,
42
+ # "stemcell_name": null,
43
+ # "vm_cid": null,
44
+ # "disk_cid": null
45
+ # }
46
+ # if $BOSH_NAME has been deployed but it failed mid-way, then some of the _cid fields above will be set.
47
+
48
+ echo ""
49
+ echo ""
50
+
51
+ if [[ "${deployment}X" == "X" ]]; then
33
52
  echo "Performing initial deploy of micro BOSH $BOSH_NAME"
34
- bosh -n micro deploy $MICRO_BOSH_STEMCELL_PATH
53
+ bosh -n --color micro deploy $MICRO_BOSH_STEMCELL_PATH
35
54
  touch $BOSH_NAME/new_bosh_deployed # to communicate with setup_bosh_user script
55
+ else
56
+ # determine if re-deploy, update, or delete&deploy
57
+
58
+ stemcell_cid=$(echo $deployment | jazor stemcell_cid)
59
+ vm_cid=$(echo $deployment | jazor vm_id)
60
+ disk_cid=$(echo $deployment | jazor disk_cid)
61
+
62
+ if [[ $stemcell_cid == "" && $vm_cid == "" && $disk_cid == "" ]]; then
63
+ echo "Deployment was deleted; deploying micro BOSH $BOSH_NAME again"
64
+ bosh -n --color micro deploy $MICRO_BOSH_STEMCELL_PATH
65
+ touch $BOSH_NAME/new_bosh_deployed # to communicate with setup_bosh_user script
66
+ elif [[ $stemcell_cid == "" || $vm_cid == "" || $disk_cid == "" ]]; then
67
+ echo "Deployment previously failed to complete. Deleting and deploying micro BOSH $BOSH_NAME again."
68
+ bosh -n --color micro delete
69
+ bosh -n --color micro deploy $MICRO_BOSH_STEMCELL_PATH
70
+ touch $BOSH_NAME/new_bosh_deployed # to communicate with setup_bosh_user script
71
+ else
72
+ echo "Performing update deploy to micro BOSH $BOSH_NAME"
73
+ bosh -n --color micro deploy $MICRO_BOSH_STEMCELL_PATH --update
74
+ fi
36
75
  fi
@@ -8,7 +8,7 @@
8
8
  #
9
9
  # Optional:
10
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
11
+ # * $ISO_NAME - defaults to ubuntu-10.04.4-server-amd64.iso for creating stemcell
12
12
 
13
13
  set -e # exit immediately if a simple command exits with a non-zero status
14
14
  set -u # report the usage of uninitialized variables
@@ -23,76 +23,26 @@ if [[ "${MICRO_BOSH_STEMCELL_NAME}X" == "X" ]]; then
23
23
  exit 1
24
24
  fi
25
25
 
26
+ STEMCELLS_DIR=/var/vcap/store/stemcells
27
+
26
28
  if [[ "${MICRO_BOSH_STEMCELL_NAME}" == "custom" ]]; then
27
29
 
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
30
+ ISO_NAME=${ISO_NAME:-ubuntu-10.04.4-server-amd64.iso}
31
31
 
32
32
  echo "Creating custom stemcell..."
33
33
 
34
+ cd ${STEMCELLS_DIR}
35
+ if [[ ! -f ${ISO_NAME} ]]; then
36
+ echo "Fetching base stemcell ISO to speed up stemcell creation..."
37
+ wget http://releases.ubuntu.com/lucid/${ISO_NAME}
38
+ fi
39
+ export UBUNTU_ISO=${STEMCELLS_DIR}/${ISO_NAME}
40
+
34
41
  if [[ -d /var/tmp/bosh/ ]]; then
35
42
  echo "But first, cleaning out previous stemcell temporary files..."
36
43
  rm -rf /var/tmp/bosh
37
44
  fi
38
45
 
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
46
  BOSH_DIR=/var/vcap/store/repos/bosh
97
47
  cd $(dirname $BOSH_DIR)
98
48
  if [[ -d bosh ]]; then
@@ -107,22 +57,20 @@ if [[ "${MICRO_BOSH_STEMCELL_NAME}" == "custom" ]]; then
107
57
 
108
58
  cd $BOSH_DIR
109
59
  echo "Creating custom stemcell..."
110
- bundle install
111
- bundle exec rake stemcell:micro[$PROVIDER,$MICRO_BOSH_MANIFEST_PATH,$LATEST_BOSH_RELEASE_PATH]
60
+ rm -rf .bundle
61
+ bundle install --deployment
62
+ bundle exec rake stemcell:micro[$PROVIDER]
112
63
 
113
64
  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
65
+ MICRO_BOSH_STEMCELL_PATH=$(ls -t /var/tmp/bosh/bosh_agent-*/work/work/*.tgz | sort | tail -n 1)
66
+ mv $MICRO_BOSH_STEMCELL_PATH $STEMCELLS_DIR
116
67
  MICRO_BOSH_STEMCELL_NAME=$(basename $MICRO_BOSH_STEMCELL_PATH)
117
68
 
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
69
+ elif [[ -f $STEMCELLS_DIR/$MICRO_BOSH_STEMCELL_NAME ]]; then
122
70
  echo "Stemcell $(pwd)/$MICRO_BOSH_STEMCELL_NAME already exists."
123
71
 
124
72
  else
125
- cd /var/vcap/store/stemcells
73
+ cd $STEMCELLS_DIR
126
74
  echo "Downloading public stemcell $MICRO_BOSH_STEMCELL_NAME"
127
75
  # set $COLUMNS manually else progressbar runs `tput cols`.to_i which causes grief
128
76
  COLUMNS=80 bosh -n download public stemcell $MICRO_BOSH_STEMCELL_NAME
@@ -15,8 +15,8 @@ module Bosh::Bootstrap::Stages
15
15
  @commands ||= Bosh::Bootstrap::Commander::Commands.new do |server|
16
16
  server.download "micro-bosh stemcell", script("download_micro_bosh_stemcell",
17
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")
18
+ "PROVIDER" => settings.bosh_provider),
19
+ :settings => settings, :save_output_to_settings_key => "micro_bosh_stemcell_name"
20
20
  server.upload_file \
21
21
  "/var/vcap/store/microboshes/deployments/#{settings.bosh_name}/micro_bosh.yml",
22
22
  micro_bosh_manifest
@@ -32,7 +32,6 @@ module Bosh::Bootstrap::Stages
32
32
  end
33
33
  end
34
34
 
35
- private
36
35
  def stage_name
37
36
  "stage_micro_bosh_deploy"
38
37
  end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Setup git configuration for the user
4
+ #
5
+ # Run as the user to configure
6
+ #
7
+ # Requires:
8
+ # * $GIT_USER_NAME
9
+ # * $GIT_USER_EMAIL
10
+
11
+ if [[ $EUID -ne 0 ]]; then
12
+ echo "ERROR: This script must be run as root" 1>&2
13
+ exit 1
14
+ fi
15
+
16
+ if [[ "${GIT_USER_NAME}X" == "X" ]]; then
17
+ echo 'ERROR please provide $GIT_USER_NAME'
18
+ exit 1
19
+ fi
20
+ if [[ "${GIT_USER_EMAIL}X" == "X" ]]; then
21
+ echo 'ERROR please provide $GIT_USER_EMAIL'
22
+ exit 1
23
+ fi
24
+
25
+ cd ~vcap
26
+ chpst -u vcap:vcap git config -f ~vcap/.gitconfig user.name "${GIT_USER_NAME}"
27
+ chpst -u vcap:vcap git config -f ~vcap/.gitconfig user.email "${GIT_USER_EMAIL}"
28
+ chpst -u vcap:vcap git config -f ~vcap/.gitconfig color.ui true
@@ -5,9 +5,14 @@ if [[ $EUID -ne 0 ]]; then
5
5
  exit 1
6
6
  fi
7
7
 
8
+ apt-get install python-software-properties
9
+ add-apt-repository ppa:keithw/mosh
10
+
8
11
  apt-get update
9
- apt-get install build-essential libsqlite3-dev curl rsync git-core tmux \
12
+ apt-get install build-essential libsqlite3-dev curl rsync git-core \
13
+ tmux mosh \
10
14
  libmysqlclient-dev libxml2-dev libxslt-dev libpq-dev libsqlite3-dev \
15
+ runit \
11
16
  genisoimage mkpasswd \
12
17
  debootstrap kpartx qemu-kvm \
13
18
  vim -y
@@ -31,37 +31,11 @@ if [[ "${INSTALL_BOSH_FROM_SOURCE}X" != "X" ]]; then
31
31
  git clone https://github.com/cloudfoundry/bosh.git
32
32
  fi
33
33
 
34
- bosh_dir=/var/vcap/store/repos/bosh
35
- projects=(
36
- bosh_common
37
- blobstore_client
38
- bosh_cpi
39
- ruby_vcloud_sdk
40
- bosh_vcloud_cpi
41
- ruby_vim_sdk
42
- bosh_vsphere_cpi
43
- bosh_aws_cpi
44
- agent_client
45
- bosh_cli
46
- bosh_aws_registry
47
- bosh_openstack_registry
48
- bosh_deployer
49
- )
50
- for project in "${projects[@]}"; do
51
- cd $bosh_dir/$project/
52
- rm -rf pkg
53
- bundle install --without=development test
54
- gem build *.gemspec
55
- mkdir -p pkg
56
- mv *.gem pkg/
57
- gem install pkg/*.gem --no-ri --no-rdoc
58
- done
34
+ cd /var/vcap/store/repos/bosh
35
+ bundle --deployment
36
+ bundle exec rake all:install
59
37
 
60
38
  else
61
- install_gem bosh_cli
62
- # TODO remove this when bosh_deployer starts installing aws-sdk 1.8.1.1 or higher
63
- install_gem httparty
64
- # end TODO
65
39
  install_gem bosh_deployer
66
40
  fi
67
41
 
@@ -13,8 +13,9 @@ fi
13
13
  # Install a gem if $UPGRADE exists or if gem not already installed
14
14
  function install_gem() {
15
15
  gem_name=$1
16
+ options=$2
16
17
  if [[ ("${UPGRADE}X" != "X") || "$(gem list $gem_name | grep $gem_name)X" == "X" ]]; then
17
- gem install $gem_name --no-ri --no-rdoc
18
+ gem install $gem_name $options --no-ri --no-rdoc
18
19
  else
19
20
  echo gem $gem_name already installed
20
21
  fi
@@ -22,3 +23,5 @@ function install_gem() {
22
23
 
23
24
  install_gem bundler
24
25
  install_gem rake
26
+ install_gem jazor
27
+ install_gem yaml_command
@@ -9,19 +9,27 @@ module Bosh::Bootstrap::Stages
9
9
  def commands
10
10
  @commands ||= Bosh::Bootstrap::Commander::Commands.new do |server|
11
11
  # using inception VM username login, create a vcap user with same authorizations
12
- server.create "vcap user", script("create_vcap_user", "ORIGUSER" => settings.inception.username),
12
+ server.create "vcap user", script("create_vcap_user",
13
+ "ORIGUSER" => settings.inception.username),
13
14
  :user => settings.inception.username
14
15
  # install base Ubuntu packages used for bosh micro deployer
15
16
  server.install "base packages", script("install_base_packages")
17
+ server.configure "git", script("configure_git",
18
+ "GIT_USER_NAME" => settings["git"]["name"],
19
+ "GIT_USER_EMAIL" => settings["git"]["email"])
16
20
  server.install "ruby 1.9.3", script("install_ruby", "UPGRADE" => settings[:upgrade_deps])
17
21
  server.install "useful ruby gems", script("install_useful_gems", "UPGRADE" => settings[:upgrade_deps])
18
22
  server.install "bosh", script("install_bosh",
19
23
  "UPGRADE" => settings[:upgrade_deps],
20
24
  "INSTALL_BOSH_FROM_SOURCE" => settings["bosh_git_source"] || "")
21
25
  server.install "bosh plugins", script("install_bosh_plugins", "UPGRADE" => settings[:upgrade_deps])
26
+
22
27
  # use inception VM to generate a salted password (local machine may not have mkpasswd)
23
- server.capture_value "salted password", script("convert_salted_password", "PASSWORD" => settings.bosh.password),
24
- :settings => settings, :save_output_to_settings_key => "bosh.salted_password"
28
+ unless settings["bosh"]["salted_password"]
29
+ server.capture_value "salted password", script("convert_salted_password", "PASSWORD" => settings.bosh.password),
30
+ :settings => settings, :save_output_to_settings_key => "bosh.salted_password"
31
+ end
32
+
25
33
  server.validate "bosh deployer", script("validate_bosh_deployer")
26
34
  end
27
35
  end
@@ -41,7 +49,7 @@ module Bosh::Bootstrap::Stages
41
49
  if variables.keys.size > 0
42
50
  inline_variables = "#!/usr/bin/env bash\n\n"
43
51
  env_variables = variables.reject { |var| var.is_a?(Symbol) }
44
- env_variables.each { |name, value| inline_variables << "#{name}=#{value}\n" }
52
+ env_variables.each { |name, value| inline_variables << "#{name}='#{value}'\n" }
45
53
  script.gsub!("#!/usr/bin/env bash", inline_variables)
46
54
  end
47
55
  script
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Bootstrap
3
- VERSION = "0.6.0"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
@@ -1,3 +1,7 @@
1
+ # Requires Ruby language 1.9 and MRI or Rubinius
2
+ require "redcard"
3
+ RedCard.verify :mri, :ruby, :rubinius, "1.9"
4
+
1
5
  module Bosh
2
6
  module Bootstrap
3
7
  end
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: test-bosh
3
+ env:
4
+ bosh:
5
+ password: pepper
6
+ logging:
7
+ level: DEBUG
8
+ network:
9
+ type: dynamic
10
+ vip: $MICROBOSH_IP$
11
+ resources:
12
+ persistent_disk: 16384
13
+ cloud_properties:
14
+ instance_type: m1.medium
15
+ cloud:
16
+ plugin: aws
17
+ properties:
18
+ aws:
19
+ access_key_id: YYY
20
+ secret_access_key: XXX
21
+ region: us-west-2
22
+ ec2_endpoint: ec2.us-west-2.amazonaws.com
23
+ default_security_groups:
24
+ - test-bosh
25
+ default_key_name: test-bosh
26
+ ec2_private_key: /home/vcap/.ssh/test-bosh.pem
27
+ apply_spec:
28
+ agent:
29
+ blobstore:
30
+ address: $MICROBOSH_IP$
31
+ nats:
32
+ address: $MICROBOSH_IP$
33
+ properties:
34
+ aws_registry:
35
+ address: $MICROBOSH_IP$
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: test-bosh
3
+ env:
4
+ bosh:
5
+ password: pepper
6
+ logging:
7
+ level: DEBUG
8
+ network:
9
+ type: dynamic
10
+ vip: $MICROBOSH_IP$
11
+ cloud_properties:
12
+ subnet: $SUBNET_ID$
13
+ resources:
14
+ persistent_disk: 16384
15
+ cloud_properties:
16
+ instance_type: m1.medium
17
+ cloud:
18
+ plugin: aws
19
+ properties:
20
+ aws:
21
+ access_key_id: YYY
22
+ secret_access_key: XXX
23
+ region: us-west-2
24
+ ec2_endpoint: ec2.us-west-2.amazonaws.com
25
+ default_security_groups:
26
+ - test-bosh
27
+ default_key_name: test-bosh
28
+ ec2_private_key: /home/vcap/.ssh/test-bosh.pem
29
+ apply_spec:
30
+ agent:
31
+ blobstore:
32
+ address: $MICROBOSH_IP$
33
+ nats:
34
+ address: $MICROBOSH_IP$
35
+ properties:
36
+ aws_registry:
37
+ address: $MICROBOSH_IP$