r10k 1.2.4 → 1.3.0rc1
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 +8 -8
- data/{CHANGELOG → CHANGELOG.mkd} +51 -41
- data/doc/dynamic-environments/configuration.mkd +1 -1
- data/doc/dynamic-environments/git-environments.markdown +19 -0
- data/doc/dynamic-environments/usage.mkd +6 -0
- data/lib/r10k/cli/deploy.rb +15 -0
- data/lib/r10k/cli/ext/logging.rb +0 -1
- data/lib/r10k/cli/module/deploy.rb +0 -1
- data/lib/r10k/cli/puppetfile.rb +2 -2
- data/lib/r10k/cli.rb +2 -16
- data/lib/r10k/deployment/environment.rb +9 -79
- data/lib/r10k/deployment/source.rb +15 -89
- data/lib/r10k/deployment.rb +13 -14
- data/lib/r10k/environment/base.rb +42 -0
- data/lib/r10k/environment/git.rb +79 -0
- data/lib/r10k/environment/svn.rb +73 -0
- data/lib/r10k/environment.rb +7 -0
- data/lib/r10k/execution.rb +0 -1
- data/lib/r10k/git/cache.rb +11 -5
- data/lib/r10k/git/repository.rb +1 -8
- data/lib/r10k/git/working_dir.rb +11 -34
- data/lib/r10k/git.rb +0 -1
- data/lib/r10k/instance_cache.rb +32 -0
- data/lib/r10k/keyed_factory.rb +39 -0
- data/lib/r10k/module/forge.rb +2 -3
- data/lib/r10k/module/svn.rb +0 -1
- data/lib/r10k/puppetfile.rb +0 -1
- data/lib/r10k/registry.rb +3 -31
- data/lib/r10k/source/base.rb +60 -0
- data/lib/r10k/source/git.rb +195 -0
- data/lib/r10k/source/svn.rb +140 -0
- data/lib/r10k/source.rb +39 -0
- data/lib/r10k/svn/remote.rb +48 -0
- data/lib/r10k/svn/working_dir.rb +0 -2
- data/lib/r10k/svn.rb +6 -0
- data/lib/r10k/task/deployment.rb +1 -2
- data/lib/r10k/task.rb +0 -2
- data/lib/r10k/task_runner.rb +0 -1
- data/lib/r10k/util/core_ext/hash_ext.rb +19 -0
- data/lib/r10k/util/subprocess.rb +0 -1
- data/lib/r10k/version.rb +1 -1
- data/lib/r10k.rb +1 -0
- data/spec/unit/deployment/environment_spec.rb +16 -15
- data/spec/unit/environment/git_spec.rb +81 -0
- data/spec/unit/environment/svn_spec.rb +76 -0
- data/spec/unit/git/repository_spec.rb +0 -10
- data/spec/unit/git/working_dir_spec.rb +1 -110
- data/spec/unit/{registry_spec.rb → instance_cache_spec.rb} +3 -3
- data/spec/unit/keyed_factory_spec.rb +51 -0
- data/spec/unit/source/git_spec.rb +274 -0
- data/spec/unit/source/svn_spec.rb +102 -0
- data/spec/unit/source_spec.rb +10 -0
- data/spec/unit/svn/remote_spec.rb +21 -0
- data/spec/unit/util/core_ext/hash_ext_spec.rb +63 -0
- metadata +36 -10
- data/lib/r10k/git/alternates.rb +0 -49
- data/spec/unit/git/alternates_spec.rb +0 -90
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Mjc5ZmQ5NWQxMmU5NDAwOWE2MzhmNTZhZTE4MDllYjNjNDAzMTA3YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzA1MmNiMWUxZDI2YzcyMWZiNWQ0NzQ4NjNiNWEzMzBkNDFkMmQwZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2RlZWUzZGM5M2ZiNjQ3ZTQ5ZTlhMThkZTkxM2M1NTk3YmIxNzBiZGQ3YWQx
|
10
|
+
MWQ1NmNkNjVjOGI2NDE4NzEzYTAwZTFmNWQzZmM4OTlhOTY5YjdhNGMzNzg0
|
11
|
+
NzU2NTFkYzAwODUzZjMyZWZmMmQ5ZjIyODRlMzQ2ZmYyNWY2OGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGEyNTFhYzNiY2YxZDIzNGExNmVlNjEyMTgwYWUzN2NiZDMwMDM0ZjhjMWY4
|
14
|
+
ZjFhM2MxYmUxYWIyYjQ4ZTdlMGY3MDU5NGI4OTdmYjM1MGE2MTBiZjUwM2Nj
|
15
|
+
MTc4NDIwNjJiYmI4MjI5N2ZjZDI5MjY1MjM3ODY1YzRlNTZlYzQ=
|
data/{CHANGELOG → CHANGELOG.mkd}
RENAMED
@@ -1,58 +1,68 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
-
1.
|
5
|
-
|
6
|
-
|
7
|
-
2014/09/14
|
8
|
-
|
9
|
-
### User Notes
|
10
|
-
|
11
|
-
(GH-188) Call puppet module tool install with --force for downgrades
|
12
|
-
|
13
|
-
1.2.3
|
14
|
-
-----
|
15
|
-
|
16
|
-
2014/07/27
|
17
|
-
|
18
|
-
### User Notes
|
19
|
-
|
20
|
-
(GH-173) Fixed a bug with Ruby 1.8.7 with Pathname objects.
|
21
|
-
|
22
|
-
1.2.2
|
23
|
-
-----
|
4
|
+
1.3.0rc1
|
5
|
+
--------
|
24
6
|
|
25
|
-
2014/07
|
7
|
+
2014/06/07
|
26
8
|
|
27
|
-
### User
|
9
|
+
### User notes
|
28
10
|
|
29
|
-
(GH-
|
11
|
+
#### (GH-104) SVN support for environments.
|
30
12
|
|
31
|
-
|
32
|
-
|
13
|
+
R10k can now dynamically generate enviroments based on SVN repositories. SVN
|
14
|
+
repositories must SVN repositories must conform to the conventional SVN
|
15
|
+
repository structure with the directories trunk/, branches/, and optionally
|
16
|
+
tags/ in the root of the repository. The trunk/ directory is specifically
|
17
|
+
mapped to the production environment, branches are created as environments with
|
18
|
+
the name of the given branch.
|
33
19
|
|
34
|
-
|
35
|
-
|
20
|
+
Please note that since SVN support for environments should be considered
|
21
|
+
preliminary and may still have some kinks to be worked out, so use it with
|
22
|
+
caution in production.
|
36
23
|
|
37
|
-
|
38
|
-
to the TaskRunner. This has been fixed so only known options are passed along,
|
39
|
-
and options that aren't relevant (such as :verbose) will be ignored.
|
24
|
+
#### (GH-112) Modules can be deployed in a single environment.
|
40
25
|
|
41
|
-
|
26
|
+
When deploying modules with `r10k deploy module <modules>`, users can specify
|
27
|
+
the `-e <environment>` flag to update modules in a single environment.
|
42
28
|
|
43
|
-
(GH-
|
29
|
+
#### (GH-117) Controllable behavior for invalid Git branches.
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
remotes and alternates will be updated.
|
31
|
+
Git sources can now tune how r10k behaves when it encounters a git branch with
|
32
|
+
a non-word character. Valid values are 'correct_and_warn' which emits a warning
|
33
|
+
and sanitizes the environment name, 'correct' which silently corrects the
|
34
|
+
environment, and 'error' which emits an error and ignores the environment.
|
50
35
|
|
51
|
-
|
36
|
+
### Developer notes
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
38
|
+
#### IMPORTANT: as of 1.3.0, r10k is relaxing how it implements semantic versioning.
|
39
|
+
|
40
|
+
There are a lot of internal APIs in r10k that need to be improved or
|
41
|
+
overhauled, and making changes in a backwards compatible manner has been
|
42
|
+
impeding development on a number of important features. There's no indication
|
43
|
+
that there are any consumers of the r10k internal APIs, and if that's the case
|
44
|
+
then r10k doesn't help anyone by maintaining SemVer for its internal APIs.
|
45
|
+
|
46
|
+
As of 1.3.0, r10k is dropping guarantees about API compatibility for most of
|
47
|
+
the core functionality. The `R10K::Task*` classes were designed to be the
|
48
|
+
primary interface for external use and those will remain backwards compatible
|
49
|
+
for 1.x. However any code around configuration parsing, deployments, sources,
|
50
|
+
environments, and modules may have API changes in minor versions.
|
51
|
+
|
52
|
+
That being said, if you are using any of these APIs and you experience breakage,
|
53
|
+
you're not out of luck. If an API change actually does affect you please report
|
54
|
+
it as a bug and those specific APIs can probably be fixed up. Hopefully this
|
55
|
+
will ease development of r10k while not making the lives of external developers
|
56
|
+
too painful.
|
57
|
+
|
58
|
+
#### (GH-116) Allow alternate implementations of sources and environments
|
59
|
+
|
60
|
+
This allows the groundwork for allowing users to implement plugins for sources
|
61
|
+
and environments. A real API specification for sources and environments has
|
62
|
+
been started, and sources and environments can be defined at runtime. In the
|
63
|
+
long run r10k will add a plugin system for loading additional code from
|
64
|
+
Rubygems and other sources, so r10k will be extensible without requiring
|
65
|
+
modifications to the source.
|
56
66
|
|
57
67
|
1.2.1
|
58
68
|
-----
|
@@ -32,7 +32,7 @@ cachedir: '/var/cache/r10k'
|
|
32
32
|
|
33
33
|
[prerun_command](http://docs.puppetlabs.com/references/latest/configuration.html#preruncommand)
|
34
34
|
|
35
|
-
The cachedir setting defaults to `~/.r10k
|
35
|
+
The cachedir setting defaults to `~/.r10k`. If the HOME environment variable is
|
36
36
|
unset r10k will assume that r10k is being run with the Puppet [`prerun_command`][prerun_command]
|
37
37
|
setting and will set the cachedir default to `/root/.r10k`.
|
38
38
|
|
@@ -40,3 +40,22 @@ appropriate Puppet environment to the latest version. Finally if there are
|
|
40
40
|
Puppet environments that don't have matching Git branches, r10k will assume that
|
41
41
|
the branches for those environments were deleted and will remove those
|
42
42
|
environments.
|
43
|
+
|
44
|
+
Configuration
|
45
|
+
-------------
|
46
|
+
|
47
|
+
The following configuration options can be specified for Git based environment
|
48
|
+
sources.
|
49
|
+
|
50
|
+
### invalid_branches:
|
51
|
+
|
52
|
+
This setting specifies how Git branch names that cannot be cleanly mapped to
|
53
|
+
Puppet environments will be handled.
|
54
|
+
|
55
|
+
Valid values:
|
56
|
+
|
57
|
+
* 'correct_and_warn': Non-word characters will be replaced with underscores
|
58
|
+
and a warning will be emitted. (Default)
|
59
|
+
* 'correct': Non-word characters will silently be replaced with underscores.
|
60
|
+
* 'error': Branches with non-word characters will be ignored and an error will
|
61
|
+
be emitted.
|
@@ -73,3 +73,9 @@ This is useful for when you're working on a module specified in a Puppetfile and
|
|
73
73
|
Update multiple modules across all environments
|
74
74
|
|
75
75
|
r10k deploy module apache jenkins java
|
76
|
+
|
77
|
+
- - -
|
78
|
+
|
79
|
+
Update one or more modules in a single environment
|
80
|
+
|
81
|
+
r10k deploy module -e production apache jenkins java
|
data/lib/r10k/cli/deploy.rb
CHANGED
@@ -51,6 +51,10 @@ scheduled. On subsequent deployments, Puppetfile deployment will default to off.
|
|
51
51
|
DESCRIPTION
|
52
52
|
|
53
53
|
flag :p, :puppetfile, 'Deploy modules from a puppetfile'
|
54
|
+
flag :h, :help, 'Show help for this command' do |value, cmd|
|
55
|
+
puts cmd.help
|
56
|
+
exit 0
|
57
|
+
end
|
54
58
|
|
55
59
|
run do |opts, args, cmd|
|
56
60
|
deploy = R10K::Deployment.load_config(opts[:config])
|
@@ -86,11 +90,18 @@ It will load the Puppetfile configurations out of all environments, and will
|
|
86
90
|
try to deploy the given module names in all environments.
|
87
91
|
DESCRIPTION
|
88
92
|
|
93
|
+
flag :h, :help, 'Show help for this command' do |value, cmd|
|
94
|
+
puts cmd.help
|
95
|
+
exit 0
|
96
|
+
end
|
97
|
+
required :e, :environment, 'Update the modules in the given environment'
|
98
|
+
|
89
99
|
run do |opts, args, cmd|
|
90
100
|
deploy = R10K::Deployment.load_config(opts[:config])
|
91
101
|
|
92
102
|
task = R10K::Task::Deployment::DeployModules.new(deploy)
|
93
103
|
task.module_names = args
|
104
|
+
task.environment_names = [opts[:environment]] if opts[:environment]
|
94
105
|
|
95
106
|
runner = R10K::TaskRunner.new(:trace => opts[:trace])
|
96
107
|
runner.append_task task
|
@@ -111,6 +122,10 @@ try to deploy the given module names in all environments.
|
|
111
122
|
summary 'Display environments and modules in the deployment'
|
112
123
|
|
113
124
|
flag :p, :puppetfile, 'Display Puppetfile modules'
|
125
|
+
flag :h, :help, 'Show help for this command' do |value, cmd|
|
126
|
+
puts cmd.help
|
127
|
+
exit 0
|
128
|
+
end
|
114
129
|
|
115
130
|
run do |opts, args, cmd|
|
116
131
|
deploy = R10K::Deployment.load_config(opts[:config])
|
data/lib/r10k/cli/ext/logging.rb
CHANGED
data/lib/r10k/cli/puppetfile.rb
CHANGED
@@ -37,7 +37,7 @@ Puppetfile (http://bombasticmonkey.com/librarian-puppet/).
|
|
37
37
|
|
38
38
|
puppetfile = R10K::Puppetfile.new(puppetfile_root, puppetfile_path, puppetfile)
|
39
39
|
|
40
|
-
runner = R10K::TaskRunner.new(
|
40
|
+
runner = R10K::TaskRunner.new(opts)
|
41
41
|
task = R10K::Task::Puppetfile::Sync.new(puppetfile)
|
42
42
|
runner.append_task task
|
43
43
|
|
@@ -90,7 +90,7 @@ Puppetfile (http://bombasticmonkey.com/librarian-puppet/).
|
|
90
90
|
|
91
91
|
puppetfile = R10K::Puppetfile.new(puppetfile_root, puppetfile_path, puppetfile)
|
92
92
|
|
93
|
-
runner = R10K::TaskRunner.new(
|
93
|
+
runner = R10K::TaskRunner.new(opts)
|
94
94
|
task = R10K::Task::Puppetfile::Purge.new(puppetfile)
|
95
95
|
runner.append_task task
|
96
96
|
|
data/lib/r10k/cli.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'r10k'
|
2
|
-
require 'r10k/logging'
|
3
2
|
require 'r10k/version'
|
4
3
|
require 'r10k/cli/ext/logging'
|
5
4
|
|
@@ -16,23 +15,10 @@ module R10K::CLI
|
|
16
15
|
complex environments.
|
17
16
|
EOD
|
18
17
|
|
19
|
-
|
20
|
-
flag :h, :help, 'Show help for this command' do |value, cmd|
|
21
|
-
# This is evil because we may not necessarily be called from the
|
22
|
-
# command line and have a meaningful ARGV to scan. However the best
|
23
|
-
# way of having a globally useful --help command is to define the
|
24
|
-
# behavior in the block of the option to immediately handle it and exit
|
25
|
-
# and we don't have access to the verbose option, so the simple method
|
26
|
-
# is to simply scan ARGV.
|
27
|
-
verbose = (ARGV.include?('-v') || ARGV.include?('--verbose'))
|
28
|
-
puts cmd.help(:verbose => verbose)
|
29
|
-
exit 0
|
30
|
-
end
|
31
|
-
|
18
|
+
flag :h, :help, 'Show help for this command'
|
32
19
|
flag :t, :trace, 'Display stack traces on application crash'
|
33
20
|
|
34
|
-
|
35
|
-
optional :v, :verbose, "Set log verbosity. Valid values: #{loglevels}" do |value, cmd|
|
21
|
+
optional :v, :verbose, 'Set verbosity level' do |value, cmd|
|
36
22
|
case value
|
37
23
|
when true
|
38
24
|
R10K::Logging.level = 'INFO'
|
@@ -1,90 +1,20 @@
|
|
1
|
-
require 'r10k/
|
2
|
-
require 'r10k/
|
1
|
+
require 'r10k/deployment'
|
2
|
+
require 'r10k/environment'
|
3
3
|
|
4
|
-
|
5
|
-
class Deployment
|
6
|
-
class Environment
|
7
|
-
|
8
|
-
include R10K::Logging
|
9
|
-
|
10
|
-
# @!attribute [r] ref
|
11
|
-
# The git ref to instantiate into the basedir
|
12
|
-
attr_reader :ref
|
13
|
-
|
14
|
-
# @!attribute [r] remote
|
15
|
-
# The location of the remote git repository
|
16
|
-
attr_reader :remote
|
17
|
-
|
18
|
-
# @!attribute [r] basedir
|
19
|
-
# The basedir to clone the root into
|
20
|
-
attr_reader :basedir
|
21
|
-
|
22
|
-
# @!attribute [r] dirname
|
23
|
-
# @return [String] The directory name to use for the environment
|
24
|
-
attr_reader :dirname
|
4
|
+
class R10K::Deployment::Environment
|
25
5
|
|
26
6
|
# @param [String] ref
|
27
7
|
# @param [String] remote
|
28
8
|
# @param [String] basedir
|
29
9
|
# @param [String] dirname The directory to clone the root into, defaults to ref
|
30
10
|
# @param [String] source_name An additional string which may be used with ref to build dirname
|
31
|
-
def initialize(ref, remote, basedir, dirname = nil, source_name = "")
|
32
|
-
@ref = ref
|
33
|
-
@remote = remote
|
34
|
-
@basedir = basedir
|
35
|
-
alternate_name = source_name.empty? ? ref : source_name + "_" + ref
|
36
|
-
@dirname = sanitize_dirname(dirname || alternate_name)
|
37
|
-
|
38
|
-
@working_dir = R10K::Git::WorkingDir.new(@ref, @remote, @basedir, @dirname)
|
39
|
-
|
40
|
-
@full_path = File.join(@basedir, @dirname)
|
41
|
-
end
|
42
|
-
|
43
|
-
def sync
|
44
|
-
recursive_needed = !(@working_dir.cloned?)
|
45
|
-
@working_dir.sync
|
46
|
-
|
47
|
-
if recursive_needed
|
48
|
-
logger.debug "Environment #{@full_path} is a fresh clone; automatically updating modules."
|
49
|
-
sync_modules
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def sync_modules
|
54
|
-
modules.each do |mod|
|
55
|
-
mod.sync
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def puppetfile
|
60
|
-
@puppetfile ||= R10K::Puppetfile.new(@full_path)
|
61
|
-
end
|
62
|
-
|
63
|
-
def modules
|
64
|
-
puppetfile.load
|
65
|
-
puppetfile.modules
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
# Strip out non-word characters in an environment directory name
|
71
|
-
#
|
72
|
-
# Puppet can only use word characters (letter, digit, underscore) in
|
73
|
-
# environment names; this cleans up environment names to avoid traversals
|
74
|
-
# and similar issues.
|
75
|
-
#
|
76
|
-
# @param input [String] The raw branch name
|
77
11
|
#
|
78
|
-
# @
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
logger.warn "Environment #{input.inspect} contained non-word characters; sanitizing to #{output.inspect}"
|
84
|
-
end
|
12
|
+
# @deprecated
|
13
|
+
# @return [R10K::Environment::Git]
|
14
|
+
def self.new(ref, remote, basedir, dirname = nil, source_name = "")
|
15
|
+
alternate_name = source_name.empty? ? ref : source_name + "_" + ref
|
16
|
+
dirname = dirname || alternate_name
|
85
17
|
|
86
|
-
|
18
|
+
R10K::Environment::Git.new(ref, basedir, dirname, {:remote => remote, :ref => ref})
|
87
19
|
end
|
88
20
|
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,110 +1,36 @@
|
|
1
|
-
require 'r10k/
|
2
|
-
require 'r10k/
|
3
|
-
require 'r10k/deployment/basedir'
|
4
|
-
require 'r10k/util/purgeable'
|
1
|
+
require 'r10k/source'
|
2
|
+
require 'r10k/util/core_ext/hash_ext'
|
5
3
|
|
6
4
|
module R10K
|
7
5
|
class Deployment
|
8
6
|
class Source
|
9
|
-
# Represents a git repository to map branches to environments
|
10
|
-
#
|
11
|
-
# This module is backed with a bare git cache that's used to enumerate
|
12
|
-
# branches. The cache isn't used for anything else here, but all environments
|
13
|
-
# using that remote will be able to reuse the cache.
|
14
|
-
|
15
|
-
# @!attribute [r] name
|
16
|
-
# @return [String] The short name for the deployment source
|
17
|
-
attr_reader :name
|
18
|
-
|
19
|
-
# @!attribute [r] source
|
20
|
-
# @return [String] The git remote to use for environments
|
21
|
-
attr_reader :remote
|
22
|
-
|
23
|
-
# @!attribute [r] basedir
|
24
|
-
# @return [String] The base directory to deploy the environments into
|
25
|
-
attr_reader :basedir
|
26
|
-
|
27
|
-
# @!attribute [r] environments
|
28
|
-
# @return [Array<R10K::Deployment::Environment>] All environments for this source
|
29
|
-
attr_reader :environments
|
30
|
-
|
31
7
|
# Create a new source from a hash representation
|
32
8
|
#
|
33
9
|
# @param name [String] The name of the source
|
34
10
|
# @param opts [Hash] The properties to use for the source
|
35
|
-
# @param prefix [true, false] Whether to prefix the source name to created
|
36
|
-
# environments
|
37
11
|
#
|
38
12
|
# @option opts [String] :remote The git remote for the given source
|
39
13
|
# @option opts [String] :basedir The directory to create environments in
|
40
14
|
# @option opts [true, false] :prefix Whether the environment names should
|
41
|
-
# be prefixed by the source name. Defaults to false.
|
42
|
-
# over the `prefix` argument
|
15
|
+
# be prefixed by the source name. Defaults to false.
|
43
16
|
#
|
44
|
-
# @
|
45
|
-
|
46
|
-
|
47
|
-
basedir = (attrs.delete(:basedir) || attrs.delete('basedir'))
|
48
|
-
prefix_config = (attrs.delete(:prefix) || attrs.delete('prefix'))
|
49
|
-
prefix_outcome = prefix_config.nil? ? prefix : prefix_config
|
17
|
+
# @deprecated
|
18
|
+
# @return [R10K::Source::Base]
|
19
|
+
def self.vivify(name, attrs)
|
50
20
|
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def initialize(name, remote, basedir, prefix = nil)
|
56
|
-
@name = name
|
57
|
-
@remote = remote
|
58
|
-
@basedir = basedir
|
59
|
-
@prefix = prefix.nil? ? false : prefix
|
21
|
+
attrs.extend R10K::Util::CoreExt::HashExt::SymbolizeKeys
|
22
|
+
attrs.symbolize_keys!
|
60
23
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
24
|
+
remote = attrs.delete(:remote)
|
25
|
+
basedir = attrs.delete(:basedir)
|
26
|
+
prefix = attrs.delete(:prefix)
|
65
27
|
|
66
|
-
|
67
|
-
|
68
|
-
load_environments
|
69
|
-
end
|
70
|
-
|
71
|
-
include R10K::Util::Purgeable
|
72
|
-
|
73
|
-
def managed_directory
|
74
|
-
@basedir
|
75
|
-
end
|
76
|
-
|
77
|
-
def current_contents
|
78
|
-
dir = self.managed_directory
|
79
|
-
glob_part = @prefix ? @name.to_s() + '_*' : '*'
|
80
|
-
glob_exp = File.join(dir, glob_part)
|
81
|
-
|
82
|
-
Dir.glob(glob_exp).map do |fname|
|
83
|
-
File.basename fname
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# List all environments that should exist in the basedir for this source
|
88
|
-
# @note This implements a required method for the Purgeable mixin
|
89
|
-
# @return [Array<String>]
|
90
|
-
def desired_contents
|
91
|
-
@environments.map {|env| env.dirname }
|
28
|
+
raise ArgumentError, "Unrecognized attributes for #{self.name}: #{attrs.inspect}" unless attrs.empty?
|
29
|
+
new(name, remote, basedir, prefix)
|
92
30
|
end
|
93
31
|
|
94
|
-
|
95
|
-
|
96
|
-
def load_environments
|
97
|
-
if @cache.cached?
|
98
|
-
@environments = @cache.branches.map do |branch|
|
99
|
-
if @prefix
|
100
|
-
R10K::Deployment::Environment.new(branch, @remote, @basedir, nil, @name.to_s())
|
101
|
-
else
|
102
|
-
R10K::Deployment::Environment.new(branch, @remote, @basedir)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
else
|
106
|
-
@environments = []
|
107
|
-
end
|
32
|
+
def self.new(name, remote, basedir, prefix)
|
33
|
+
R10K::Source::Git.new(name, basedir, {:prefix => prefix, :remote => remote})
|
108
34
|
end
|
109
35
|
end
|
110
36
|
end
|
data/lib/r10k/deployment.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
require 'r10k'
|
2
|
-
require 'r10k/deployment/source'
|
3
|
-
require 'r10k/deployment/config'
|
4
|
-
|
5
1
|
require 'yaml'
|
2
|
+
require 'r10k'
|
3
|
+
require 'r10k/source'
|
6
4
|
|
7
5
|
module R10K
|
8
6
|
class Deployment
|
9
7
|
# Model a full installation of module directories and modules.
|
10
8
|
|
9
|
+
require 'r10k/deployment/environment'
|
10
|
+
require 'r10k/deployment/basedir'
|
11
|
+
require 'r10k/deployment/source'
|
12
|
+
require 'r10k/deployment/config'
|
13
|
+
|
11
14
|
# Generate a deployment object based on a config
|
12
15
|
#
|
13
16
|
# @param path [String] The path to the deployment config
|
@@ -19,16 +22,12 @@ class Deployment
|
|
19
22
|
|
20
23
|
def initialize(config)
|
21
24
|
@config = config
|
22
|
-
|
23
|
-
load_environments
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
sources.each
|
28
|
-
source.fetch_remote
|
29
|
-
end
|
30
|
-
load_environments
|
27
|
+
def preload!
|
28
|
+
sources.each(&:preload!)
|
31
29
|
end
|
30
|
+
alias fetch_sources preload!
|
32
31
|
|
33
32
|
# Lazily load all sources
|
34
33
|
#
|
@@ -36,7 +35,7 @@ class Deployment
|
|
36
35
|
# used directly as it could be legitimately unset if we're doing lazy
|
37
36
|
# loading.
|
38
37
|
#
|
39
|
-
# @return [Array<R10K::
|
38
|
+
# @return [Array<R10K::Source::Base>] All repository sources
|
40
39
|
# specified in the config
|
41
40
|
def sources
|
42
41
|
load_sources if @_sources.nil?
|
@@ -49,7 +48,7 @@ class Deployment
|
|
49
48
|
# used directly as it could be legitimately unset if we're doing lazy
|
50
49
|
# loading.
|
51
50
|
#
|
52
|
-
# @return [Array<R10K::
|
51
|
+
# @return [Array<R10K::Environment::Base>] All enviroments across
|
53
52
|
# all sources
|
54
53
|
def environments
|
55
54
|
load_environments if @_environments.nil?
|
@@ -61,7 +60,7 @@ class Deployment
|
|
61
60
|
def load_sources
|
62
61
|
sources = @config.setting(:sources)
|
63
62
|
@_sources = sources.map do |(name, hash)|
|
64
|
-
R10K::
|
63
|
+
R10K::Source.from_hash(name, hash)
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This class defines a common interface for environment implementations.
|
2
|
+
#
|
3
|
+
# @since 1.3.0
|
4
|
+
class R10K::Environment::Base
|
5
|
+
|
6
|
+
# @!attribute [r] name
|
7
|
+
# @return [String] A name for this environment that is unique to the given source
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
# @!attribute [r] basedir
|
11
|
+
# @return [String] The path that this environment will be created in
|
12
|
+
attr_reader :basedir
|
13
|
+
|
14
|
+
# @!attribute [r] dirname
|
15
|
+
# @return [String] The directory name for the given environment
|
16
|
+
attr_reader :dirname
|
17
|
+
|
18
|
+
# Initialize the given environment.
|
19
|
+
#
|
20
|
+
# @param name [String] The unique name describing this environment.
|
21
|
+
# @param basedir [String] The base directory where this environment will be created.
|
22
|
+
# @param dirname [String] The directory name for this environment.
|
23
|
+
# @param options [Hash] An additional set of options for this environment.
|
24
|
+
# The semantics of this environment may depend on the environment implementation.
|
25
|
+
def initialize(name, basedir, dirname, options = {})
|
26
|
+
@name = name
|
27
|
+
@basedir = basedir
|
28
|
+
@dirname = dirname
|
29
|
+
@options = options
|
30
|
+
|
31
|
+
@full_path = File.join(@basedir, @dirname)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Synchronize the given environment.
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
# @abstract
|
38
|
+
# @return [void]
|
39
|
+
def sync
|
40
|
+
raise NotImplementedError, "#{self.class} has not implemented method #{__method__}"
|
41
|
+
end
|
42
|
+
end
|