intercity 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9e4cb14857b488f4fa9b273892debcc5fd189c7
4
- data.tar.gz: 732ddd745efc949198da1663c003e6ae081950ec
3
+ metadata.gz: d35afb301302349a658481ccc4791431ff3d042d
4
+ data.tar.gz: 1c7e5d7ab4cfbfb85a5b5ead6cb581a865958741
5
5
  SHA512:
6
- metadata.gz: 8883ba153a41414ff4617a16184f23a0c80fceafbd35889c828ebb3a3ef0107f6438979e85e3b67521ec5ece5542f8752e48c39c4eff85f9401664341d5428bf
7
- data.tar.gz: 48610b447767312fade43c6e5723e0f7f17507af06f3716561e23c8edf0dd1ffd6b300b873d75e5a21a1dc42aab91c48ea4fa7c0e49c1cec7f62dabf20660653
6
+ metadata.gz: f93310bb6008f3edc8a27d4fe760c2d6480f120200c884cc7e5c6170f21e5ac8f88808303d46ca920b27c59137caa029341b68d361f65cd044f5d3985585cd30
7
+ data.tar.gz: 6a605b5a6dbe905730024a76221ee9c3218e2b17d446a0016cbbf1c130b6cb9118b5d1e5a253b6196a25e27e0c0c5594b19242932c6f68d461d03af3a63e5860
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -13,23 +13,40 @@ $ gem install intercity
13
13
  Usage
14
14
  -----
15
15
 
16
- Install a clean Ubuntu server and add MySQL:
16
+ Get a clean Ubuntu 14.04 LTS server and initialize it:
17
17
 
18
18
  ```
19
19
  $ intercity server install IPADDRESS
20
- $ intercity mysql install --server=IPADDRESS
21
20
  ```
22
21
 
23
- Then create an application on your server:
22
+ Then install a database server. You can choose PostgreSQL or MySQL:
24
23
 
25
24
  ```
26
- $ intercity application create intercity --server=IPADDRESS --domain-name=myapp.com
25
+ $ intercity postgresql install
26
+ ```
27
+
28
+ or
29
+
30
+ ```
31
+ $ intercity mysql install
32
+ ```
33
+
34
+ Now, create an application on your server:
35
+
36
+ ```
37
+ $ intercity application create myapp
38
+ ```
39
+
40
+ Upload your SSH key to the server so you can deploy the app with Capistrano:
41
+
42
+ ```
43
+ $ intercity sshkey add
27
44
  ```
28
45
 
29
46
  You can edit environment variables for your app like this:
30
47
 
31
48
  ```
32
- $ intercity application edit intercity --server=IPADDRESS # Edit ENV vars
49
+ $ intercity application edit intercity
33
50
  ```
34
51
 
35
52
  Finally, set up Capistrano in your app and deploy with:
@@ -43,13 +60,36 @@ All commands
43
60
  ------------
44
61
 
45
62
  ```
46
- $ intercity server install IPADDRESS
63
+ # Initialize a server:
64
+ $ intercity server install HOST/IP
65
+
66
+ # List all your servers:
67
+ $ intercity server list
68
+
69
+ # Switch the active server:
70
+ $ intercity switch HOST/IP
71
+
72
+ # Install PostgreSQL:
73
+ $ intercity postgresql install
74
+
75
+ # Install MySQL:
76
+ $ intercity mysql install
77
+
78
+ # List your MySQL databases:
79
+ $ intercity mysql list
80
+
81
+ # Add your SSH key for deployment:
82
+ $ intercity sshkey add
83
+
84
+ # Create an application on your server:
85
+ $ intercity application create APPNAME
86
+
87
+ # Update an application setting, for example the domain names:
88
+ $ intercity application update APPNAME --domain-name=mysite.com
47
89
 
48
- $ intercity mysql list --server=IPADDRESS
49
- $ intercity mysql install --server=IPADDRESS
90
+ # Edit environment variables for an application:
91
+ $ intercity application edit APPNAME
50
92
 
51
- $ intercity application add APPNAME --server=IPADDRESS --domain-name=myapp.com
52
- $ intercity application update APPNAME --server=IPADDRESS --domain-name=myapp.com
53
- $ intercity application edit APPNAME --server=IPADDRESS # For editing the ENV vars
54
- $ intercity application list --server=IPADDRESS
93
+ # List all the applications on the server:
94
+ $ intercity application list
55
95
  ```
data/intercity.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'intercity'
3
- s.version = '0.1.3'
4
- s.date = '2015-01-24'
3
+ s.version = '0.1.4'
4
+ s.date = '2015-03-15'
5
5
  s.summary = 'Command-line interface for hosting Rails apps on your server.'
6
6
  s.authors = ['Michiel Sikkes']
7
7
  s.email = 'michiel.sikkes@gmail.com'
@@ -10,11 +10,11 @@ module IntercityCLI
10
10
 
11
11
  desc "list", "Lists all the application deployments on the server"
12
12
  option :user, default: "root"
13
- option :server, type: :string, required: true
13
+ option :server, type: :string
14
14
  def list()
15
15
  configuration = IntercityCLI::Configuration.new()
16
16
 
17
- server = options[:server]
17
+ server = options[:server] || configuration.active_server!
18
18
  user = options[:user]
19
19
  on server do |host|
20
20
  host.user = user
@@ -26,12 +26,11 @@ module IntercityCLI
26
26
 
27
27
  desc "edit APPLICATION", "Edit ENV variables for application"
28
28
  option :user, default: "root"
29
- option :server, type: :string, required: true
29
+ option :server, type: :string
30
30
  def edit(application)
31
- address = options[:server]
32
-
33
31
  configuration = IntercityCLI::Configuration.new()
34
- node_file = File.join(configuration.config_directory, "#{address}.json")
32
+ address = options[:server] || configuration.active_server!
33
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
35
34
 
36
35
  user = options[:user]
37
36
 
@@ -82,7 +81,7 @@ module IntercityCLI
82
81
 
83
82
  upload! node_file , "/root/server_config.json"
84
83
 
85
- execute 'chef-client -z -j ~/server_config.json -o "recipe[rails::env_vars]"'
84
+ execute 'chef-solo -c solo.rb -j ~/server_config.json -o "recipe[rails::env_vars]"'
86
85
  end
87
86
  end
88
87
  else
@@ -92,20 +91,21 @@ module IntercityCLI
92
91
 
93
92
  desc "add APPLICATION", "Adds an application to a server"
94
93
  option :user, default: "root"
95
- option :server, type: :string, required: true
96
- option :domain_name, type: :string, required: true
94
+ option :server, type: :string
95
+ option :domain_name, type: :string
97
96
  option :rails_environment, type: :string, default: "production"
98
- option :database_adapter, type: :string, default: "mysql2"
97
+ option :database_adapter, type: :string, default: "postgresql"
99
98
  option :database_name, type: :string, default: SecureRandom.hex(6)
100
99
  option :database_user, type: :string, default: SecureRandom.hex(6)
101
100
  option :database_password, type: :string, default: SecureRandom.hex()
102
- option :database_host, type: :string, default: "127.0.0.1"
101
+ option :database_host, type: :string, default: "localhost"
103
102
  option :ruby_version, type: :string, default: "2.1.3"
104
103
  def add(application)
105
- address = options[:server]
106
-
107
104
  configuration = IntercityCLI::Configuration.new()
108
- node_file = File.join(configuration.config_directory, "#{address}.json")
105
+
106
+ address = options[:server] || configuration.active_server!
107
+
108
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
109
109
 
110
110
  if File.exists?(node_file)
111
111
  raw_json = File.read(node_file)
@@ -114,13 +114,16 @@ module IntercityCLI
114
114
  raise "No configuration file for this server yet! Please create one by running:\n\n$ intercity server install <ip address>\n\n"
115
115
  end
116
116
 
117
+ json["nginx"] ||= {}
118
+ json["nginx"]["package_name"] = "nginx-extras"
119
+
117
120
  json["active_applications"] ||= {}
118
121
 
119
122
  json["active_applications"][application] ||= {}
120
123
 
