mdt-core 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 +4 -4
- data/MODULE_GUIDELINES.md +65 -0
- data/README.md +44 -0
- data/lib/mdt/command_modifiers/base.rb +7 -0
- data/lib/mdt/commands/base.rb +7 -0
- data/lib/mdt/directory_choosers/base.rb +14 -0
- data/lib/mdt/errors/override_needed.rb +5 -0
- data/lib/mdt/fetchers/base.rb +6 -0
- data/lib/mdt/helpers/command.rb +8 -0
- data/lib/mdt/helpers/runner.rb +7 -0
- data/lib/mdt/modules/extensible.rb +11 -0
- data/lib/mdt/version.rb +4 -1
- metadata +16 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f5302dd44719fbcd4484a84a8438421edd7b85532663df5ce94ac00ba4a3c93
|
4
|
+
data.tar.gz: 60de727f66d701fb2db324f943a07f80eb4e5d069277804c8565fbb4ff7c0834
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6c396dcb98ab54208fdbec4791aa0c82a633b0ea1d8ce954d1438196f7bf199c5a94425cebc72b115d5a47dbc8a80bbad4451b3e1eb5e8063bf244eca300eb
|
7
|
+
data.tar.gz: c65921bdc2bf5dd9ef37b244aaaa505ecf3e72ce3c0b6600f4154210458541253843223cb7fc815b81f964acd385e121aceec3edbdea1b2f06d818f56b354811
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Module creation guidelines
|
2
|
+
|
3
|
+
There are a few things to take into account when creating a MDT module. This document is an attempt to summarize them.
|
4
|
+
|
5
|
+
## Gem naming convention
|
6
|
+
|
7
|
+
Because of the way MDT handles autoloading gems, you should always use `mdt-<something>` as a name of the gem. Otherwise the autoloading process will not include them and that may cause problems with the users of your module.
|
8
|
+
|
9
|
+
## Gem structure
|
10
|
+
|
11
|
+
An MDT module gem should have the following structure:
|
12
|
+
|
13
|
+
```
|
14
|
+
-- Gemfile
|
15
|
+
-- Gemfile.lock
|
16
|
+
-- mdt-<something>.gemspec
|
17
|
+
-- .gitignore
|
18
|
+
-- LICENSE
|
19
|
+
-- README.md
|
20
|
+
-- lib
|
21
|
+
|
|
22
|
+
-- mdt-<something>.rb
|
23
|
+
-- mdt
|
24
|
+
|
|
25
|
+
-- version.rb
|
26
|
+
-- fetchers.rb
|
27
|
+
-- directory_choosers.rb
|
28
|
+
-- commands.rb
|
29
|
+
-- command_modifiers.rb
|
30
|
+
-- fetchers
|
31
|
+
|
|
32
|
+
<fetchers_key>.rb
|
33
|
+
...
|
34
|
+
-- directory_choosers
|
35
|
+
|
|
36
|
+
<directory_choosers_key>.rb
|
37
|
+
...
|
38
|
+
-- commands
|
39
|
+
|
|
40
|
+
<commands_key>.rb
|
41
|
+
...
|
42
|
+
-- command_modifiers
|
43
|
+
|
|
44
|
+
<command_modifiers_key>.rb
|
45
|
+
...
|
46
|
+
-- spec
|
47
|
+
```
|
48
|
+
|
49
|
+
The most important thing to remember is that the top file in lib should be named exactly as a gem because of the MDT autoloading process. The rest is just an example, if your module does not define a subclass for a particular object type then it is not required.
|
50
|
+
|
51
|
+
## Module separation convention
|
52
|
+
|
53
|
+
A module can include commands for a programming language and its standard tooling or custom tools. It can also define a flow using directory choosers and/or fetchers. A decision whether or not to separate the objects to a separate module or to keep them together in one should take these points into account:
|
54
|
+
|
55
|
+
* When making a module for a programming language it should refer only to the standard tools included with the language. Any additional tools should be separated to their own modules.
|
56
|
+
|
57
|
+
* When making a module that includes a way to fetch a code with a particular tool or to choose a deploy directory with the use of a particular tool or flow, it should also include commands and command modifiers related to the tool or flow. When making a module that uses a tool to define commands or command modifiers, it should also include fetchers or directory choosers if it can be used to define a deploy flow. A module for a particular tool or flow should be single and as complete as possible.
|
58
|
+
|
59
|
+
## Module distribution
|
60
|
+
|
61
|
+
MDT modules that meet these guidelines should be distributed as gems, preferrably through the official RubyGems service.
|
62
|
+
|
63
|
+
## Testing and documentation
|
64
|
+
|
65
|
+
Modules should be tested and documented as good as possible.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# MDT - Modular Deployment Tool (Core)
|
2
|
+
|
3
|
+
MDT is a deployment automation tool that is designed to be simple and easily extended by additional modules. It is written in Ruby and takes advantage of Ruby tools, but it can be used to deploy almost anything if there is a module for it.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* Ruby (tested with 2.5.0, earlier versions down to 2.0 may also work)
|
8
|
+
* RubyGems
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
`gem install mdt-core`
|
13
|
+
|
14
|
+
Be sure to also install any modules that you need.
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
The gem installs an executable called `mdt` that is used in a way described below:
|
19
|
+
|
20
|
+
`mdt [options] <config_key>`
|
21
|
+
|
22
|
+
By default it searches for the deployment configuration in `config/mdt-deploy.yml`. Options can be any of: `-c CONFIG_FILE_PATH`, `--config CONFIG_FILE_PATH`, `-h`, `--help`. `config_key` is required.
|
23
|
+
|
24
|
+
## Deployment configuration file
|
25
|
+
|
26
|
+
See `config/mdt-deploy.yml.example` for example deployment configuration file with comments.
|
27
|
+
|
28
|
+
## The concept
|
29
|
+
|
30
|
+
MDT defines 5 modular objects that can be used to build a simple deploy flow. These objects are:
|
31
|
+
|
32
|
+
* Directory choosers - each of them defines how a deploy directory should be created, set as a working directory and, if necessary, removed on deploy failure.
|
33
|
+
* Fetchers - each of them defines how the project contents should be fetched into the deploy directory.
|
34
|
+
* Commands - each of them represents a single command executed in the deploy.
|
35
|
+
* Command modifiers - each of them represents an expression that can be prepended to the command (like e.g. `bundle exec` from Ruby Bundler or environment variables). The way they are prepended is ultimately decided by the specific command.
|
36
|
+
* Command groups - these are present only in the configuration and can be used to group together a set of other commands and command groups, describe it and add common parameters like command modifiers or make the whole group not fail the deploy.
|
37
|
+
|
38
|
+
## Known modules
|
39
|
+
|
40
|
+
* [mdt-dummy](https://github.com/Phitherek/mdt-dummy "mdt-dummy") - a module containing dummy implementations of each extensible MDT class. They can be used to skip a particular deployment step.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
You can contribute to the development of MDT by submitting an issue or pull request. You can also extend MDT's capabilities by creating your own module in accordance with guidelines in MODULE_GUIDELINES.md and submitting it to RubyGems.
|
@@ -2,10 +2,17 @@ require_relative '../errors/override_needed'
|
|
2
2
|
require_relative '../modules/extensible'
|
3
3
|
|
4
4
|
module MDT
|
5
|
+
# A module containing all command modifiers
|
5
6
|
module CommandModifiers
|
7
|
+
# A base class for command modifiers
|
6
8
|
class Base
|
7
9
|
include MDT::Extensible
|
8
10
|
|
11
|
+
# A method that defines how to prepend command modifiers to commands. Raises MDT::Errors::OverrideNeeded.
|
12
|
+
# Arguments:
|
13
|
+
# * +key+ - a key identifier of a particular command modifier
|
14
|
+
# * +command+ - a command to apply command modifier on
|
15
|
+
# * +options+ - options for modifier as a Hash
|
9
16
|
def prepend(key, command, options = {})
|
10
17
|
raise MDT::Errors::OverrideNeeded.new('prepend')
|
11
18
|
end
|
data/lib/mdt/commands/base.rb
CHANGED
@@ -2,10 +2,17 @@ require_relative '../errors/override_needed'
|
|
2
2
|
require_relative '../modules/extensible'
|
3
3
|
|
4
4
|
module MDT
|
5
|
+
# A module containing all commands
|
5
6
|
module Commands
|
7
|
+
# A base class for commands
|
6
8
|
class Base
|
7
9
|
include MDT::Extensible
|
8
10
|
|
11
|
+
# A method that defines how to execute a command and how to apply command modifiers. Raises MDT::Errors::OverrideNeeded.
|
12
|
+
# Arguments:
|
13
|
+
# +key+ - a key identifier of a particular command
|
14
|
+
# +modifiers+ - an array of command modifier configurations - each configuration is a Hash that includes modifier type and modifier options
|
15
|
+
# +options+ - options for command as a Hash
|
9
16
|
def execute(key, modifiers = [], options = {})
|
10
17
|
raise MDT::Errors::OverrideNeeded.new('execute')
|
11
18
|
end
|
@@ -3,18 +3,32 @@ require_relative '../errors/override_needed'
|
|
3
3
|
require_relative '../modules/extensible'
|
4
4
|
|
5
5
|
module MDT
|
6
|
+
# A module containing all directory choosers
|
6
7
|
module DirectoryChoosers
|
8
|
+
# A base class for directory choosers
|
7
9
|
class Base
|
8
10
|
include MDT::Extensible
|
9
11
|
|
12
|
+
# A method that defines how to create a deploy directory with directory choosers. Raises MDT::Errors::OverrideNeeded.
|
13
|
+
# Arguments:
|
14
|
+
# * +key+ - a key identifier of a particular directory chooser
|
15
|
+
# * +options+ - options for directory chooser as a Hash
|
10
16
|
def mkdir(key, options = {})
|
11
17
|
raise MDT::Errors::OverrideNeeded.new('mkdir')
|
12
18
|
end
|
13
19
|
|
20
|
+
# A method that defines how to change the working directory to a deploy directory with directory choosers. Raises MDT::Errors::OverrideNeeded.
|
21
|
+
# Arguments:
|
22
|
+
# * +key+ - a key identifier of a particular directory chooser
|
23
|
+
# * +options+ - options for directory chooser as a Hash
|
14
24
|
def cd(key, options = {})
|
15
25
|
raise MDT::Errors::OverrideNeeded.new('cd')
|
16
26
|
end
|
17
27
|
|
28
|
+
# A method that defines how to remove a deploy directory with directory choosers. Raises MDT::Errors::OverrideNeeded.
|
29
|
+
# Arguments:
|
30
|
+
# * +key+ - a key identifier of a particular directory chooser
|
31
|
+
# * +options+ - options for directory chooser as a Hash
|
18
32
|
def rm(key, options = {})
|
19
33
|
raise MDT::Errors::OverrideNeeded.new('rm')
|
20
34
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module MDT
|
2
|
+
# A module containing all MDT errors
|
2
3
|
module Errors
|
4
|
+
# An error thrown when a method in a base class needs to be overriden in a subclass.
|
3
5
|
class OverrideNeeded < StandardError
|
6
|
+
# Initializes the error with the method key to be shown in error message.
|
7
|
+
# Arguments:
|
8
|
+
# * +method_key+ - the key of the method that needs to be overriden
|
4
9
|
def initialize(method_key)
|
5
10
|
super("Method #{method_key} must be overriden in a subclass!")
|
6
11
|
end
|
data/lib/mdt/fetchers/base.rb
CHANGED
@@ -2,10 +2,16 @@ require_relative '../errors/override_needed'
|
|
2
2
|
require_relative '../modules/extensible'
|
3
3
|
|
4
4
|
module MDT
|
5
|
+
# A module containing all fetchers
|
5
6
|
module Fetchers
|
7
|
+
# A base class for fetchers
|
6
8
|
class Base
|
7
9
|
include MDT::Extensible
|
8
10
|
|
11
|
+
# A method that defines how to fetch project contents to a deploy directory with fetchers. Raises MDT::Errors::OverrideNeeded.
|
12
|
+
# Arguments:
|
13
|
+
# * +key+ - a key identifier of a particular fetcher
|
14
|
+
# * +options+ - options for fetchers as a Hash
|
9
15
|
def fetch(key, options ={})
|
10
16
|
raise MDT::Errors::OverrideNeeded.new('fetch')
|
11
17
|
end
|
data/lib/mdt/helpers/command.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
require_relative '../command_modifiers'
|
2
2
|
module MDT
|
3
|
+
# A module containing all helper classes
|
3
4
|
module Helpers
|
5
|
+
# A helper class to be used when implementing commands
|
4
6
|
class Command
|
7
|
+
# Finds and applies command modifiers to a command using passed modifiers configuration.
|
8
|
+
# Arguments:
|
9
|
+
# * +command+ - a command or expression to prepend command modifiers to
|
10
|
+
# * +modifiers+ - an array of modifier configurations - each configuration is a Hash that includes the modifier type and modifier options
|
11
|
+
# Returns:
|
12
|
+
# * Modified command
|
5
13
|
def self.apply_command_modifiers(command, modifiers)
|
6
14
|
modifiers.each do |modifier_config|
|
7
15
|
unless modifier_config.has_key?('type')
|
data/lib/mdt/helpers/runner.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
require_relative '../commands'
|
2
2
|
module MDT
|
3
3
|
module Helpers
|
4
|
+
# A helper class used in the MDT executable
|
4
5
|
class Runner
|
6
|
+
# A method that processes an array of contents that includes configurations for commands and command groups.
|
7
|
+
# Arguments:
|
8
|
+
# +contents+ - an array of configurations for commands and command groups. Refer to example configuration file in the code repository for structure description
|
9
|
+
# +modifiers+ - an array of configurations for command modifiers that have to be applied to every command defined in +contents+
|
10
|
+
# Returns:
|
11
|
+
# * 1 on failure, otherwise 0
|
5
12
|
def self.process_contents(contents, modifiers = [])
|
6
13
|
failure = false
|
7
14
|
contents.each do |elem|
|
@@ -1,21 +1,32 @@
|
|
1
1
|
module MDT
|
2
|
+
# A module to make the class a MDT base class
|
2
3
|
module Extensible
|
4
|
+
# Adds needed class methods when included in a class.
|
5
|
+
# Arguments:
|
6
|
+
# * +klass+ - the class a module is being included in
|
3
7
|
def self.included(klass)
|
4
8
|
klass.class_eval do
|
9
|
+
# Stores the descendant classes.
|
5
10
|
@descendants = []
|
11
|
+
# Defines a key that a subclass can be found by. Raises MDT::Errors::OverrideNeeded.
|
6
12
|
def self.key
|
7
13
|
raise MDT::Errors::OverrideNeeded.new('key')
|
8
14
|
end
|
9
15
|
|
16
|
+
# Defines a set of subkeys that can be passed to class methods. Raises MDT::Errors::OverrideNeeded.
|
10
17
|
def self.subkeys
|
11
18
|
raise MDT::Errors::OverrideNeeded.new('subkeys')
|
12
19
|
end
|
13
20
|
|
21
|
+
# Adds a subclass to the descendants variable when it is inherited and makes the list unique.
|
22
|
+
# Arguments
|
23
|
+
# * +subclass+ - a subclass that the class is inherited by.
|
14
24
|
def self.inherited(subclass)
|
15
25
|
@descendants << subclass
|
16
26
|
@descendants.uniq!
|
17
27
|
end
|
18
28
|
|
29
|
+
# Exposes descendants variable.
|
19
30
|
def self.descendants
|
20
31
|
@descendants
|
21
32
|
end
|
data/lib/mdt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdt-core
|
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
|
- Phitherek_
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,8 +30,12 @@ email:
|
|
30
30
|
executables:
|
31
31
|
- mdt
|
32
32
|
extensions: []
|
33
|
-
extra_rdoc_files:
|
33
|
+
extra_rdoc_files:
|
34
|
+
- README.md
|
35
|
+
- MODULE_GUIDELINES.md
|
34
36
|
files:
|
37
|
+
- MODULE_GUIDELINES.md
|
38
|
+
- README.md
|
35
39
|
- bin/mdt
|
36
40
|
- lib/mdt-core.rb
|
37
41
|
- lib/mdt/command_modifiers.rb
|
@@ -52,9 +56,16 @@ files:
|
|
52
56
|
homepage: https://github.com/Phitherek/mdt-core
|
53
57
|
licenses:
|
54
58
|
- MIT
|
55
|
-
metadata:
|
59
|
+
metadata:
|
60
|
+
documentation_uri: http://www.rubydoc.info/github/Phitherek/mdt-core
|
61
|
+
source_code_uri: https://github.com/Phitherek/mdt-core
|
56
62
|
post_install_message:
|
57
|
-
rdoc_options:
|
63
|
+
rdoc_options:
|
64
|
+
- "--title"
|
65
|
+
- MDT Core
|
66
|
+
- "--main"
|
67
|
+
- README.md
|
68
|
+
- "--line-numbers"
|
58
69
|
require_paths:
|
59
70
|
- lib
|
60
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|