server_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ada90b9349cffe38e7e70527223bff3e1aeae00
4
+ data.tar.gz: 6f095fc20aff6773d3da0c7e5143af63fc0a1272
5
+ SHA512:
6
+ metadata.gz: dd466b318dfabf619fe132975141d2fc851e005d2e962451e72b08f34d5e01c43707e6fddc799b2ee4f4bb92b5c7c7bea11a210f30a78bb0d6c35ed17210171b
7
+ data.tar.gz: 554a43a0725e5d783c94aee6d625d687712c7d56e0cdb8494d30984257e9ca8f1832428d5f9852edd677f39692865a99d5450aa2573c9df0fd88f6c8e54aaf1e
data/.chef/knife.rb ADDED
@@ -0,0 +1,2 @@
1
+ client_key File::NULL
2
+ validation_key File::NULL
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ Exclude:
5
+ - 'vendor/bundle/**/*'
6
+ - 'bin/**/*'
7
+
8
+ StringLiterals:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Max: 120
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/AccessModifierIndentation:
18
+ Enabled: false
19
+
20
+ Style/GuardClause:
21
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.2.3
6
+ before_install: gem update --remote bundler
7
+ install:
8
+ - bundle install
9
+ script:
10
+ - bin/rake
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Decomplect Software LLP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ [![Build Status](https://travis-ci.org/decomplect-io/server_tools.svg?branch=master)](https://travis-ci.org/decomplect-io/server_tools)
2
+ # Server Tools
3
+
4
+ A bunch of tools to provision (via Chef) and deploy packages to servers.
5
+
6
+ Available commands:
7
+
8
+ - `bootstrap`: Installs Chef on the provided host
9
+ - `provision`: Runs chef with the provided list of roles/recipes
10
+ - `install-deb-package`: Installs a local Debian package on the remote host (optionally purges the older version)
11
+
12
+ All command line flags can be seen by running `server_tools help`.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'server_tools'
20
+ ```
21
+
22
+ Or install directly via:
23
+ ```ruby
24
+ gem install server_tools
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bin/rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/decomplect-io/server_tools.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
4
+ require 'yard'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: [:rubocop, :spec]
8
+
9
+ desc 'Run rubocop'
10
+ RuboCop::RakeTask.new
11
+
12
+ desc 'Build documentation'
13
+ YARD::Rake::YardocTask.new
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "server_tools"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path vendor/bundle -j4
data/exe/server_tools ADDED
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
5
+
6
+ require 'rubygems'
7
+ require 'bundler/setup'
8
+ require 'server_tools/cli'
9
+
10
+ ServerTools::CLI.start(ARGV)
@@ -0,0 +1,23 @@
1
+ module ServerTools
2
+ class Bootstrap
3
+ def initialize(hostname, options)
4
+ @hostname = hostname
5
+ @options = options
6
+ end
7
+
8
+ def command
9
+ [
10
+ "bundle exec knife bootstrap #{hostname}",
11
+ "--identity-file #{options[:identity_file]}",
12
+ "--ssh-port #{options[:ssh_port]}",
13
+ "--ssh-user #{options[:ssh_user]}",
14
+ "--sudo",
15
+ "--local-mode"
16
+ ].join(' ')
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :hostname, :options
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ require 'thor'
2
+ require 'server_tools/support/shell_out'
3
+ require 'server_tools/bootstrap'
4
+ require 'server_tools/provision'
5
+ require 'server_tools/install_deb_package'
6
+
7
+ module ServerTools
8
+ class CLI < Thor
9
+ include ShellOut
10
+
11
+ class_option :identity_file,
12
+ desc: 'The private SSH key to use',
13
+ default: '$HOME/.ssh/id_rsa',
14
+ type: :string
15
+
16
+ class_option :ssh_user,
17
+ desc: 'The user to SSH in as',
18
+ default: `whoami`.chomp,
19
+ type: :string
20
+
21
+ class_option :ssh_port,
22
+ desc: 'The port to SSH into',
23
+ default: '22',
24
+ type: :string
25
+
26
+ desc 'bootstrap HOSTNAME/IP', 'install Chef on HOSTNAME/IP'
27
+ def bootstrap(hostname)
28
+ shell_out(ServerTools::Bootstrap.new(hostname, options).command)
29
+ end
30
+
31
+ desc 'provision HOSTNAME/IP', 'run chef-client on host with given recipes/roles'
32
+ option :roles,
33
+ desc: 'The recipes/roles to apply on the host',
34
+ required: true,
35
+ type: :array
36
+ def provision(hostname)
37
+ shell_out(ServerTools::Provision.new(hostname, options).command)
38
+ end
39
+
40
+ desc 'install-deb-package HOSTNAME', 'install a deb package on a remote host'
41
+ option :deb_package_name,
42
+ desc: 'The name of the deb package to install',
43
+ required: true,
44
+ type: :string
45
+
46
+ option :deb_package_file,
47
+ desc: 'The deb package to install',
48
+ required: true,
49
+ type: :string
50
+
51
+ option :purge_older_version,
52
+ desc: 'Purge the older version of the package?',
53
+ required: false,
54
+ defaut: false,
55
+ type: :boolean
56
+
57
+ def install_deb_package(hostname)
58
+ install_deb_package = ServerTools::InstallDebPackage.new(hostname, options)
59
+ shell_out(install_deb_package.copy_command)
60
+ shell_out(install_deb_package.install_command)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,43 @@
1
+ require 'server_tools/support/ssh'
2
+
3
+ module ServerTools
4
+ class InstallDebPackage
5
+ include SSH
6
+ def initialize(hostname, options)
7
+ @hostname = hostname
8
+ @options = options
9
+ end
10
+
11
+ def copy_command
12
+ [
13
+ "rsync -avz",
14
+ %(-e "ssh #{ssh_opts(options)}"),
15
+ "--progress --partial",
16
+ "#{options[:deb_package_file]}",
17
+ "#{options[:ssh_user]}@#{hostname}:~/"
18
+ ].join(' ')
19
+ end
20
+
21
+ def install_command
22
+ ["ssh #{hostname}", "#{ssh_opts(options)}"].tap do |command|
23
+ if options[:purge_older_version]
24
+ command << "#{purge_command} && #{_install_command}"
25
+ else
26
+ command << _install_command
27
+ end
28
+ end.join(' ')
29
+ end
30
+
31
+ private
32
+
33
+ def purge_command
34
+ "sudo dpkg -P #{options[:deb_package_name]}"
35
+ end
36
+
37
+ def _install_command
38
+ "sudo dpkg -i ~/#{File.basename(options[:deb_package_file])}"
39
+ end
40
+
41
+ attr_reader :hostname, :options
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ require 'server_tools/support/ssh'
2
+
3
+ module ServerTools
4
+ class Provision
5
+ include SSH
6
+ def initialize(hostname, options)
7
+ @hostname = hostname
8
+ @options = options
9
+ end
10
+
11
+ def command
12
+ [
13
+ "ssh #{hostname}",
14
+ "#{ssh_opts(options)}",
15
+ "sudo /usr/bin/chef-client -o'#{options[:roles].join(',')}'"
16
+ ].join(' ')
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :hostname, :options
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+ require 'mixlib/shellout'
3
+
4
+ module ShellOut
5
+ def shell_out(cmd, options: {})
6
+ opts = options.merge(live_stdout: STDOUT, live_stderr: STDERR)
7
+ shellout = Mixlib::ShellOut.new(cmd, opts)
8
+ puts cmd
9
+ Bundler.with_clean_env do
10
+ shellout.run_command
11
+ end
12
+ handle_errors(shellout)
13
+ end
14
+
15
+ private
16
+
17
+ def handle_errors(shellout)
18
+ if shellout.error?
19
+ STDERR.puts('Failure!')
20
+ STDERR.puts("Exit code: #{shellout.exitstatus}")
21
+ exit(shellout.exitstatus)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module SSH
2
+ def ssh_opts(options)
3
+ [
4
+ "-p #{options[:ssh_port]}",
5
+ "-i #{options[:identity_file]}",
6
+ "-l #{options[:ssh_user]}",
7
+ "-t -t",
8
+ "-o StrictHostKeyChecking=no",
9
+ "-o UserKnownHostsFile=/dev/null"
10
+ ].join(' ')
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ServerTools
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'server_tools/version'
2
+ require 'server_tools/cli'
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'server_tools/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "server_tools"
7
+ spec.version = ServerTools::VERSION
8
+ spec.authors = ["Decomplect Software LLP"]
9
+ spec.email = ["hello@decomplect.io"]
10
+
11
+ spec.summary = %(A bunch of tools to provision (via Chef) and deploy packages to servers)
12
+ spec.homepage = "https://github.com/decomplect-io/server_tools"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.10"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rubocop", "~> 0.3"
23
+ spec.add_development_dependency "yard", "~> 0.8"
24
+ spec.add_development_dependency "redcarpet", "~> 3.3"
25
+
26
+ spec.add_dependency "chef", "~> 12.3"
27
+ spec.add_dependency "thor", "~> 0.19"
28
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: server_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Decomplect Software LLP
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chef
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.19'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.19'
111
+ description:
112
+ email:
113
+ - hello@decomplect.io
114
+ executables:
115
+ - server_tools
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".chef/knife.rb"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".ruby-version"
124
+ - ".travis.yml"
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/rake
131
+ - bin/setup
132
+ - exe/server_tools
133
+ - lib/server_tools.rb
134
+ - lib/server_tools/bootstrap.rb
135
+ - lib/server_tools/cli.rb
136
+ - lib/server_tools/install_deb_package.rb
137
+ - lib/server_tools/provision.rb
138
+ - lib/server_tools/support/shell_out.rb
139
+ - lib/server_tools/support/ssh.rb
140
+ - lib/server_tools/version.rb
141
+ - server_tools.gemspec
142
+ homepage: https://github.com/decomplect-io/server_tools
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.4.8
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: A bunch of tools to provision (via Chef) and deploy packages to servers
166
+ test_files: []
167
+ has_rdoc: