ski 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbaf7eaddb47af6314b91d0730ac015ea9f0450e
4
+ data.tar.gz: 70338abe261e6c9c65816113bb41af5344771dfe
5
+ SHA512:
6
+ metadata.gz: d67d923ae65f1c9e5c0d9a08906fa95adde73563a7b1f23b02c18fea348b0a4d7ede30288d5fa4bc6c57660996a0de13607d60604320dbaa3e71bea8904fd957
7
+ data.tar.gz: 1dbb4bb9b0684827c7f07e88581ca0b2e9c0067b0bf6cce9218a40abcc7d247a6bf379b7daf71cc9f574cd99b5a78750c920be0a60a7c7be189332286a3cb87a
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem 'net-ssh'
data/LICENSE ADDED
@@ -0,0 +1,6 @@
1
+ Copyright (c) 2018 Niklas Hanft
2
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+
4
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+
6
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Ski
2
+ ### A automation framework made for portability
3
+
4
+ Installation:
5
+
6
+ `gem install ski`
7
+
8
+ Example setup:
9
+
10
+ 1. Create a `.ski/` directory in your project.
11
+
12
+ 2. Add a file `your-project.yml` to `.ski/`
13
+
14
+ ``` yaml
15
+ title: Your Project
16
+ description: Hello World
17
+ pipelines:
18
+ - pipeline:
19
+ id: build
20
+ description: Build local docker images
21
+ fail-fast: true
22
+ target: :local
23
+ tasks:
24
+ - task:
25
+ name: Show all local files
26
+ command: ls .
27
+ - task:
28
+ name: Space used
29
+ command: du -sch .
30
+ - task:
31
+ name: Ping google exactly one time
32
+ command: ping google.de -t 1
33
+ - task:
34
+ name: Check processes running of port 3000
35
+ command: lsof -i :3000
36
+ - task:
37
+ name: Check ruby version
38
+ command: ruby -v
39
+ on-success:
40
+ tasks:
41
+ - task:
42
+ name: Wish a happy day
43
+ command: echo 'Hey dear, the deployment was successfull. Have a nice day! :)'
44
+ on-error:
45
+ tasks:
46
+ - task:
47
+ name: Build App server
48
+ command: echo 'Hello World'
49
+ - pipeline:
50
+ id: deploy
51
+ description: Build local docker images
52
+ fail-fast: true
53
+ target: :local
54
+ tasks:
55
+ - task:
56
+ name: Deploy to prod
57
+ command: echo 'Deploy to prod'
58
+ on-success:
59
+ tasks:
60
+ - task:
61
+ name: Build App server
62
+ command: echo 'Hello World'
63
+ on-error:
64
+ tasks:
65
+ - task:
66
+ name: Build App server
67
+ command: echo 'Hello World'
68
+ targets:
69
+ - target:
70
+ name: local
71
+ ip: 192.168.0.1
72
+ username: root
73
+ password: :prompt
74
+ ssh-key: true
75
+ ```
76
+
77
+ 3. Run:
78
+ `ski -P your-project -p build`
data/bin/ski ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/ski'
3
+ require 'optparse'
4
+
5
+ usage = "Usage: ski :project run :pipeline"
6
+
7
+ # This will hold the options we parse
8
+ options = {}
9
+
10
+ OptionParser.new do |opts|
11
+ opts.on('-P', '--project PROJECT', 'Given project') do |project|
12
+ options[:project] = project
13
+ end
14
+ opts.on('-p', '--pipeline PIPELINE', 'Given pipeline') do |pipeline|
15
+ options[:pipeline] = pipeline
16
+ end
17
+ end.parse!
18
+
19
+ if options[:project].nil? || options[:pipeline].nil?
20
+ puts "ERROR: Either project or pipeline is not correctly set!"
21
+ exit 255
22
+ end
23
+
24
+ Ski::Ski.new(options[:project],options[:pipeline])
@@ -0,0 +1,4 @@
1
+ module Ski
2
+ class MissingAttributeError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Ski
2
+ class NoSkiProjectError < StandardError
3
+ end
4
+ end
data/lib/project.rb ADDED
@@ -0,0 +1,79 @@
1
+ require_relative 'missing_attribute_error'
2
+
3
+ module Ski
4
+ class Project
5
+ attr_reader :title
6
+ attr_reader :description
7
+ attr_reader :pipelines
8
+ attr_reader :credentials
9
+
10
+ def initialize(config)
11
+ @title = config.dig('title')
12
+ @description = config.dig('description')
13
+ @pipelines = config.dig('pipelines')
14
+ @credentials = config.dig('pipelines')
15
+ @ff = config.dig('pipelines')
16
+ @errors = []
17
+ end
18
+
19
+ def kick_off(pipeline_id)
20
+ @pipeline = @pipelines.find { |pipeline| pipeline.dig('pipeline', 'id') == pipeline_id }
21
+ run_tasks
22
+ if @errors.count.zero?
23
+ run_on_success
24
+ else
25
+ run_on_error
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def run_on_error
32
+ @pipeline.dig('pipeline','on-error', 'tasks').each_with_index do |task, index|
33
+ puts "************ ON-ERROR: Running error task: #{index+1}/#{number_of_error_tasks} #{task.dig('task', 'name')} ************"
34
+ begin
35
+ output = system task.dig('task', 'command')
36
+ rescue SystemCallError
37
+ puts output
38
+ exit 255
39
+ end
40
+ end
41
+ end
42
+
43
+ def run_on_success
44
+ @pipeline.dig('pipeline','on-success', 'tasks').each_with_index do |task, index|
45
+ puts "************ ON-SUCCESS: Running success task: #{index+1}/#{number_of_success_tasks} #{task.dig('task', 'name')} ************"
46
+ begin
47
+ output = system task.dig('task', 'command')
48
+ rescue SystemCallError
49
+ puts output
50
+ exit 255
51
+ end
52
+ end
53
+ end
54
+
55
+ def number_of_tasks
56
+ @pipeline.dig('pipeline','tasks').count || 'ERROR'
57
+ end
58
+
59
+ def number_of_success_tasks
60
+ @pipeline.dig('pipeline','on-success', 'tasks').count || 'ERROR'
61
+ end
62
+
63
+ def number_of_error_tasks
64
+ @pipeline.dig('pipeline','on-error', 'tasks').count || 'ERROR'
65
+ end
66
+
67
+ def run_tasks
68
+ @pipeline.dig('pipeline','tasks').each_with_index do |task, index|
69
+ puts "************ INFO: Running task: #{index+1}/#{number_of_tasks} #{task.dig('task', 'name')} ************"
70
+ begin
71
+ output = system task.dig('task', 'command')
72
+ rescue SystemCallError
73
+ @errors << output
74
+ exit 255 if pipeline.dig('pipeline','fail-fast') == 'true'
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
data/lib/ski.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'no_ski_project_error'
2
+ require_relative 'project'
3
+ require 'yaml'
4
+ require 'byebug'
5
+
6
+ module Ski
7
+ class Ski
8
+ def initialize(project, pipeline)
9
+ raise NoSkiProjectError unless Dir.exists?('.ski')
10
+ @project = Project.new(YAML.load_file(".ski/#{project}.yml"))
11
+ @project.kick_off(pipeline)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Ski
2
+ module Networking
3
+
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ski
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Hanft
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automation framework
14
+ email: niklas.hanft@outlook.com
15
+ executables:
16
+ - ski
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - LICENSE
22
+ - README.md
23
+ - bin/ski
24
+ - lib/missing_attribute_error.rb
25
+ - lib/no_ski_project_error.rb
26
+ - lib/project.rb
27
+ - lib/ski.rb
28
+ - modules/networking.rb
29
+ homepage: https://github.com/ParadoXxGER/ski
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.0.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.14
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Automation framework
53
+ test_files: []