planet-express 0.1.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee6f8996b57476df49f605f2248ae35722f5c983
4
+ data.tar.gz: 96a7b590980f608746e6c8fe084aa2671a94398c
5
+ SHA512:
6
+ metadata.gz: a6eaaf9599d71cad4b000dd31a20ab30057d4e80ec313122f126d9d850bb1de5dad68461f87c58233dcbe32eaf04c7fb01ab81a9aecb2831fcac8577a5134684
7
+ data.tar.gz: 4c019c2f61769abc59ece3a61c63d9ed3b85a6bc9b487748744a688bd72a1b929c447a71ccdedeb41ac10cb77a7a8e019311d41b1f448fa272fdbca9913297ce
@@ -0,0 +1,42 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log# Created by https://www.gitignore.io
15
+
16
+ ### OSX ###
17
+ .DS_Store
18
+ .AppleDouble
19
+ .LSOverride
20
+
21
+ # Icon must end with two \r
22
+ Icon
23
+
24
+ # Thumbnails
25
+ ._*
26
+
27
+ # Files that might appear in the root of a volume
28
+ .DocumentRevisions-V100
29
+ .fseventsd
30
+ .Spotlight-V100
31
+ .TemporaryItems
32
+ .Trashes
33
+ .VolumeIcon.icns
34
+
35
+ # Directories potentially created on remote AFP share
36
+ .AppleDB
37
+ .AppleDesktop
38
+ Network Trash Folder
39
+ Temporary Items
40
+ .apdisk
41
+
42
+ Planetfile
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,84 @@
1
+ ![image](https://dl.dropboxusercontent.com/u/6888621/htdocs/planet-express.png)
2
+
3
+ Planet-Express
4
+ ==============
5
+
6
+ ![image](https://img.shields.io/badge/version-0.1.4-brightgreen.svg)
7
+
8
+ Planet Express is a command line utility written in **Ruby** to deploy code from git repositories.
9
+
10
+ **This project is under developpement. Consider this project not production-ready.**
11
+
12
+ Requirements
13
+ ------------
14
+
15
+ - Git > 2.x
16
+ - Ruby > 2.x
17
+
18
+ Installation
19
+ ------------
20
+
21
+ For now you can clone this repository and build the gem
22
+
23
+ ```
24
+ git clone git@github.com:yadomi/planet-express.git
25
+ bundle install
26
+ rake install
27
+ ```
28
+
29
+ Usage
30
+ -----
31
+
32
+ 1. Initialize your projet with a `Planetfile`:
33
+
34
+ ```
35
+ $ planet init
36
+ ```
37
+
38
+ This command created a `Planetfile` at the root of the projet. You may want to edit this file to adapt to your deployment stack.
39
+
40
+ 2. Setup on the remote server:
41
+
42
+ ```
43
+ $ planet setup preprod
44
+ ```
45
+ This command clone the repo on the remote host to the desired location.
46
+
47
+ 3. Deploy !
48
+
49
+ ```
50
+ $ planet deploy preprod
51
+ ```
52
+
53
+ This command pull the lastest revision of the specified branch on the remote host and then run hooks in **deploy/**.
54
+
55
+ FAQ
56
+ ---
57
+
58
+ TODO
59
+ ----
60
+
61
+ Statut | Task |
62
+ :-----:|------|
63
+ ☑ | Add todos |
64
+ ☑ | Write tests |
65
+ ☐ | Keep old releases |
66
+ ☐ | Auto rollback when deploy fail |
67
+
68
+ Planetfile API
69
+ --------------
70
+
71
+ ###Planet.configure
72
+
73
+ - `config.branch`: the default branch to pull from the repository (default: master)
74
+ - `config.repository`: the Git SCP-style URI repository URL
75
+ - `config.key`: the private SSH key used to connect to the repository (eg: GitHub)
76
+
77
+ ###Planet.target
78
+
79
+ - `server.ssh`: the deployement target using SCP Style URI.
80
+
81
+ The last part is the path where you want to deploy your project. You can use absolute (eg: **/path/to/deploy/location**) or
82
+ or relative path. This mean that deploy/location is the same than **/home/ user/deploy/location** or **~/deploy/location**
83
+
84
+ - `server.key`: The private SSH key used to connect to the server
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'planet'
7
+ Planet::Cli::Application.start(ARGV)
@@ -0,0 +1,123 @@
1
+ require 'thor'
2
+ require 'gitable/uri'
3
+ require 'net/ssh'
4
+
5
+ require 'planet/version'
6
+
7
+ module Planet
8
+ class << self
9
+ attr_accessor :configuration, :servers
10
+ end
11
+
12
+ class Configuration
13
+ attr_accessor :branch, :repository, :key
14
+ end
15
+
16
+ class Server
17
+ attr_accessor :ssh, :uri, :key
18
+ end
19
+
20
+ def self.target(s)
21
+ self.servers ||= Hash.new
22
+ self.servers[s] = Server.new
23
+
24
+ yield servers[s]
25
+ servers[s].uri = Gitable::URI.parse(servers[s].ssh)
26
+ servers[s].uri.path = '~/' + servers[s].uri.path unless servers[s].uri.path[0] == '/'
27
+
28
+ end
29
+
30
+ def self.configure
31
+ self.configuration ||= Configuration.new
32
+ yield configuration
33
+ end
34
+
35
+ module Cli
36
+ class Application < Thor
37
+
38
+ PLANET_FILE = 'Planetfile'
39
+ LOCAL_DIR = File.expand_path('..', __FILE__)
40
+
41
+
42
+
43
+ def initialize(*args)
44
+ super
45
+
46
+ unless initialized? then return end
47
+
48
+ if not File.file?(File.join(Dir.pwd, PLANET_FILE))
49
+ abort 'No Planetfile found in current folder'
50
+ end
51
+
52
+ @@planetfile = File.join(Dir.pwd, PLANET_FILE)
53
+ load @@planetfile
54
+
55
+ end
56
+
57
+
58
+
59
+ desc 'init', 'Initialize project with a dummy Planetfile and adds deploy scripts'
60
+ def init
61
+
62
+ if initialized? then
63
+ abort 'This projet has already been initialized with a Planetfile'
64
+ end
65
+
66
+ Dir.mkdir 'deploy/'
67
+ template_dir = File.join(LOCAL_DIR, 'template')
68
+ FileUtils.cp(File.join(template_dir, PLANET_FILE), '.')
69
+ FileUtils.cp(File.join(template_dir, 'after_deploy.sh'), 'deploy/')
70
+ FileUtils.chmod "u=wrx,go=rx", 'deploy/after_deploy.sh'
71
+
72
+ end
73
+
74
+
75
+
76
+ desc 'setup TARGET', 'Create the git repository on the remote and install hooks on it'
77
+ def setup(target)
78
+
79
+ unless initialized? then
80
+ abort "This project hasn't been initialized. Run planet init to initialize and commit your changes"
81
+ end
82
+
83
+ uri = Planet.servers[target.to_sym].uri
84
+ Net::SSH.start(uri.host, uri.user, :keys => [Planet.servers[target.to_sym].key] ) do |ssh|
85
+
86
+ if Planet.configuration.key
87
+ cmd = %{ ssh-agent bash -c '
88
+ ssh-add #{Planet.configuration.key } &&
89
+ git clone #{Planet.configuration.repository} #{uri.path}' }
90
+ else
91
+ cmd = %{ git clone --depth 1 #{Planet.configuration.repository} #{uri.path} }
92
+ end
93
+ ssh.exec(cmd)
94
+ end
95
+ end
96
+
97
+
98
+
99
+ desc 'deploy TARGET [BRANCH]', 'Deploy the application to the specified target'
100
+ def deploy(target, branch = Planet.configuration.branch )
101
+ uri = Planet.servers[target.to_sym].uri
102
+ Net::SSH.start(uri.host, uri.user, :keys => [Planet.servers[target.to_sym].key] ) do |ssh|
103
+ cmd = %{
104
+ cd #{uri.path} && \
105
+ git checkout #{branch} && \
106
+ git pull origin #{branch} && \
107
+ cd #{uri.path} && sh ./deploy/after_deploy.sh
108
+ }
109
+ ssh.exec(cmd)
110
+ end
111
+ end
112
+
113
+
114
+
115
+ private
116
+ def initialized?
117
+ cmd = %x[git ls-files | grep -c '#{PLANET_FILE}' ].chomp!
118
+ if cmd === '0' then false else true end
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,3 @@
1
+ module Version
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1 @@
1
+ echo "-> Triggering Hooks: $0"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'planet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.authors = ["Felix Yadomi"]
8
+ spec.email = ["felix.yadomi@gmail.com"]
9
+
10
+ spec.name = "planet-express"
11
+ spec.version = Version::VERSION
12
+ spec.summary = %q{Ship any code with Planet Express}
13
+
14
+ spec.files = `git ls-files`.split($\)
15
+ spec.executables = ['planet']
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency 'thor', '~> 0.19'
19
+ spec.add_dependency 'gitable', '~> 0.3'
20
+ spec.add_dependency 'net-ssh'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planet-express
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Felix Yadomi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gitable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description:
84
+ email:
85
+ - felix.yadomi@gmail.com
86
+ executables:
87
+ - planet
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/planet
96
+ - lib/planet.rb
97
+ - lib/planet/version.rb
98
+ - lib/template/Planetfile
99
+ - lib/template/after_deploy.sh
100
+ - planet.gemspec
101
+ homepage:
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.6
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Ship any code with Planet Express
124
+ test_files: []