121
124
  json["active_applications"][application].merge!(
122
125
  {
123
- "domain_names" => [options[:domain_name]],
126
+ "domain_names" => [options[:domain_name] || address],
124
127
  "rails_env" => options[:rails_environment],
125
128
  "database_info" => {
126
129
  "adapter" => options[:database_adapter],
@@ -129,7 +132,8 @@ module IntercityCLI
129
132
  "password" => options[:database_password],
130
133
  "database" => options[:database_name]
131
134
  },
132
- "ruby_version" => options[:ruby_version]
135
+ "ruby_version" => options[:ruby_version],
136
+ "packages" => ["nodejs", "imagemagick"]
133
137
  }
134
138
  )
135
139
 
@@ -145,7 +149,7 @@ module IntercityCLI
145
149
 
146
150
  upload! node_file, "/root/server_config.json"
147
151
 
148
- execute 'chef-client -z -j ~/server_config.json -o "recipe[rails::passenger],recipe[rails::databases]"'
152
+ execute 'chef-solo -c solo.rb -j ~/server_config.json -o "recipe[apt],recipe[rails::passenger],recipe[rails::databases]"'
149
153
  end
150
154
  end
151
155
  end
@@ -10,10 +10,10 @@ module IntercityCLI
10
10
  option :user, default: "root"
11
11
  option :server, type: :string, required: true
12
12
  def list
13
- address = options[:server]
14
-
15
13
  configuration = IntercityCLI::Configuration.new()
16
- node_file = File.join(configuration.config_directory, "#{address}.json")
14
+ address = options[:server] || configuration.active_server!
15
+
16
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
17
17
 
18
18
  raw_json = File.read(node_file)
19
19
  json = JSON.parse(raw_json)
@@ -45,9 +45,12 @@ module IntercityCLI
45
45
  desc "install IPADDRESS", "Installs MySQL at IPADDRESS"
46
46
  option :user, default: "root"
47
47
  option :root_password, default: SecureRandom.hex(), type: :string
48
- def install(address)
48
+ option :server, required: true, type: :string
49
+ def install
49
50
  configuration = IntercityCLI::Configuration.new()
50
- node_file = File.join(configuration.config_directory, "#{address}.json")
51
+ address = options[:server] || configuration.active_server!
52
+
53
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
51
54
 
52
55
  if File.exists?(node_file)
53
56
  raw_json = File.read(node_file)
@@ -70,7 +73,7 @@ module IntercityCLI
70
73
 
71
74
  upload! node_file, "/root/server_config.json"
72
75
 
73
- execute 'chef-client -z -j ~/server_config.json -o recipe[mysql::server]'
76
+ execute 'chef-solo -c solo.rb -j ~/server_config.json -o recipe[mysql::server]'
74
77
  end
75
78
  end
76
79
  end
@@ -0,0 +1,45 @@
1
+ require "thor"
2
+ require "json"
3
+ require "sshkit"
4
+
5
+ module IntercityCLI
6
+ class PostgreSQL < Thor
7
+ require "sshkit/dsl"
8
+
9
+ desc "install IPADDRESS", "Installs MySQL at IPADDRESS"
10
+ option :user, default: "root"
11
+ option :root_password, default: SecureRandom.hex(), type: :string
12
+ option :server, type: :string
13
+ def install
14
+ configuration = IntercityCLI::Configuration.new()
15
+ address = options[:server] || configuration.active_server!
16
+
17
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
18
+
19
+ if File.exists?(node_file)
20
+ raw_json = File.read(node_file)
21
+ json = JSON.parse(raw_json)
22
+ else
23
+ json = {postgresql: {
24
+ password: { postgres: options[:root_password] }
25
+ }}
26
+ end
27
+
28
+ File.open(node_file, "w+") do |f|
29
+ f.write(JSON.pretty_generate(json))
30
+ end
31
+
32
+ server = address
33
+ user = options[:user]
34
+ on server do |host|
35
+ with debian_frontend: :noninteractive do
36
+ host.user = user
37
+
38
+ upload! node_file, "/root/server_config.json"
39
+
40
+ execute 'chef-solo -c solo.rb -j ~/server_config.json -o recipe[postgresql::server]'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -5,9 +5,26 @@ module IntercityCLI
5
5
  class Server < Thor
6
6
  require "sshkit/dsl"
7
7
 
8
+ desc "list", "Lists your servers"
9
+ def list()
10
+ configuration = IntercityCLI::Configuration.new()
11
+ Dir.chdir(configuration.nodes_directory) do
12
+ Dir["*.json"].each do |server_config|
13
+ server_name = server_config.gsub(".json", "")
14
+ if server_name == configuration.active_server
15
+ puts "* #{server_name}"
16
+ else
17
+ puts server_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+
8
23
  desc "install IPADDRESS", "Installs server at IPADDRESS"
9
24
  option :user, type: :string, default: "root"
10
25
  def install(address)
26
+ configuration = IntercityCLI::Configuration.new()
27
+
11
28
  server = address
12
29
  user = options[:user]
13
30
  on server do |host|
@@ -20,12 +37,21 @@ module IntercityCLI
20
37
  execute "curl -L https://www.chef.io/chef/install.sh | sudo bash"
21
38
 
22
39
  # Install chef-repo
23
- execute "wget http://binaries.intercityup.com/cookbooks/cookbooks-2.3.0.tar.gz?client=cli -O cookbooks-2.3.0.tar.gz"
24
- execute "tar zxf cookbooks-2.3.0.tar.gz"
40
+ execute "wget http://binaries.intercityup.com/cookbooks/cookbooks-2.3.1.tar.gz?client=cli -O cookbooks-2.3.1.tar.gz"
41
+ execute "tar zxf cookbooks-2.3.1.tar.gz"
42
+
43
+ solo_config = StringIO.new('cookbook_path ["/root/cookbooks"]')
44
+ upload! solo_config, "/root/solo.rb"
25
45
 
26
- execute "chef-client -z"
46
+ execute "chef-solo -c solo.rb"
27
47
  end
28
48
  end
49
+
50
+ configuration.active_server = address
51
+ puts
52
+ puts "Badam. Server #{address} initialized."
53
+ puts "This server will be used for subsequent commands."
54
+ puts "You can switch to a different server with \"intercity switch\"."
29
55
  end
30
56
  end
31
57
  end
@@ -0,0 +1,53 @@
1
+ require "thor"
2
+ require "sshkit"
3
+
4
+ module IntercityCLI
5
+ class SSHKey < Thor
6
+ require "sshkit/dsl"
7
+
8
+ desc "add", "Adds your workstation SSH key for deployment"
9
+ option :user, default: "root"
10
+ option :server, type: :string
11
+ option :ssh_public_key_path, type: :string, default: "~/.ssh/id_rsa.pub"
12
+ def add()
13
+ configuration = IntercityCLI::Configuration.new()
14
+ address = options[:server] || configuration.active_server!
15
+
16
+ node_file = File.join(configuration.nodes_directory, "#{address}.json")
17
+
18
+ if File.exists?(node_file)
19
+ raw_json = File.read(node_file)
20
+ json = JSON.parse(raw_json)
21
+ else
22
+ raise "No configuration file for this server yet! Please create one by running:\n\n$ intercity server install <ip address>\n\n"
23
+ end
24
+
25
+ ssh_key_path = File.expand_path(options[:ssh_public_key_path])
26
+ if !File.exists?(ssh_key_path)
27
+ raise "You don't have an SSH key yet. Generate one with ssh-keygen"
28
+ end
29
+
30
+ json["deploy_users"] ||= []
31
+ json["deploy_users"] << "deploy"
32
+ json["deploy_users"].uniq!
33
+
34
+ json["ssh_deploy_keys"] ||= []
35
+ json["ssh_deploy_keys"] << File.read(ssh_key_path)
36
+ json["ssh_deploy_keys"].uniq!
37
+
38
+ File.open(node_file, "w+") do |f|
39
+ f.write(JSON.pretty_generate(json))
40
+ end
41
+
42
+ server = address
43
+ user = options[:user]
44
+ on server do |host|
45
+ host.user = user
46
+
47
+ upload! node_file, "/root/server_config.json"
48
+
49
+ execute 'chef-solo -c solo.rb -j ~/server_config.json -o "recipe[ssh_deploy_keys]"'
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/intercity/cli.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require "thor"
2
2
  require "intercity/cli/server"
