placer 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +16 -0
- data/bin/placer +6 -0
- data/lib/my_logger.rb +12 -0
- data/lib/placer.rb +69 -0
- data/lib/placer_dsl.rb +62 -0
- data/placer.rb +18 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5096d719ac49f40ad59c6e52dfb19934a7929fb
|
4
|
+
data.tar.gz: 04205c0121ffed5e8fab9b0c62bdfa15918e5ace
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b8844240a7b9729b9674fefcd26e5d9d1bee3e2c5002bb884ce9412f9c507896b4e6c357df2dfc19a7eaa22e7e986b8e579b1be1016caa0206db57ab504f2c9
|
7
|
+
data.tar.gz: afa2a6ac773a71c314c8c07eddb91b34ef12efc83c07b47dc33aa782f2f720e6b6813d76440e36da5cb891041307806196775440dd80cf53e98ac07e742969b0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/bin/placer
ADDED
data/lib/my_logger.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Supported levels are basically every user-defined symbol
|
2
|
+
class MyLogger
|
3
|
+
# Pass [:all] to log just everything
|
4
|
+
def initialize(*hide_levels)
|
5
|
+
@hide_levels = hide_levels.flatten
|
6
|
+
end
|
7
|
+
|
8
|
+
def log(level, message)
|
9
|
+
return if @hide_levels.include?(:all) || @hide_levels.include?(level)
|
10
|
+
puts "[LOG] [#{level.to_s.upcase}]: #{message}"
|
11
|
+
end
|
12
|
+
end
|
data/lib/placer.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative 'placer_dsl'
|
3
|
+
require_relative 'my_logger'
|
4
|
+
|
5
|
+
class Placer
|
6
|
+
def initialize(args)
|
7
|
+
@args, @params = parse_options(args)
|
8
|
+
@logger = @params[:log] ? MyLogger.new : MyLogger.new(:all)
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
@logger.log(:info, "Loading config file #{@params[:config_path]}")
|
13
|
+
if @params[:debug]
|
14
|
+
run
|
15
|
+
else
|
16
|
+
begin
|
17
|
+
run
|
18
|
+
rescue => e
|
19
|
+
@logger.log(:error, e)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
PlacerDSL.new(File.read(@params[:config_path]), @logger)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_options(args)
|
29
|
+
opts = OptionParser.new
|
30
|
+
params = {}
|
31
|
+
|
32
|
+
banner = <<BANNER
|
33
|
+
placer - a simpler deployment
|
34
|
+
deployment back to the basics
|
35
|
+
|
36
|
+
If you have no config, just start off by the example in the repo/placer.yaml.
|
37
|
+
In case you are wondering, public/private key auth is the only way.
|
38
|
+
We don't support manual solutions. This tool is thought for automated use.
|
39
|
+
|
40
|
+
Usage: placer [options]
|
41
|
+
BANNER
|
42
|
+
|
43
|
+
opts.banner = banner
|
44
|
+
|
45
|
+
params[:log] = true
|
46
|
+
opts.on('-q', '--[no-]log', 'toggle logging') do |val|
|
47
|
+
params[:log] = val
|
48
|
+
end
|
49
|
+
|
50
|
+
params[:config_path] = 'placer.rb'
|
51
|
+
opts.on('-c', '--config FILE', 'path to config FILE to use default: ' << params[:config_path]) do |file|
|
52
|
+
params[:config_path] = file
|
53
|
+
end
|
54
|
+
|
55
|
+
params[:debug] = false
|
56
|
+
opts.on('--debug', 'enable debugging') do
|
57
|
+
params[:debug] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on_tail('-h', '--help', 'shows this message') do
|
61
|
+
puts opts
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
args = opts.parse(args)
|
66
|
+
|
67
|
+
[args, params]
|
68
|
+
end
|
69
|
+
end
|
data/lib/placer_dsl.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'net/sftp'
|
3
|
+
|
4
|
+
class SSHDSL
|
5
|
+
def initialize(conn, logger)
|
6
|
+
@conn = conn
|
7
|
+
@logger = logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def exec(*command)
|
11
|
+
cmd = command.flatten.join(' ')
|
12
|
+
@logger.log(:ssh_exec, "Executing command #{cmd} on remote")
|
13
|
+
@conn.exec!(cmd) do |channel, stream, data|
|
14
|
+
{:stdout => :ssh_info, :stderr => :ssh_error}.each do |s, l|
|
15
|
+
data.lines.each{ |d| @logger.log(l, d) if stream == s }
|
16
|
+
end
|
17
|
+
|
18
|
+
channel.on_request("exit-status") do |ch, data|
|
19
|
+
exit_code = data.read_long
|
20
|
+
raise "remote command: \"#{cmd}\" returned with non-zero exit code: #{exit_code}" if exit_code != 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class SFTPDSL
|
27
|
+
def initialize(conn, logger)
|
28
|
+
@conn = conn
|
29
|
+
@logger = logger
|
30
|
+
end
|
31
|
+
|
32
|
+
def upload(from, to)
|
33
|
+
Dir.glob(from).each do |src|
|
34
|
+
to.flatten.each do |dst|
|
35
|
+
dst += File.basename(src) if dst.end_with?('/')
|
36
|
+
@logger.log(:sftp, "Uploading #{src} to #{dst}")
|
37
|
+
# Maybe parallel uploads with @conn.upload!
|
38
|
+
@conn.upload!(src, dst)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class PlacerDSL
|
45
|
+
def initialize(config, logger)
|
46
|
+
@logger = logger
|
47
|
+
|
48
|
+
instance_eval config
|
49
|
+
end
|
50
|
+
|
51
|
+
def ssh(&block)
|
52
|
+
Net::SSH.start(@ssh_host, @ssh_user, @ssh_options) do |c|
|
53
|
+
block.call SSHDSL.new(c, @logger)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def sftp(&block)
|
58
|
+
Net::SFTP.start(@ssh_host, @ssh_user, @ssh_options) do |c|
|
59
|
+
block.call SFTPDSL.new(c, @logger)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/placer.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# @ssh_host, @ssh_user and @ssh_options are used for sftp and ssh
|
2
|
+
@ssh_host = 'ekranos.me'
|
3
|
+
@ssh_user = 'ekranos'
|
4
|
+
@ssh_options = {port: 10099, user: 'ekranos', keys: '~/.ssh/ekranos.me', keys_only: true}
|
5
|
+
@tmp_gem_path = '/tmp/placer.gem'
|
6
|
+
@public_path = "/home/#{@ssh_user}/caddy/public.ekranos.me/browse"
|
7
|
+
|
8
|
+
sftp do |sftp|
|
9
|
+
{'placer-*.gem' => [@tmp_gem_path, "#{@public_path}/ruby/gems/placer/"]}.each do |k, v|
|
10
|
+
sftp.upload k, v
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ssh do |ssh|
|
15
|
+
['gem install', 'rm'].each do |cmd|
|
16
|
+
ssh.exec "#{cmd} '#{@tmp_gem_path}'"
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: placer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marvin Lee Fimmel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Automates Deployment via ssh and sftp. Focuses on simplicity.
|
14
|
+
email: kontakt@ekranos.me
|
15
|
+
executables:
|
16
|
+
- placer
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- bin/placer
|
23
|
+
- lib/my_logger.rb
|
24
|
+
- lib/placer.rb
|
25
|
+
- lib/placer_dsl.rb
|
26
|
+
- placer.rb
|
27
|
+
homepage: https://git.ekranos.me/ekranos/placer
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements:
|
46
|
+
- net-ssh
|
47
|
+
- net-sftp
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.6.8
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Simple Deployment Automation
|
53
|
+
test_files: []
|