teleport 1.0.1 → 1.0.2

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.
data/README.md CHANGED
@@ -59,4 +59,4 @@ Teleport will ssh to the machine and set it up per your instructions.
59
59
 
60
60
  Full docs are in the wiki:
61
61
 
62
- https://github.com/rglabs/teleport/wiki
62
+ https://github.com/gurgeous/teleport/wiki
@@ -1,7 +1,7 @@
1
1
  module Teleport
2
2
  # This class parses Telfile, and includes DSL and the models.
3
3
  class Config
4
- RUBIES = ["1.9.2", "REE", "1.8.7"]
4
+ RUBIES = ["1.9.3", "1.9.2", "REE", "1.8.7"]
5
5
 
6
6
  attr_accessor :user, :ruby, :ssh_options, :roles, :servers, :apt, :packages, :callbacks, :dsl
7
7
 
@@ -17,6 +17,8 @@ module Teleport
17
17
 
18
18
  @user ||= Util.whoami
19
19
  @ruby ||= RUBIES.first
20
+
21
+ sanity_check_gemfiles
20
22
  end
21
23
 
22
24
  def role(n)
@@ -27,6 +29,17 @@ module Teleport
27
29
  @servers.find { |i| i.name == n.to_s }
28
30
  end
29
31
 
32
+ def sanity_check_gemfiles
33
+ files = ["files"] + @roles.map { |i| "files_#{i.name}" }
34
+ files.each do |i|
35
+ gemfile = "#{i}/Gemfile"
36
+ lock = "#{gemfile}.lock"
37
+ if File.exists?(gemfile) && !File.exists?(lock)
38
+ Util.fatal "Hm. I found #{gemfile}, but you forgot to create #{lock}."
39
+ end
40
+ end
41
+ end
42
+
30
43
  # The model for role in the Telfile.
31
44
  class Role
32
45
  attr_reader :name, :options, :packages
@@ -118,7 +131,7 @@ module Teleport
118
131
  @config.packages += list.flatten
119
132
  end
120
133
 
121
- %w(install user packages files).each do |op|
134
+ %w(install user packages gemfiles files).each do |op|
122
135
  %w(before after).each do |before_after|
123
136
  callback = "#{before_after}_#{op}".to_sym
124
137
  define_method(callback) do |&block|
@@ -15,5 +15,5 @@ module Constants
15
15
  PUBKEY = "id_teleport.pub"
16
16
 
17
17
  # Minimum version of rubygems to install.
18
- RUBYGEMS = "1.8.5"
18
+ RUBYGEMS = "1.8.10"
19
19
  end
@@ -138,6 +138,7 @@ module Teleport
138
138
  when /Ruby Enterprise Edition/ then ruby = "REE"
139
139
  when /1\.8\.7/ then ruby = "1.8.7"
140
140
  when /1\.9\.2/ then ruby = "1.9.2"
141
+ when /1\.9\.3/ then ruby = "1.9.3"
141
142
  end
142
143
  append "ruby #{ruby.inspect}" if ruby
143
144
  end
@@ -30,6 +30,9 @@ module Teleport
30
30
  _with_callback(:packages) do
31
31
  _packages
32
32
  end
33
+ _with_callback(:gemfiles) do
34
+ _gemfiles
35
+ end
33
36
  _with_callback(:files) do
34
37
  _files
35
38
  end
@@ -73,16 +76,6 @@ module Teleport
73
76
  run "gem update --system"
74
77
  end
75
78
 
76
- # uninstall all gems except for bundler
77
- gems = `gem list`.split("\n").map { |i| i.split.first }
78
- gems.delete("bundler")
79
- if !gems.empty?
80
- banner "Uninstalling #{gems.length} system gems..."
81
- gems.each do |i|
82
- run "gem uninstall -aIx #{i}"
83
- end
84
- end
85
-
86
79
  # install bundler
87
80
  gem_if_necessary("bundler")
88
81
  end
@@ -104,15 +97,21 @@ module Teleport
104
97
  end
105
98
  run "hostname -F /etc/hostname"
106
99
 
107
- puts "adding #{@host} to /etc/hosts ..."
100
+ # list of hostnames to add to /etc/hosts
101
+ hostnames = []
102
+ hostnames << @host
103
+ hostnames << @host.split(".").first if @host.index(".")
104
+ hostnames = hostnames.join(" ")
105
+
106
+ puts "adding #{hostnames} to /etc/hosts ..."
108
107
  _rewrite("/etc/hosts") do |fout|
109
108
  hosts = File.read("/etc/hosts")
110
109
 
111
110
  # old_hostname => @host
112
- hosts.gsub!(_etc_hosts_regex(old_hostname), "\\1#{@host}\\2")
111
+ hosts.gsub!(_etc_hosts_regex(old_hostname), "\\1#{hostnames}\\2")
113
112
  if hosts !~ _etc_hosts_regex(@host)
114
113
  # not found? append to localhost
115
- hosts.gsub!(_etc_hosts_regex("localhost"), "\\1localhost #{@host}\\2")
114
+ hosts.gsub!(_etc_hosts_regex("localhost"), "\\1localhost #{hostnames}\\2")
116
115
  if hosts !~ _etc_hosts_regex(@host)
117
116
  puts " Hm. I couldn't add it, unfortunately. You'll have to do it manually."
118
117
  end
@@ -190,6 +189,21 @@ EOF
190
189
  list.sort.each { |i| package_if_necessary(i) }
191
190
  end
192
191
 
192
+ def _gemfiles
193
+ files = ["files"]
194
+ files << "files_#{@role.name}" if @role
195
+ Dir.chdir(DATA) do
196
+ files.each do |i|
197
+ gemfile = "#{i}/Gemfile"
198
+ lock = "#{gemfile}.lock"
199
+ if File.exists?(gemfile)
200
+ banner "Gemfiles - #{gemfile}..."
201
+ run "bundle install --gemfile #{gemfile}"
202
+ end
203
+ end
204
+ end
205
+ end
206
+
193
207
  def _files
194
208
  banner "Files..."
195
209
  files = ["files"]
data/lib/teleport/main.rb CHANGED
@@ -27,13 +27,9 @@ module Teleport
27
27
  def cli(cmd)
28
28
  @options = { }
29
29
  @options[:cmd] = cmd
30
- @options[:file] = "Telfile"
31
30
 
32
31
  opt = OptionParser.new do |o|
33
32
  o.banner = "Usage: teleport <hostname>"
34
- o.on("-f", "--file FILE", "use this file instead of Telfile") do |f|
35
- @options[:file] = f
36
- end
37
33
  o.on("-i", "--infer", "infer a new Telfile from YOUR machine") do |f|
38
34
  @options[:cmd] = :infer
39
35
  end
@@ -63,10 +59,10 @@ module Teleport
63
59
 
64
60
  # Read Telfile
65
61
  def read_config
66
- if !File.exists?(@options[:file])
67
- fatal("Sadly, I can't find #{@options[:file]} here. Please create one.")
62
+ if !File.exists?("Telfile")
63
+ fatal("Sadly, I can't find Telfile here. Please create one.")
68
64
  end
69
- @config = Config.new(@options[:file])
65
+ @config = Config.new("Telfile")
70
66
  end
71
67
 
72
68
  # Assemble the the tgz before we teleport to the host
@@ -76,12 +72,12 @@ module Teleport
76
72
 
77
73
  # gem
78
74
  run("cp", ["-r", "#{File.dirname(__FILE__)}/../../lib", GEM])
79
- # Telfile, if necessary
80
- if @options[:file] != "Telfile"
81
- run("cp", [@options[:file], "Telfile"])
82
- end
83
75
  # data
84
- run("cp", ["-r", ".", DATA])
76
+ mkdir(DATA)
77
+ copy = []
78
+ copy << "Telfile"
79
+ copy += Dir["files*"]
80
+ copy.sort.each { |i| run("cp", ["-r", i, DATA]) }
85
81
  # config.sh
86
82
  File.open("#{DIR}/config", "w") do |f|
87
83
  f.puts("CONFIG_HOST='#{@options[:host]}'")
@@ -5,6 +5,15 @@ module Teleport
5
5
  module Mirror
6
6
  include Constants
7
7
 
8
+ # Don't install these files.
9
+ IGNORE = [
10
+ ".",
11
+ "..",
12
+ "Gemfile",
13
+ "Gemfile.lock",
14
+ /^.#/,
15
+ ]
16
+
8
17
  # Install file from the teleport data directory into the normal
9
18
  # filesystem. Path can use a few different formats:
10
19
  #
@@ -56,7 +65,7 @@ module Teleport
56
65
  mkdir_if_necessary(dst, user_for_file(dst)) if !dst.empty?
57
66
 
58
67
  files = Dir.new(path).to_a.sort
59
- files.delete_if { |i| i == "." || i == ".." || i =~ /^.#/ }
68
+ files.delete_if { |file| IGNORE.any? { |i| i === file } }
60
69
  files.each do |i|
61
70
  i = "#{path}/#{i}"
62
71
  if File.directory?(i)
data/lib/teleport/run.sh CHANGED
@@ -33,6 +33,7 @@ function install_ruby() {
33
33
  case $CONFIG_RUBY in
34
34
  1.8.7 ) install_ruby_187 ;;
35
35
  1.9.2 ) install_ruby_192 ;;
36
+ 1.9.3 ) install_ruby_193 ;;
36
37
  REE ) install_ruby_ree ;;
37
38
  * ) fatal "unknown ruby ($CONFIG_RUBY)" ;;
