travis-custom-deploy 0.0.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aec931f741eed8f077825a3befa8466e5e4976f6
4
- data.tar.gz: 5532a7c0308adc31324907698f77c67ed1161236
3
+ metadata.gz: 76a456e9755c9e0f605bf5284750ff4143d3fac9
4
+ data.tar.gz: 3db5ba20e932a1139ca16258f764ba6f3b1fe91b
5
5
  SHA512:
6
- metadata.gz: 520ad562cd94147e07f0f61e91f5b9ab6ea096624a4c5d04d024e32d3b5bc0fdc867b34012208fa4a426a4cbeccefac062e2dcc989a134e293f4eab62af025f0
7
- data.tar.gz: 265c9efffe93c98e2bff80db8e516fa165a9a6a3464a71b4cb0959b449443e9a619eab071f216055404779d16496f4d1cb8af907f8ea4f96ef5887f9f84ae835
6
+ metadata.gz: 6d08feb91cd3845d41ccf3ed034d174d7f80e41b9ab908b0d2b6d41e3e1623adfb1c645cbf100657c94ba644c6f5e020d4132c6b4f3e4e274fd95aa3e1416c88
7
+ data.tar.gz: 0bf6ac51455bd1aca593e72dbbeaac76f872c349f498fe37b64bdea8bb4dbe00ca254f2c6ae3b418d2d3b4f0189702dd64bef34c0ac1585e8fee9e33222803d3
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ cache: bundler
3
+ before_install:
4
+ - gem install bundler
5
+ rvm:
6
+ - 2.1.0
7
+ script: bundle exec rake
data/LICENSE.md CHANGED
@@ -0,0 +1,23 @@
1
+
2
+ The MIT License
3
+ ===============
4
+
5
+ Copyright (c) 2013, Jens Nazarenus
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
- travis-custom-deploy
1
+ travis-custom-deploy [![Gem Version](https://badge.fury.io/rb/travis-custom-deploy.png)](http://badge.fury.io/rb/travis-custom-deploy)
2
2
  ====================
3
+ [![Build Status](https://travis-ci.org/jens-na/travis-custom-deploy.png?branch=master)](https://travis-ci.org/jens-na/travis-custom-deploy) [![Coverage Status](https://coveralls.io/repos/jens-na/travis-custom-deploy/badge.png?branch=master)](https://coveralls.io/r/jens-na/travis-custom-deploy?branch=master)
4
+ [![Dependency Status](https://gemnasium.com/jens-na/travis-custom-deploy.png)](https://gemnasium.com/jens-na/travis-custom-deploy)
3
5
 
4
6
  Deploy your ruby based applications on your own server.
5
7
 
8
+ Configuration
9
+ -------------
10
+ You need to define environment variables with Travis. `travis-custom-deploy` will use those to
11
+ deploy your application.
12
+
13
+ Example:
14
+ ```yml
6
15
  env:
7
16
  global:
8
17
  - "CUSTOM_DEPLOY_HOST=host"
@@ -10,4 +19,25 @@ env:
10
19
  - "CUSTOM_DEPLOY_PASSWORD=password"
11
20
  - "CUSTOM_DEPLOY_REMOTEDIR=/path/to/"
12
21
 
13
- travis-custom-deploy sftp site/
22
+ after_success: travis-custom-deploy sftp _site/
23
+ ```
24
+
25
+ #### Services
26
+ There are predefined services available. For example if you want to deploy a [Jekyll](https://github.com/jekyll/jekyll) page you can write:
27
+
28
+ ```yml
29
+ after_success: travis-custom-deploy sftp service:jekyll
30
+ ```
31
+
32
+ Services currently availble:
33
+ ```
34
+ Service File
35
+ -------- -------
36
+ jekyll _site/
37
+ ```
38
+
39
+ License and Copyright
40
+ =====================
41
+ Licensed under the MIT license.
42
+
43
+ Jens Nazarenus, 2014
@@ -6,25 +6,26 @@ def usage
6
6
  puts 'Usage: travis-custom-deploy TRANSFER_TYPE FILES...'
7
7
  end
8
8
 
9
+ # Returns a list of read environment variables in a hash based
10
+ # on options.rb. The hash may be used as parameter for deployment.rb.
11
+ def get_env_vars(transfer_type)
12
+ envs = TravisCustomDeploy::Options.get_options(transfer_type)
13
+ options = {}
14
+ for e in envs
15
+ value = ENV['DEPLOY_' + e.upcase]
16
+ options[e] = value
17
+ end
18
+ options
19
+ end
20
+
9
21
  if ARGV.count < 2
10
22
  usage
11
23
  end
12
24
 
13
- transfer = ARGV[0]
25
+ transfer_type = ARGV[0]
14
26
  files = ARGV[1..-1]
15
27
 
16
- host = ENV['DEPLOY_HOST']
17
- username = ENV['DEPLOY_USERNAME']
18
- password = ENV['DEPLOY_PASSWORD']
19
- remotedir = ENV['DEPLOY_REMOTEDIR']
20
-
21
- transfer_opts = {
22
- :type => transfer,
23
- :host => ENV['DEPLOY_HOST'],
24
- :username => ENV['DEPLOY_USERNAME'],
25
- :password => ENV['DEPLOY_PASSWORD'],
26
- :remotedir => ENV['DEPLOY_REMOTEDIR']
27
- }
28
+ options = get_env_vars(transfer_type)
28
29
 
29
- d = TravisCustomDeploy::Deployment.new(transfer_opts, files)
30
+ d = TravisCustomDeploy::Deployment.new(transfer_type, options, files)
30
31
  d.deploy
@@ -1,5 +1,5 @@
1
1
  require 'travis-custom-deploy/deployment'
2
2
  require 'travis-custom-deploy/transfer'
3
3
  require 'travis-custom-deploy/version'
4
- require 'travis-custom-deploy/services'
4
+ require 'travis-custom-deploy/options'
5
5
  require 'travis-custom-deploy/transfer/base'
@@ -2,39 +2,33 @@ module TravisCustomDeploy
2
2
 
3
3
  class Deployment
4
4
 
5
- attr_reader :remoteopts
5
+ attr_reader :options
6
6
  attr_reader :files
7
7
 
8
- def initialize(remoteopts, files)
9
- check_remoteopts(remoteopts)
10
- @remoteopts = remoteopts
8
+ # Initializes a new deployment
9
+ #
10
+ # remteopts - the options to connect to the remote server
11
+ # files - the files to transfer
12
+ def initialize(transfer_type, options, files)
13
+ raise ArgumentError, 'transfer type must not be nil' if transfer_type.nil?
11
14
  @files = files
12
15
  check_services(@files[0])
13
- @transfer = get_transfer(remoteopts[:type])
16
+ @options = options
17
+ @transfer = get_transfer(transfer_type)
14
18
  end
15
19
 
16
- # Actually start the deployment
20
+ # Starts the deployment
17
21
  def deploy
18
22
  @transfer.transfer
19
23
  end
20
24
 
21
- # Check if the remoteopts are valid
22
- #
23
- # opts - the remote opts to check
24
- def check_remoteopts(opts)
25
- raise ArgumentError, 'host must not be nil' if opts[:host].nil?
26
- raise ArgumentError, 'username must not be nil' if opts[:username].nil?
27
- raise ArgumentError, 'password must not be nil' if opts[:password].nil?
28
- raise ArgumentError, 'transfer type must not be nil' if opts[:type].nil?
29
- end
30
-
31
- # Create an instance for the transfer type and return it
25
+ # Creates an instance for the transfer type and return it
32
26
  #
33
27
  # type - the transfer type like sftp, ftp, etc.
34
28
  def get_transfer(type)
35
29
  type = type[0].upcase + type[1..-1]
36
30
  try_require(type)
37
- Transfer.const_get(type).new(@remoteopts, @files)
31
+ Transfer.const_get(type).new(@options, @files)
38
32
  end
39
33
 
40
34
  # Try requiring a transfer type class
@@ -46,7 +40,7 @@ module TravisCustomDeploy
46
40
  end
47
41
  protected :try_require
48
42
 
49
- # check if the first file matches service:<service-name>
43
+ # Check if the first file matches service:<service-name>
50
44
  # and try to determine the files based on the service.
51
45
  #
52
46
  # first_file the first file given
@@ -0,0 +1,46 @@
1
+ module TravisCustomDeploy
2
+
3
+ # The available services. Each service has an
4
+ # unique id and an array of files or directories to deploy.
5
+ SERVICES = {
6
+
7
+ # Jekyll support
8
+ # Usage: service:jekyll
9
+ 'jekyll' => [ '_site/' ]
10
+ }
11
+
12
+ # The possible options of the different transfer types
13
+ OPTIONS = {
14
+
15
+ 'sftp' => [
16
+ 'host', # host name of the sftp server
17
+ 'username', # username to connect
18
+ 'password', # password to connect
19
+ 'remotedir' # remote dir, for example: /public/
20
+ ],
21
+
22
+ 'ftp' => [
23
+ 'host', # host name of the ftp server
24
+ 'username', # username to connect
25
+ 'password', # password to connect
26
+ 'remotedir' # remote dir, for example: /public/
27
+ ],
28
+
29
+ 'copy' => [
30
+ 'remotedir' # the destination where to copy the files
31
+ ]
32
+
33
+ }
34
+
35
+ class Options
36
+
37
+ def self.get_options(transfer_type)
38
+ OPTIONS.each do |k,v|
39
+ if k == transfer_type
40
+ return v
41
+ end
42
+ end
43
+ nil
44
+ end
45
+ end
46
+ end
@@ -4,6 +4,7 @@ module TravisCustomDeploy
4
4
 
5
5
  autoload :Sftp, 'travis-custom-deploy/transfer/sftp'
6
6
  autoload :Ftp, 'travis-custom-deploy/transfer/ftp'
7
+ autoload :Copy, 'travis-custom-deploy/transfer/copy'
7
8
 
8
9
  end
9
10
 
@@ -4,13 +4,13 @@ module TravisCustomDeploy
4
4
 
5
5
  class Base
6
6
 
7
- attr_reader :remoteopts
7
+ attr_reader :options
8
8
  attr_reader :files
9
9
 
10
- def initialize(remoteopts, files)
11
- @remoteopts = remoteopts
10
+ def initialize(options, files)
11
+ @options = options
12
12
  @files = files
13
- prepare_remotedir
13
+ check_options(options)
14
14
  end
15
15
 
16
16
  # The method which needs to be implemented by subclasses
@@ -19,12 +19,13 @@ module TravisCustomDeploy
19
19
  raise NotImplementedError
20
20
  end
21
21
 
22
- # Prepares the remote directory (remote trailing slash)
23
- def prepare_remotedir
24
- @remotedir = @remoteopts[:remotedir]
25
- @remotedir = "" if @remotedir.nil?
26
- @remotedir = @remotedir[0..-2] if @remotedir[-1] == "/"
22
+ # The method which needs to be implemented by subclasses
23
+ # to check if the remote options are sufficient for the
24
+ # defined transfer type
25
+ def check_options
26
+ raise NotImplementedError
27
27
  end
28
+
28
29
  end
29
30
  end
30
31
  end
@@ -0,0 +1,12 @@
1
+ module TravisCustomDeploy
2
+
3
+ module Transfer
4
+
5
+ class Copy < Base
6
+
7
+ def initialize
8
+ super(@remoteopts, files)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module TravisCustomDeploy
2
+
3
+ module Transfer
4
+
5
+ # The class which transfers files via the File Transfer protocol (FTP).
6
+ class Ftp < Base
7
+
8
+ def initialize(remoteopts, files)
9
+ super(remoteopts, files)
10
+ end
11
+
12
+ def transfer
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -4,22 +4,37 @@ module TravisCustomDeploy
4
4
 
5
5
  module Transfer
6
6
 
7
+ # The class which transfers files via the SSH File Transfer Protocol
8
+ # (SFTP).
7
9
  class Sftp < Base
8
10
 
9
- def initialize(remoteopts, files)
10
- super(remoteopts, files)
11
+ def initialize(options, files)
12
+ super(options, files)
13
+ prepare_remotedir
11
14
  end
12
15
 
13
- # transfers the given files via sftp
14
16
  def transfer
15
- Net::SFTP.start(@remoteopts[:host], @remoteopts[:username], :password => @remoteopts[:password]) do |sftp|
17
+ Net::SFTP.start(@options['host'], @options['username'],
18
+ :password => @options['password']) do |sftp|
16
19
  for e in @files
17
20
  sftp.upload!(e, "#{@remotedir}/")
18
21
  end
19
22
  end
20
23
  end
21
24
 
25
+ def check_options(options)
26
+ raise ArgumentError, 'host name must not be nil' if options['host'].nil?
27
+ raise ArgumentError, 'username must not be nil' if options['username'].nil?
28
+ raise ArgumentError, 'password must not be nil' if options['password'].nil?
29
+ end
22
30
 
31
+ # Prepares the remote directory (remote trailing slash)
32
+ def prepare_remotedir
33
+ @remotedir = @options[:remotedir]
34
+ @remotedir = "" if @remotedir.nil?
35
+ @remotedir = @remotedir[0..-2] if @remotedir[-1] == "/"
36
+ end
37
+
23
38
  end
24
39
  end
25
40
  end
@@ -1,5 +1,5 @@
1
1
  module TravisCustomDeploy
2
2
 
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
 
5
5
  end
@@ -5,17 +5,16 @@ class TestDeployment < Test::Unit::TestCase
5
5
  context "A deployment" do
6
6
  setup do
7
7
  @opts = {
8
- :type => 'sftp',
9
- :host => 'example.org',
10
- :username => 'username',
11
- :password => 'password',
12
- :remotedir => '/public/'
8
+ 'host' => 'example.org',
9
+ 'username' => 'username',
10
+ 'password' => 'password',
11
+ 'remotedir' => '/public/'
13
12
  }
14
13
  end
15
14
 
16
15
  context "with files" do
17
16
  setup do
18
- @deployment = Deployment.new(@opts, ['foo', 'bar', 'foo2'])
17
+ @deployment = Deployment.new('sftp', @opts, ['foo', 'bar', 'foo2'])
19
18
  end
20
19
 
21
20
  should "return file names" do
@@ -25,7 +24,7 @@ class TestDeployment < Test::Unit::TestCase
25
24
 
26
25
  context "with service identifier as first file name" do
27
26
  setup do
28
- @deployment = Deployment.new(@opts, ['service:jekyll'])
27
+ @deployment = Deployment.new('sftp', @opts, ['service:jekyll'])
29
28
  end
30
29
 
31
30
  should "return file names of service" do
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class TestOptions < Test::Unit::TestCase
4
+
5
+ context "Options" do
6
+
7
+ context "environment variables" do
8
+ setup do
9
+ @env = Options.get_options('sftp')
10
+ end
11
+
12
+ should "return sftp options" do
13
+ assert_equal ['host', 'username', 'password', 'remotedir'], @env
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-custom-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Nazarenus
@@ -159,6 +159,7 @@ extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
161
  - ".gitignore"
162
+ - ".travis.yml"
162
163
  - Gemfile
163
164
  - LICENSE.md
164
165
  - README.md
@@ -168,14 +169,16 @@ files:
168
169
  - features/.gitkeep
169
170
  - lib/travis-custom-deploy.rb
170
171
  - lib/travis-custom-deploy/deployment.rb
171
- - lib/travis-custom-deploy/services.rb
172
+ - lib/travis-custom-deploy/options.rb
172
173
  - lib/travis-custom-deploy/transfer.rb
173
174
  - lib/travis-custom-deploy/transfer/base.rb
175
+ - lib/travis-custom-deploy/transfer/copy.rb
174
176
  - lib/travis-custom-deploy/transfer/ftp.rb
175
177
  - lib/travis-custom-deploy/transfer/sftp.rb
176
178
  - lib/travis-custom-deploy/version.rb
177
179
  - test/helper.rb
178
180
  - test/test_deployment.rb
181
+ - test/test_options.rb
179
182
  - travis-custom-deploy.gemspec
180
183
  homepage: https://github.com/jens-na/travis-custom-deploy
181
184
  licenses:
@@ -205,3 +208,4 @@ test_files:
205
208
  - features/.gitkeep
206
209
  - test/helper.rb
207
210
  - test/test_deployment.rb
211
+ - test/test_options.rb
@@ -1,10 +0,0 @@
1
- module TravisCustomDeploy
2
-
3
- SERVICES = {
4
-
5
- 'jekyll' => [ '_site/' ]
6
-
7
- # future services
8
- }
9
-
10
- end