travis-custom-deploy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/LICENSE.md +23 -0
- data/README.md +32 -2
- data/bin/travis-custom-deploy +15 -14
- data/lib/travis-custom-deploy.rb +1 -1
- data/lib/travis-custom-deploy/deployment.rb +13 -19
- data/lib/travis-custom-deploy/options.rb +46 -0
- data/lib/travis-custom-deploy/transfer.rb +1 -0
- data/lib/travis-custom-deploy/transfer/base.rb +10 -9
- data/lib/travis-custom-deploy/transfer/copy.rb +12 -0
- data/lib/travis-custom-deploy/transfer/ftp.rb +17 -0
- data/lib/travis-custom-deploy/transfer/sftp.rb +19 -4
- data/lib/travis-custom-deploy/version.rb +1 -1
- data/test/test_deployment.rb +6 -7
- data/test/test_options.rb +17 -0
- metadata +6 -2
- data/lib/travis-custom-deploy/services.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a456e9755c9e0f605bf5284750ff4143d3fac9
|
4
|
+
data.tar.gz: 3db5ba20e932a1139ca16258f764ba6f3b1fe91b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d08feb91cd3845d41ccf3ed034d174d7f80e41b9ab908b0d2b6d41e3e1623adfb1c645cbf100657c94ba644c6f5e020d4132c6b4f3e4e274fd95aa3e1416c88
|
7
|
+
data.tar.gz: 0bf6ac51455bd1aca593e72dbbeaac76f872c349f498fe37b64bdea8bb4dbe00ca254f2c6ae3b418d2d3b4f0189702dd64bef34c0ac1585e8fee9e33222803d3
|
data/.travis.yml
ADDED
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
|
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
|
data/bin/travis-custom-deploy
CHANGED
@@ -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
|
-
|
25
|
+
transfer_type = ARGV[0]
|
14
26
|
files = ARGV[1..-1]
|
15
27
|
|
16
|
-
|
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(
|
30
|
+
d = TravisCustomDeploy::Deployment.new(transfer_type, options, files)
|
30
31
|
d.deploy
|
data/lib/travis-custom-deploy.rb
CHANGED
@@ -2,39 +2,33 @@ module TravisCustomDeploy
|
|
2
2
|
|
3
3
|
class Deployment
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :options
|
6
6
|
attr_reader :files
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
@
|
16
|
+
@options = options
|
17
|
+
@transfer = get_transfer(transfer_type)
|
14
18
|
end
|
15
19
|
|
16
|
-
#
|
20
|
+
# Starts the deployment
|
17
21
|
def deploy
|
18
22
|
@transfer.transfer
|
19
23
|
end
|
20
24
|
|
21
|
-
#
|
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(@
|
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
|
-
#
|
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,13 +4,13 @@ module TravisCustomDeploy
|
|
4
4
|
|
5
5
|
class Base
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :options
|
8
8
|
attr_reader :files
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(options, files)
|
11
|
+
@options = options
|
12
12
|
@files = files
|
13
|
-
|
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
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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,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(
|
10
|
-
super(
|
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(@
|
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
|
data/test/test_deployment.rb
CHANGED
@@ -5,17 +5,16 @@ class TestDeployment < Test::Unit::TestCase
|
|
5
5
|
context "A deployment" do
|
6
6
|
setup do
|
7
7
|
@opts = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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.
|
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/
|
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
|