38
39
  esac
@@ -43,12 +44,12 @@ function install_ruby_187() {
43
44
 
44
45
  wget http://production.cf.rubygems.org/rubygems/rubygems-$CONFIG_RUBYGEMS.tgz
45
46
  tar xfpz rubygems-$CONFIG_RUBYGEMS.tgz
46
- (cd rubygems-$CONFIG_RUBYGEMS ; ruby setup.rb)
47
+ (cd rubygems-$CONFIG_RUBYGEMS ; sudo ruby setup.rb)
47
48
  ln -s /usr/bin/gem1.8 /usr/bin/gem
48
49
  }
49
50
 
50
51
  function install_ruby_192() {
51
- local patch=p180
52
+ local patch=p290
52
53
 
53
54
  # see http://threebrothers.org/brendan/blog/ruby-1-9-2-on-ubuntu-11-04/
54
55
  sudo apt-get install -y bison build-essential checkinstall libffi5 libssl-dev libyaml-dev zlib1g-dev
@@ -78,10 +79,44 @@ function install_ruby_192() {
78
79
  --slave /usr/local/bin/rdoc rdoc /usr/local/bin/rdoc1.9.2
79
80
  }
80
81
 
82
+ function install_ruby_193() {
83
+ local patch=p0
84
+
85
+ # see http://threebrothers.org/brendan/blog/ruby-1-9-2-on-ubuntu-11-04/
86
+ sudo apt-get install -y bison build-essential checkinstall libffi5 libssl-dev libyaml-dev zlib1g-dev
87
+
88
+ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-$patch.tar.gz
89
+ tar xvzf ruby-1.9.3-$patch.tar.gz
90
+
91
+ cd ruby-1.9.3-$patch
92
+ ./configure --prefix=/usr/local \
93
+ --program-suffix=1.9.3 \
94
+ --with-ruby-version=1.9.3 \
95
+ --disable-install-doc
96
+ make
97
+ sudo checkinstall -D -y \
98
+ --fstrans=no \
99
+ --nodoc \
100
+ --pkgname="ruby1.9.3" \
101
+ --pkgversion="1.9.3-$patch" \
102
+ --provides="ruby"
103
+ cd ..
104
+
105
+ sudo update-alternatives --install /usr/local/bin/ruby ruby /usr/local/bin/ruby1.9.3 500 \
106
+ --slave /usr/local/bin/ri ri /usr/local/bin/ri1.9.3 \
107
+ --slave /usr/local/bin/irb irb /usr/local/bin/irb1.9.3 \
108
+ --slave /usr/local/bin/gem gem /usr/local/bin/gem1.9.3 \
109
+ --slave /usr/local/bin/erb erb /usr/local/bin/erb1.9.3 \
110
+ --slave /usr/local/bin/rdoc rdoc /usr/local/bin/rdoc1.9.3
111
+ }
112
+
81
113
  function install_ruby_ree() {
82
114
  local ree="ruby-enterprise_1.8.7-2011.03_${ARCH}_ubuntu10.04.deb"
83
115
  wget http://rubyenterpriseedition.googlecode.com/files/$ree
84
116
  sudo dpkg -i $ree
117
+
118
+ # remove all gems
119
+ gem list | cut -d" " -f1 | xargs sudo gem uninstall
85
120
  }
86
121
 
87
122
 
data/lib/teleport/util.rb CHANGED
@@ -89,6 +89,11 @@ module Teleport
89
89
  run("#{command} > /dev/null 2> /dev/null")
90
90
  end
91
91
 
92
+ # Run one or several commands, separate by newlines.
93
+ def shell(commands)
94
+ commands.split("\n").each { |i| run(i) }
95
+ end
96
+
92
97
  # Run a command, return true if it succeeds.
93
98
  def succeeds?(command)
94
99
  system("#{command} > /dev/null 2> /dev/null")
@@ -1,4 +1,4 @@
1
1
  module Teleport
2
2
  # Gem version
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
  describe "a new ec2 instance" do
5
5
  ec2
6
6
 
7
+ # Telfile
7
8
  telfile do
8
9
  <<EOF
9
10
  user "gub"
@@ -18,6 +19,17 @@ before_install do
18
19
  puts "BEFORE_INSTALL"
19
20
  end
20
21
 
22
+ after_files do
23
+ puts "AFTER_FILES"
24
+ puts "test.txt"
25
+ p File.read("/test.txt")
26
+ end
27
+
28
+ after_gemfiles do
29
+ puts "AFTER_GEMFILES"
30
+ Util.run "gem list"
31
+ end
32
+
21
33
  after_install do
22
34
  puts "AFTER_INSTALL"
23
35
  run "touch /tmp/gub.txt"
@@ -25,6 +37,10 @@ end
25
37
  EOF
26
38
  end
27
39
 
40
+ # Roles. This is clunky, unfortunately.
41
+ role(nil, "test.txt.erb" => "<%= 1+2 %>", "Gemfile" => "source 'http://rubygems.org'\ngem 'trollop'", "Gemfile.lock" => "GEM\n remote: http://rubygems.org/\n specs:\n trollop (1.16.2)\n\nPLATFORMS\n ruby\n\nDEPENDENCIES\n trollop")
42
+ role("master", "Gemfile" => "source 'http://rubygems.org'\ngem 'awesome_print'", "Gemfile.lock" => "GEM\n remote: http://rubygems.org/\n specs:\n awesome_print (0.4.0)\n\nPLATFORMS\n ruby\n\nDEPENDENCIES\n awesome_print")
43
+
28
44
  it "installs properly" do
29
45
  ARGV.clear
30
46
  ARGV << $ec2_ip_address
data/spec/support/ec2.rb CHANGED
@@ -3,9 +3,10 @@ require "AWS"
3
3
  # spin up a fresh ec2 instance
4
4
  module Support
5
5
  module Ec2
6
- AMI_10_04 = "fbbf7892"
7
- AMI_10_10 = "08f40561"
8
- AMI_11_04 = "68ad5201"
6
+ AMI_10_04 = "1136fb78"
7
+ AMI_10_10 = "1933fe70"
8
+ AMI_11_04 = "71589518"
9
+ AMI_11_10 = "4b772b0e"
9
10
  KEYPAIR = "teleport"
10
11
  GROUP = "teleport"
11
12
 
@@ -76,10 +77,11 @@ EOF
76
77
  puts "Waiting for ec2 instance to start..."
77
78
  while true
78
79
  sleep 3
79
- instance = describe_instances.first
80
- status = instance["instanceState"]["name"]
81
- puts " #{instance["instanceId"]}: #{status}"
82
- break if status == "running"
80
+ if instance = describe_instances.first
81
+ status = instance["instanceState"]["name"]
82
+ puts " #{instance["instanceId"]}: #{status}"
83
+ break if status == "running"
84
+ end
83
85
  end
84
86
 
85
87
  # return the ip address
@@ -21,5 +21,17 @@ module Support
21
21
  Dir.chdir(pwd)
22
22
  end
23
23
  end
24
+
25
+ def role(role, files)
26
+ before(:all) do
27
+ path = (role == nil) ? "files" : "files_#{role}"
28
+ `mkdir -p #{path}`
29
+ Dir.chdir(path) do
30
+ files.each_pair do |key, value|
31
+ File.open(key, "w") { |f| f.write(value) }
32
+ end
33
+ end
34
+ end
35
+ end
24
36
  end
25
37
  end
data/teleport.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Adam Doppelt"]
10
10
  s.email = ["amd@gurge.com"]
11
- s.homepage = "http://github.com/rglabs/teleport"
11
+ s.homepage = "http://github.com/gurgeous/teleport"
12
12
  s.summary = "Teleport - opinionated Ubuntu server setup with Ruby."
13
13
  s.description = "Easy Ubuntu server setup via teleportation."
14
14
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teleport
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Doppelt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-10 00:00:00 -07:00
18
+ date: 2011-11-02 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -30,8 +30,8 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  version: "0"
33
- requirement: *id001
34
33
  prerelease: false
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: awesome_print
37
37
  type: :development
@@ -44,8 +44,8 @@ dependencies:
44
44
  segments:
45
45
  - 0
46
46
  version: "0"
47
- requirement: *id002
48
47
  prerelease: false
48
+ requirement: *id002
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
51
  type: :development
@@ -58,8 +58,8 @@ dependencies:
58
58
  segments:
59
59
  - 0
60
60
  version: "0"
61
- requirement: *id003
62
61
  prerelease: false
62
+ requirement: *id003
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: rdoc
65
65
  type: :development
@@ -73,8 +73,8 @@ dependencies:
73
73
  - 3
74
74
  - 9
75
75
  version: "3.9"
76
- requirement: *id004
77
76
  prerelease: false
77
+ requirement: *id004
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rspec
80
80
  type: :development
@@ -88,8 +88,8 @@ dependencies:
88
88
  - 2
89
89
  - 6
90
90
  version: "2.6"
91
- requirement: *id005
92
91
  prerelease: false
92
+ requirement: *id005
93
93
  description: Easy Ubuntu server setup via teleportation.
94
94
  email:
95
95
  - amd@gurge.com
@@ -124,7 +124,7 @@ files:
124
124
  - spec/unit/teleport/config_spec.rb
125
125
  - teleport.gemspec
126
126
  has_rdoc: true
127
- homepage: http://github.com/rglabs/teleport
127
+ homepage: http://github.com/gurgeous/teleport
128
128
  licenses: []
129
129
 
130
130
  post_install_message: