r10k 1.1.4 → 1.2.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -0
  3. data/.nodeset.yml +7 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +2 -1
  6. data/CHANGELOG +17 -12
  7. data/Gemfile +8 -0
  8. data/README.markdown +4 -2
  9. data/Rakefile +1 -0
  10. data/doc/dynamic-environments.markdown +206 -0
  11. data/doc/puppetfile.markdown +87 -0
  12. data/lib/r10k/cli.rb +1 -1
  13. data/lib/r10k/errors.rb +30 -3
  14. data/lib/r10k/execution.rb +5 -2
  15. data/lib/r10k/git/cache.rb +26 -42
  16. data/lib/r10k/git/commit.rb +22 -0
  17. data/lib/r10k/git/errors.rb +31 -22
  18. data/lib/r10k/git/head.rb +33 -0
  19. data/lib/r10k/git/ref.rb +63 -0
  20. data/lib/r10k/git/repository.rb +65 -36
  21. data/lib/r10k/git/tag.rb +26 -0
  22. data/lib/r10k/git/working_dir.rb +93 -83
  23. data/lib/r10k/git.rb +14 -0
  24. data/lib/r10k/module/forge.rb +129 -62
  25. data/lib/r10k/module/git.rb +72 -6
  26. data/lib/r10k/module/metadata.rb +47 -0
  27. data/lib/r10k/module/svn.rb +99 -0
  28. data/lib/r10k/module.rb +1 -0
  29. data/lib/r10k/module_repository/forge.rb +64 -0
  30. data/lib/r10k/module_repository.rb +8 -0
  31. data/lib/r10k/semver.rb +1 -1
  32. data/lib/r10k/svn/working_dir.rb +76 -0
  33. data/lib/r10k/task/deployment.rb +21 -28
  34. data/lib/r10k/util/subprocess/io.rb +12 -0
  35. data/lib/r10k/util/subprocess/result.rb +36 -0
  36. data/lib/r10k/util/subprocess/runner.rb +88 -0
  37. data/lib/r10k/util/subprocess.rb +107 -0
  38. data/lib/r10k/version.rb +1 -1
  39. data/r10k.gemspec +11 -1
  40. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +42 -0
  41. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +42 -0
  42. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +42 -0
  43. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +42 -0
  44. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +42 -0
  45. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +42 -0
  46. data/spec/rspec-system-r10k/puppetfile.rb +24 -0
  47. data/spec/rspec-system-r10k/tmpdir.rb +32 -0
  48. data/spec/shared-examples/git-ref.rb +49 -0
  49. data/spec/spec_helper.rb +23 -0
  50. data/spec/system/module/forge/install_spec.rb +51 -0
  51. data/spec/system/module/git/install_spec.rb +117 -0
  52. data/spec/system/module/svn/install_spec.rb +51 -0
  53. data/spec/system/module/svn/update_spec.rb +38 -0
  54. data/spec/system/spec_helper.rb +60 -0
  55. data/spec/system/system-helpers.rb +4 -0
  56. data/spec/system/version_spec.rb +7 -0
  57. data/spec/system-provisioning/el.rb +38 -0
  58. data/spec/unit/deployment/source_spec.rb +1 -1
  59. data/spec/unit/git/cache_spec.rb +38 -0
  60. data/spec/unit/git/commit_spec.rb +33 -0
  61. data/spec/unit/git/head_spec.rb +27 -0
  62. data/spec/unit/git/ref_spec.rb +68 -0
  63. data/spec/unit/git/tag_spec.rb +31 -0
  64. data/spec/unit/module/forge_spec.rb +157 -37
  65. data/spec/unit/module/git_spec.rb +49 -0
  66. data/spec/unit/module/metadata_spec.rb +68 -0
  67. data/spec/unit/module/svn_spec.rb +146 -0
  68. data/spec/unit/module_repository/forge_spec.rb +32 -0
  69. metadata +151 -8
checksums.yaml CHANGED
@@ -1,15 +1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VkNWI5MGEyN2MwMjZjMmQ0NjYyYmJmZTQ0ZGNkYTU2MzZi
15
+ NWRmZTViMTBjZGEzYTAwOTdiMmYzYmNkMmM2NThkM2U1MGQyMjk=
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ Gemfile.local
3
3
  Gemfile.lock
