mdt-versioned 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 +7 -0
- data/README.md +61 -0
- data/lib/mdt-versioned.rb +3 -0
- data/lib/mdt/commands.rb +1 -0
- data/lib/mdt/commands/versioned.rb +74 -0
- data/lib/mdt/directory_choosers.rb +1 -0
- data/lib/mdt/directory_choosers/versioned.rb +108 -0
- data/lib/mdt/version.rb +8 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ad286f3fdb69b008ee34d111a797e611877aed3b1fda91e4402166e2536eaec
|
4
|
+
data.tar.gz: 24cab94d2d7fc333653567ecb4e055187ee5f34b0312f31bc083b234d7fae297
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4e95336d3bfdcf072cc26c310914f2410741de799213805535db58158c08c981130be849b317bfbe3630d9481ebe6896e40dff0aa5921af1c1a3fbcfb5d5884
|
7
|
+
data.tar.gz: d5e837e3a0ee7e94d883410149d7b4a477d349312c9cc42e807bad0bd15117b75fe5d66b8bbb72300c37371ea9e04208800ed97a5854ff8a92447051eca02546
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# MDT - Versioned module
|
2
|
+
|
3
|
+
A module that implements versioned releases deployment flow for MDT.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* [mdt-core](https://github.com/Phitherek/mdt-core "mdt-core") >= 0.1.0
|
8
|
+
* Ruby (tested with 2.5.0, earlier versions down to 2.0 may also work)
|
9
|
+
* RubyGems
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
`gem install mdt-versioned`
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
The module is automatically loaded by `mdt`. All you need to do is to use appropriate keys in your `mdt-deploy.yml`.
|
18
|
+
|
19
|
+
## Objects defined by module
|
20
|
+
|
21
|
+
NOTE: All of the options are optional unless indicated otherwise.
|
22
|
+
|
23
|
+
### Commands
|
24
|
+
|
25
|
+
* `versioned.link_current` - creates a symlink to the current release version.
|
26
|
+
Options:
|
27
|
+
* `current_name` - name of the link to the current release version, "current" by default.
|
28
|
+
* `versioned.link_shared` - creates symlinks to the contents of the shared directory inside the current release directory.
|
29
|
+
Options:
|
30
|
+
* `shared_name` - name of the shared directory, "shared" by default.
|
31
|
+
* `versioned.cleanup` - deletes old releases. Options:
|
32
|
+
* `retained_versions_count` - number of releases to retain including current release, 2 by default.
|
33
|
+
|
34
|
+
### Directory choosers
|
35
|
+
|
36
|
+
* `versioned.integer` - uses versioned subdirectories based on increasing integer (1, 2, etc.). Creates and changes to the directory. Removes the directory on failure.
|
37
|
+
Options:
|
38
|
+
* `path` - path of the base deployment directory. Required.
|
39
|
+
* `releases_dirname` - name of the directory that contains versioned release directories, "releases" by default.
|
40
|
+
* `versioned.timestamp` - uses versioned subdirectories based on the formatted date and time. Creates and changes to the directory. Removes the directory on failure.
|
41
|
+
Options:
|
42
|
+
* `path` - path of the base deployment directory. Required.
|
43
|
+
* `releases_dirname` - name of the directory that contains versioned release directories, "releases" by default.
|
44
|
+
* `timestamp_format` - format of the timestamp as required by Ruby Time.strftime method, "%Y%m%d%H%M%S" by default.
|
45
|
+
|
46
|
+
Both of the directory choosers set the following data in the MDT::DataStorage object:
|
47
|
+
* `versioned_base_path` - path of the base deployment directory.
|
48
|
+
* `versioned_version_id` - current version identifier.
|
49
|
+
* `versioned_releases_dirname` - name of the directory that contains versioned release directories.
|
50
|
+
|
51
|
+
## Data storage notice
|
52
|
+
|
53
|
+
All of the data in the MDT::DataStorage object set by the directory choosers has to be set for this module's commands to work properly.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
You can contribute to the development of this MDT module by submitting an issue or pull request.
|
58
|
+
|
59
|
+
## Documentation
|
60
|
+
|
61
|
+
Generated RDoc documentation can be found [here](https://rubydoc.info/github/Phitherek/mdt-versioned "here").
|
data/lib/mdt/commands.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'commands/versioned'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'mdt-core'
|
2
|
+
require 'fileutils'
|
3
|
+
module MDT
|
4
|
+
# A module containing all commands
|
5
|
+
module Commands
|
6
|
+
# A class that implements commands for versioned releases flow
|
7
|
+
class Versioned < MDT::Commands::Base
|
8
|
+
# A method that defines a key for commands class.
|
9
|
+
# Returns:
|
10
|
+
# * "versioned"
|
11
|
+
def self.key
|
12
|
+
'versioned'
|
13
|
+
end
|
14
|
+
|
15
|
+
# A method that defines keys for available commands.
|
16
|
+
# Returns:
|
17
|
+
# * +["link_current", "link_shared", "cleanup"]+
|
18
|
+
def self.subkeys
|
19
|
+
['link_current', 'link_shared', 'cleanup']
|
20
|
+
end
|
21
|
+
|
22
|
+
# A method that defines how to execute a command and how to apply command modifiers.
|
23
|
+
# Arguments:
|
24
|
+
# * +key+ - a key identifier of a particular command
|
25
|
+
# * +modifiers+ - an array of command modifier configurations - each configuration is a Hash that includes modifier type and modifier options
|
26
|
+
# * +options+ - options for command as a Hash
|
27
|
+
# Returns:
|
28
|
+
# * Exit code of command +key+
|
29
|
+
# More information:
|
30
|
+
# * See README.md for detailed description of commands
|
31
|
+
def execute(key, modifiers = [], options = {})
|
32
|
+
case key
|
33
|
+
when 'link_current'
|
34
|
+
begin
|
35
|
+
options['current_name'] ||= 'current'
|
36
|
+
puts "Creating a symlink to: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id} named: #{MDT::DataStorage.instance.versioned_base_path}/#{options['current_name']}"
|
37
|
+
FileUtils.rm_f(Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{options['current_name']}"])
|
38
|
+
FileUtils.ln_s(Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"].first, "#{MDT::DataStorage.instance.versioned_base_path}/#{options['current_name']}")
|
39
|
+
0
|
40
|
+
rescue
|
41
|
+
1
|
42
|
+
end
|
43
|
+
when 'link_shared'
|
44
|
+
begin
|
45
|
+
options['shared_name'] ||= 'shared'
|
46
|
+
puts "Creating symlinks to: #{MDT::DataStorage.instance.versioned_base_path}/#{options['shared_name']}/* at: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"
|
47
|
+
FileUtils.ln_s(Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{options['shared_name']}/*"], Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"].first)
|
48
|
+
0
|
49
|
+
rescue
|
50
|
+
1
|
51
|
+
end
|
52
|
+
when 'cleanup'
|
53
|
+
options['retained_versions_count'] ||= 2
|
54
|
+
begin
|
55
|
+
puts 'Cleaning up old releases...'
|
56
|
+
versions = []
|
57
|
+
Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/*"].each do |vn|
|
58
|
+
versions << vn.split('/').last
|
59
|
+
end
|
60
|
+
versions.sort!
|
61
|
+
if versions.count > options['retained_versions_count']
|
62
|
+
versions.first(versions.count-options['retained_versions_count']).each do |v|
|
63
|
+
FileUtils.rm_rf("#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{v}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
0
|
67
|
+
rescue
|
68
|
+
1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'directory_choosers/versioned'
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'mdt-core'
|
2
|
+
require 'fileutils'
|
3
|
+
module MDT
|
4
|
+
# A module containing all directory choosers
|
5
|
+
module DirectoryChoosers
|
6
|
+
# A class that implements directory choosers for versioned releases flow
|
7
|
+
class Versioned < MDT::DirectoryChoosers::Base
|
8
|
+
# A method that defines a key for command modifiers class.
|
9
|
+
# Returns:
|
10
|
+
# * "versioned"
|
11
|
+
def self.key
|
12
|
+
'versioned'
|
13
|
+
end
|
14
|
+
|
15
|
+
# A method that defines keys for available command modifiers.
|
16
|
+
# Returns:
|
17
|
+
# * +["timestamp", "integer"]+
|
18
|
+
def self.subkeys
|
19
|
+
['timestamp', 'integer']
|
20
|
+
end
|
21
|
+
|
22
|
+
# A method that defines how to create a deploy directory with directory choosers.
|
23
|
+
# Arguments:
|
24
|
+
# * +key+ - a key identifier of a particular directory chooser
|
25
|
+
# * +options+ - options for directory chooser as a Hash
|
26
|
+
# Returns:
|
27
|
+
# * Exit code for directory chooser +key+
|
28
|
+
# More information:
|
29
|
+
# * See README.md for detailed description of directory choosers
|
30
|
+
def mkdir(key, options = {})
|
31
|
+
return 1 unless options['path']
|
32
|
+
options['releases_dirname'] ||= 'releases'
|
33
|
+
case key
|
34
|
+
when 'timestamp'
|
35
|
+
begin
|
36
|
+
options['timestamp_format'] ||= '%Y%m%d%H%M%S'
|
37
|
+
MDT::DataStorage.instance.versioned_base_path = options['path']
|
38
|
+
MDT::DataStorage.instance.versioned_version_id = Time.now.strftime(options['timestamp_format'])
|
39
|
+
MDT::DataStorage.instance.versioned_releases_dirname = options['releases_dirname']
|
40
|
+
puts "Creating directory: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"
|
41
|
+
FileUtils.mkdir_p("#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}")
|
42
|
+
0
|
43
|
+
rescue => e
|
44
|
+
1
|
45
|
+
end
|
46
|
+
when 'integer'
|
47
|
+
begin
|
48
|
+
if Dir.exist?("#{options['path']}/#{options['releases_dirname']}")
|
49
|
+
previous_versions = []
|
50
|
+
Dir["#{options['path']}/#{options['releases_dirname']}/*"].each do |vd|
|
51
|
+
previous_versions << vd.split('/').last
|
52
|
+
end
|
53
|
+
previous_versions.sort!
|
54
|
+
MDT::DataStorage.instance.versioned_version_id = (previous_versions.last.to_i + 1).to_s
|
55
|
+
else
|
56
|
+
MDT::DataStorage.instance.versioned_version_id = 1.to_s
|
57
|
+
end
|
58
|
+
MDT::DataStorage.instance.versioned_base_path = options['path']
|
59
|
+
MDT::DataStorage.instance.versioned_releases_dirname = options['releases_dirname']
|
60
|
+
puts "Creating directory: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"
|
61
|
+
FileUtils.mkdir_p("#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}")
|
62
|
+
0
|
63
|
+
rescue => e
|
64
|
+
1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# A method that defines how to change working directory to a deploy directory with directory choosers.
|
70
|
+
# Arguments:
|
71
|
+
# * +key+ - a key identifier of a particular directory chooser
|
72
|
+
# * +options+ - options for directory chooser as a Hash
|
73
|
+
# Returns:
|
74
|
+
# * Exit code for directory chooser +key+
|
75
|
+
# More information:
|
76
|
+
# * See README.md for detailed description of directory choosers
|
77
|
+
def cd(key, options = {})
|
78
|
+
return 1 unless self.class.subkeys.include?(key)
|
79
|
+
begin
|
80
|
+
puts "Changing working directory to: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"
|
81
|
+
FileUtils.cd(Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"].first)
|
82
|
+
0
|
83
|
+
rescue
|
84
|
+
1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# A method that defines how to remove a deploy directory with directory choosers.
|
89
|
+
# Arguments:
|
90
|
+
# * +key+ - a key identifier of a particular directory chooser
|
91
|
+
# * +options+ - options for directory chooser as a Hash
|
92
|
+
# Returns:
|
93
|
+
# * Exit code for directory chooser +key+
|
94
|
+
# More information:
|
95
|
+
# * See README.md for detailed description of directory choosers
|
96
|
+
def rm(key, options = {})
|
97
|
+
return 1 unless self.class.subkeys.include?(key)
|
98
|
+
begin
|
99
|
+
puts "Removing directory: #{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"
|
100
|
+
FileUtils.rm_rf(Dir["#{MDT::DataStorage.instance.versioned_base_path}/#{MDT::DataStorage.instance.versioned_releases_dirname}/#{MDT::DataStorage.instance.versioned_version_id}"].first)
|
101
|
+
0
|
102
|
+
rescue
|
103
|
+
1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/mdt/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mdt-versioned
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phitherek_
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mdt-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.7'
|
41
|
+
description: A module that implements versioned releases deployment for MDT
|
42
|
+
email:
|
43
|
+
- phitherek@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- README.md
|
50
|
+
- lib/mdt-versioned.rb
|
51
|
+
- lib/mdt/commands.rb
|
52
|
+
- lib/mdt/commands/versioned.rb
|
53
|
+
- lib/mdt/directory_choosers.rb
|
54
|
+
- lib/mdt/directory_choosers/versioned.rb
|
55
|
+
- lib/mdt/version.rb
|
56
|
+
homepage: https://github.com/Phitherek/mdt-versioned
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
documentation_uri: http://www.rubydoc.info/github/Phitherek/mdt-versioned
|
61
|
+
source_code_uri: https://github.com/Phitherek/mdt-versioned
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- "--title"
|
65
|
+
- MDT Simple module
|
66
|
+
- "--main"
|
67
|
+
- README.md
|
68
|
+
- "--line-numbers"
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.7.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: MDT Versioned module
|
87
|
+
test_files: []
|