3
3
  require "intercity/cli/mysql"
4
+ require "intercity/cli/postgresql"
4
5
  require "intercity/cli/application"
6
+ require "intercity/cli/ssh_key"
7
+
8
+ require "fileutils"
5
9
 
6
10
  module IntercityCLI
7
11
 
@@ -14,19 +18,74 @@ module IntercityCLI
14
18
  desc "mysql SUBCOMMAND ARGS", "subcommands to manage mysql"
15
19
  subcommand "mysql", MySQL
16
20
 
21
+ desc "postgresql SUBCOMMAND ARGS", "subcommands to manage postgresql"
22
+ subcommand "postgresql", PostgreSQL
23
+
17
24
  desc "application SUBCOMMAND ARGS", "subcommands to manage applications"
18
25
  subcommand "application", Application
26
+
27
+ desc "sshkey SUBCOMMAND ARGS", "subcommand to manage SSH keys"
28
+ subcommand "sshkey", SSHKey
29
+
30
+ desc "switch SERVER", "switches Intercity CLI over to SERVER so you don't have to set --server"
31
+ def switch(server)
32
+ configuration = IntercityCLI::Configuration.new()
33
+ configuration.active_server = server
34
+ puts "Switched active server to #{server}"
35
+ end
36
+
37
+ desc "active", "Shows you which server is active for Intercity CLI"
38
+ def active
39
+ configuration = IntercityCLI::Configuration.new()
40
+ puts configuration.active_server
41
+ end
19
42
  end
20
43
 
21
44
  class Configuration
22
45
  def initialize()
23
- if !Dir.exists?("nodes")
24
- Dir.mkdir("nodes")
46
+ if !Dir.exists?(config_directory)
47
+ FileUtils.mkdir_p(nodes_directory)
48
+ end
49
+
50
+ if !Dir.exists?(config_directory)
51
+ FileUtils.mkdir_p(nodes_directory)
25
52
  end
26
53
  end
27
54
 
28
55
  def config_directory
29
- File.expand_path("nodes")
56
+ File.expand_path("~/.intercity")
57
+ end
58
+
59
+ def nodes_directory
60
+ File.expand_path("~/.intercity/nodes")
61
+ end
62
+
63
+ def active_server
64
+ if !@active_server
65
+ current_server_path = File.expand_path("~/.intercity/active_server")
66
+ if File.exists?(current_server_path)
67
+ @active_server = File.open(current_server_path, "r") do |f|
68
+ f.read
69
+ end
70
+ end
71
+ end
72
+ return @active_server
73
+ end
74
+
75
+ def active_server!
76
+ if !active_server
77
+ puts 'No active server yet. Use the "switch" command or pass a server with --server'
78
+ exist
79
+ else
80
+ return active_server
81
+ end
82
+ end
83
+
84
+ def active_server=(server)
85
+ current_server_path = File.expand_path("~/.intercity/active_server")
86
+ File.open(current_server_path, "w+") do |f|
87
+ f.write(server)
88
+ end
30
89
  end
31
90
  end
32
91
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michiel Sikkes
@@ -30,7 +30,7 @@ cert_chain:
30
30
  +MPuiRlaQjfZy/soMMERP/wuGpw6Ce94ITJ56wjQgl3YhqQPoE76KgRu4b4YwKhx
31
31
  H7APPQD4vksmpWYDCN7llFs/nPaYM6lkxy7bcHRQxaA/km9IF+0iwbhv9mDdDQ==
32
32
  -----END CERTIFICATE-----
33
- date: 2015-01-24 00:00:00.000000000 Z
33
+ date: 2015-03-15 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: thor
@@ -75,7 +75,9 @@ files:
75
75
  - lib/intercity/cli.rb
76
76
  - lib/intercity/cli/application.rb
77
77
  - lib/intercity/cli/mysql.rb
78
+ - lib/intercity/cli/postgresql.rb
78
79
  - lib/intercity/cli/server.rb
80
+ - lib/intercity/cli/ssh_key.rb
79
81
  homepage: https://intercityup.com
80
82
  licenses:
81
83
  - MIT
metadata.gz.sig CHANGED
Binary file