4
4
  .bundle
5
5
  bundle
6
+ /.rspec_system
data/.nodeset.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ default_set: 'centos-59-x64'
3
+ sets:
4
+ 'centos-59-x64':
5
+ nodes:
6
+ "main":
7
+ prefab: 'centos-59-x64'
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --default_path spec/unit
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  language: ruby
3
- script: "bundle exec rspec --color --format documentation"
3
+ bundler_args: "--without system"
4
+ script: "bundle exec rspec --color --format documentation spec/unit"
4
5
  notifications:
5
6
  email: false
6
7
  rvm:
data/CHANGELOG CHANGED
@@ -1,26 +1,31 @@
1
1
  CHANGELOG
2
2
  =========
3
3
 
4
- 1.1.4
4
+ 1.2.0
5
5
  -----
6
6
 
7
- 2014-02-24
7
+ 2014/02/08
8
8
 
9
- This is a backwards compatible bugfix release.
9
+ ### User Notes
10
10
 
11
- ### Notes
11
+ Preliminary support for Puppetfile modules from SVN sources. SVN repositories
12
+ can track the latest available revision or may be pinned to a specific revision.
12
13
 
13
- * (GH-90) Multiple environments with the same name but with different sources
14
- were previously colliding and some environments were being ignored. This has
15
- been fixed and all environments should be deployed when updates are run.
14
+ Forge modules can now track the latest available version. This can be enabled by
15
+ setting the module version to `:latest`.
16
16
 
17
- ### Thanks
17
+ Git based Puppetfile modules can now be specified as branches, tags, and
18
+ commits. When tags and commits are specified r10k can perform optimizations
19
+ when updating the given repositories to reduce network accesses.
18
20
 
19
- Thanks to the following contributors for their their extraordinary patience and
20
- help in for chasing down GH-90:
21
+ Command execution has been greatly improved. The old library for executing
22
+ commands (systemu) had very high overhead and was 50 - 100 times slower than
23
+ %x[] or fork/exec. It's been replaced with a custom process execution
24
+ implementation.
21
25
 
22
- * Andreas Ntaflos (antaflos)
23
- * Igor Galić (igalic)
26
+ Modules can swap out sources. When an existing module is changed from Forge to
27
+ Git, for instance, the existing module will be removed before the new module is
28
+ installed. (GH-30)
24
29
 
25
30
  1.1.3
26
31
  -----
data/Gemfile CHANGED
@@ -2,6 +2,14 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ group(:system) do
6
+ gem 'rake'
7
+ gem 'rspec-system', '~> 2.8.0'
8
+ gem 'rspec-system-serverspec', '~> 2.0.1'
9
+ gem 'net-ssh', '2.7.0'
10
+ gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant', :tag => 'v1.4.1'
11
+ end
12
+
5
13
  if File.exists? "#{__FILE__}.local"
6
14
  eval(File.read("#{__FILE__}.local"), binding)
7
15
  end
data/README.markdown CHANGED
@@ -75,9 +75,11 @@ Common Commands
75
75
  Puppetfile support
76
76
  ------------------
77
77
 
78
- r10k can operate on a Puppetfile as a drop-in replacement for librarian-puppet.
78
+ r10k can operate on a Puppetfile using the same syntax as librarian-puppet uses.
79
79
  Puppetfiles are a simple Ruby based DSL that specifies a list of modules to
80
- install, what version to install, and where to fetch them from.
80
+ install, what version to install, and where to fetch them from. Unlike
81
+ librarian-puppet dependency resolution is not yet implemented but is on the
82
+ roadmap.
81
83
 
82
84
  Puppetfile based commands are under the `r10k puppetfile` subcommand.
83
85
 
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'rspec-system/rake_task'
@@ -0,0 +1,206 @@
1
+ Dynamic Environments
2
+ ====================
3
+
4
+ r10k implements the dynamic environment workflow with Puppet. This allows you to
5
+ create, modify, and remove Puppet environments on the fly with Git branches.
6
+
7
+ Dynamic Environments in a nutshell
8
+ ----------------------------------
9
+
10
+ The core idea of dynamic environments is that you should be able to manage your
11
+ Puppet modules in the same manner that you would manage any other code base. It
12
+ builds on top of Git topic branch model.
13
+
14
+ [git-topic-branching]: http://git-scm.com/book/en/Git-Branching-Branching-Workflows#Topic-Branches "Git Topic Branches"
15
+
16
+ One of the most prevalent ways of using Git relies on using [topic branches][git-topic-branching].
17
+ Whenever changes need to be made that need to be reviewed or tested before going
18
+ live, they should be done in a different, short lived branch called a topic
19
+ branch. Work can be freely done on a topic branch in isolation and when the work
20
+ is completed it is merged into a "master" or "production" branch. This is very
21
+ powerful because it allows any number of people to rapidly develop features in
22
+ isolation and merge features in a single operation.
23
+
24
+ The dynamic environment model extends extends this git branching strategy to
25
+ your live Puppet masters. It creates a mapping between Git branches and Puppet
26
+ environments so that you can use the Git branching model and have that be
27
+ seamlessly reflected in Puppet environments. This means that creating a new Git
28
+ branch creates a new Puppet environment, updating a Git branch will update that
29
+ environment, and deleting a Git branch will remove that environment.
30
+
31
+ How it works
32
+ ------------
33
+
34
+ r10k works by tracking the state of your git repositories and comparing them the
35
+ the currently deployed environments. If there's a Git branch that doesn't have a
36
+ corresponding Puppet environment then r10k will clone that branch into the
37
+ appropriate directory. When Git branches are updated r10k will update the
38
+ appropriate Puppet environment to the latest version. Finally if there are
39
+ Puppet environments that don't have matching Git branches, r10k will assume that
40
+ the branches for those environments were deleted and will remove those
41
+ environments.
42
+
43
+ Configuration
44
+ -------------
45
+
46
+ r10k uses a configuration file to determine how dynamic environments should be
47
+ deployed.
48
+
49
+ ### Config file location
50
+
51
+ By default r10k will try to read `/etc/r10k.yaml` for configuration settings.
52
+ You can specify an alternate configuration file by specifying the `--config`
53
+ option, like so:
54
+
55
+ r10k deploy -c /srv/puppet/r10k.yaml
56
+
57
+ ### Configuration format
58
+
59
+ #### cachedir
60
+
61
+ The `cachedir` setting specifies where r10k should keep cached information.
62
+ Right now this is predominantly used for caching git repositories but will be
63
+ expanded as other subsystems can take advantage of caching.
64
+
65
+ For example:
66
+
67
+ ---
68
+ # Store all cache information in /var/cache
69
+ cachedir: '/var/cache/r10k'
70
+
71
+ #### sources
72
+
73
+ The `sources` setting specifies what repositories should be used for creating
74
+ dynamic environments.
75
+
76
+ The `sources` setting is a hash where each key is the short name of a specific
77
+ repository (for instance, "qa" or "web" or "ops") and the value is a hash of
78
+ properties for that source.
79
+
80
+ #### source sub-options
81
+
82
+ ##### remote
83
+
84
+ The remote is the URL of the Git repository to clone. This repository will need
85
+ to be cloned without user intervention so SSH keys will need to be configured
86
+ for the user running r10k.
87
+
88
+ ##### basedir
89
+
90
+ The basedir is the directory that will be populated with Puppet environments.
91
+ This directory will be entirely managed by r10k and any contents that r10k did
92
+ not put there will be _removed_.
93
+
94
+ ##### prefix
95
+
96
+ The prefix setting allows environment names to be prefixed with the short name
97
+ of the given source. This prevents collisions when multiple sources are deployed
98
+ into the same directory.
99
+
100
+ #### source examples
101
+
102
+ ##### Basic examples
103
+
104
+ The majority of users will only have a single repository where all modules and
105
+ hiera data files are kept. In this case you will specify a single source:
106
+
107
+ ---
108
+ # Specify a single environment source
109
+ sources:
110
+ operations:
111
+ remote: 'git@github.com:my-org/org-modules'
112
+ basedir: '/etc/puppet/environments'
113
+
114
+ - - -
115
+
116
+ ##### Advanced examples
117
+
118
+ For more complex cases where you want to store hiera data in a different
119
+ repository and your modules in another repository, you can specify two sources:
120
+
121
+ ---
122
+ sources:
123
+ operations:
124
+ remote: 'git@github.com:my-org/org-modules'
125
+ basedir: '/etc/puppet/environments'
126
+ hiera:
127
+ remote: 'git@github.com:my-org/org-hiera-data'
128
+ basedir: '/etc/puppet/hiera-data'
129
+
130
+ - - -
131
+
132
+ Alternately you may want to create separate environments from multiple
133
+ repositories. This is useful when you want two groups to be able to deploy
134
+ Puppet modules but they should only have write access to their own modules and
135
+ not the modules of other groups.
136
+
137
+ ---
138
+ sources:
139
+ main:
140
+ remote: 'git@github.com:my-org/main-modules'
141
+ basedir: '/etc/puppet/environments'
142
+ prefix: false # Prefix defaults to false so this is only here for clarity
143
+ qa:
144
+ remote: 'git@github.com:my-org/qa-puppet-modules'
145
+ basedir: '/etc/puppet/environments'
146
+ prefix: true
147
+ dev:
148
+ remote: 'git@github.com:my-org/dev-puppet-modules'
149
+ basedir: '/etc/puppet/environments'
150
+ prefix: true
151
+
152
+ This will create the following directory structure:
153
+
154
+
155
+ /etc/puppet/environments
156
+ |-- production # main-modules repository, production branch
157
+ |-- upgrade_apache # main-modules repository, upgrade_apache branch
158
+ |-- qa_production # qa repository, production branch
159
+ |-- qa_jenkins_test # qa repository, jenkins_test branch
160
+ |-- dev_production # dev repository, production branch
161
+ `-- dev_loadtest # dev repository, loadtest branch
162
+
163
+ Dynamic environments and Puppetfiles
164
+ ------------------------------------
165
+
166
+ TODO
167
+
168
+ Interacting with dynamic environments
169
+ -------------------------------------
170
+
171
+ r10k provides fairly fine grained controls over your environments to fit your
172
+ needs. If you want to do a full update of all of your environments and modules
173
+ and don't need it to be done in real time, you can trigger a full update and let
174
+ it run in the background. If you are actively developing code and need to run
175
+ very fast updates of one specific environment, you can do a targeted update of
176
+ that code as well.
177
+
178
+ All commands that deal with deploying environments are grouped under the `r10k
179
+ deploy` subcommand.
180
+
181
+ ### Examples
182
+
183
+ #### Deploying environments
184
+
185
+ # Update all environments across all sources. This can be slow depending
186
+ # on the number of environments and modules that you're using.
187
+ r10k deploy environment
188
+
189
+ # Update a single environment. When you're actively working on an
190
+ # environment this is the best way to deploy your changes.
191
+ r10k deploy environment my_working_environment
192
+
193
+ # This is the brute force approach of "update everything, ever." This can
194
+ # run for an extremely long time so it should not be something you run
195
+ # interactively on a regular basis.
196
+ r10k deploy environment --puppetfile
197
+
198
+ #### Deploying modules
199
+
200
+ # Update a single module across all environments This is useful for when
201
+ # you're working on a module in an environment and only want to update that
202
+ # one module.
203
+ r10k deploy module apache
204
+
205
+ # More than one module can be updated at a time.
206
+ r10k deploy module apache jenkins java
@@ -0,0 +1,87 @@
1
+ Puppetfile
2
+ ==========
3
+
4
+ The Puppetfile is a way to reuse independent Puppet modules in your codebase.
5
+
6
+ When directly working with Puppetfiles, you can use the `r10k puppetfile`
7
+ subcommand to interact with a Puppetfile.
8
+
9
+ When using r10k's deploy functionality, interacting with Puppetfiles is handled
10
+ on a case by case basis.
11
+
12
+ The Puppetfile format is actually implemented using a Ruby DSL so any valid Ruby
13
+ expression can be used. That being said, being a bit too creative in the DSL
14
+ can lead to surprising (read: bad) things happening, so consider keeping it
15
+ simple.
16
+
17
+ Module types
18
+ ------------
19
+
20
+ ### Git
21
+
22
+ Modules can be installed via git.
23
+
24
+ #### Examples
25
+
26
+ # Install puppetlabs/apache and keep it up to date with 'master'
27
+ mod 'apache',
28
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache'
29
+
30
+ # Install puppetlabs/apache and track the 'docs_experiment' branch
31
+ mod 'apache',
32
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache',
33
+ :ref => 'docs_experiment'
34
+
35
+ You can also use the exact object type you want to check out. This may be a
36
+ little bit more work but it has the advantage that r10k make certain
37
+ optimizations based on the object type that you specify.
38
+
39
+ mod 'apache',
40
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache',
41
+ :tag => '0.9.0'
42
+
43
+ mod 'apache',
44
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache',
45
+ :commit => '83401079053dca11d61945bd9beef9ecf7576cbf'
46
+
47
+ You can also explicitly specify a branch, but this behaves the same as
48
+ specifying :ref and is mainly useful for clarity.
49
+
50
+ mod 'apache',
51
+ :git => 'https://github.com/puppetlabs/puppetlabs-apache',
52
+ :branch => 'docs_experiment'
53
+
54
+ ### Forge
55
+
56
+ Modules can be installed using the Puppet module tool.
57
+
58
+ If no version is specified the latest version available at the time will be
59
+ installed, and will be kept at that version.
60
+
61
+ mod 'puppetlabs/apache'
62
+
63
+ If a version is specified then that version will be installed.
64
+
65
+ mod 'puppetlabs/apache', '0.10.0'
66
+
67
+ If the version is set to :latest then the module will be always updated to the
68
+ latest version available.
69
+
70
+ mod 'puppetlabs/apache', :latest
71
+
72
+ ### SVN
73
+
74
+ Modules can be installed via SVN.
75
+
76
+ mod 'apache',
77
+ :svn => 'https://github.com/puppetlabs/puppetlabs-apache/trunk'
78
+
79
+ mod 'apache',
80
+ :svn => 'https://github.com/puppetlabs/puppetlabs-apache/trunk',
81
+ :rev => '154'
82
+
83
+ Alternately,
84
+
85
+ mod 'apache',
86
+ :svn => 'https://github.com/puppetlabs/puppetlabs-apache/trunk',
87
+ :revision => '154'
data/lib/r10k/cli.rb CHANGED
@@ -28,7 +28,7 @@ module R10K::CLI
28
28
  end
29
29
  end
30
30
 
31
- required :c, :config, 'Specify a configuration file' do |value, cmd|
31
+ required :c, :config, 'Specify a global configuration file (deprecated, use `r10k deploy -c`)' do |value, cmd|
32
32
  logger.warn "Calling `r10k --config <action>` as a global option is deprecated; use r10k <action> --config"
33
33
  end
34
34
 
data/lib/r10k/errors.rb CHANGED
@@ -1,5 +1,32 @@
1
1
  module R10K
2
- class ExecutionFailure < StandardError
3
- attr_accessor :exit_code, :stdout, :stderr
4
- end
2
+ class ExecutionFailure < StandardError
3
+ attr_accessor :exit_code, :stdout, :stderr
4
+ end
5
+
6
+ # An error class that accepts an optional hash.
7
+ #
8
+ # @overload initialize(mesg)
9
+ # @param mesg [String] The exception mesg
10
+ #
11
+ # @overload initialize(mesg, options)
12
+ # @param mesg [String] The exception mesg
13
+ # @param options [Hash] A set of options to store on the exception
14
+ #
15
+ # @overload initialize(options)
16
+ # @param options [Hash] A set of options to store on the exception
17
+ #
18
+ class R10KError < StandardError
19
+ def initialize(mesg = nil, options = {})
20
+ if mesg.is_a? String
21
+ super(mesg)
22
+ @mesg = mesg
23
+ @options = options
24
+ elsif mesg.is_a? Hash
25
+ @mesg = nil
26
+ @options = mesg
27
+ elsif mesg.nil? and options
28
+ @options = options
29
+ end
30
+ end
31
+ end
5
32
  end