r10k 3.4.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +4 -0
  3. data/.github/workflows/docker.yml +25 -1
  4. data/.github/workflows/release.yml +36 -0
  5. data/.travis.yml +21 -8
  6. data/CHANGELOG.mkd +64 -4
  7. data/CODEOWNERS +1 -1
  8. data/Gemfile +1 -1
  9. data/README.mkd +13 -4
  10. data/azure-pipelines.yml +4 -2
  11. data/doc/dynamic-environments/configuration.mkd +41 -4
  12. data/doc/dynamic-environments/git-environments.mkd +1 -1
  13. data/doc/dynamic-environments/master-configuration.mkd +28 -58
  14. data/doc/faq.mkd +6 -1
  15. data/doc/puppetfile.mkd +2 -0
  16. data/docker/Makefile +19 -3
  17. data/docker/r10k/Dockerfile +22 -8
  18. data/docker/r10k/release.Dockerfile +23 -4
  19. data/integration/Rakefile +2 -2
  20. data/integration/tests/git_source/git_source_repeated_remote.rb +68 -0
  21. data/lib/r10k/action/deploy/environment.rb +5 -1
  22. data/lib/r10k/action/deploy/module.rb +5 -1
  23. data/lib/r10k/action/runner.rb +4 -4
  24. data/lib/r10k/cli/deploy.rb +1 -1
  25. data/lib/r10k/forge/module_release.rb +2 -2
  26. data/lib/r10k/git/cache.rb +1 -3
  27. data/lib/r10k/git/stateful_repository.rb +4 -0
  28. data/lib/r10k/module/base.rb +8 -0
  29. data/lib/r10k/module/git.rb +4 -0
  30. data/lib/r10k/puppetfile.rb +26 -6
  31. data/lib/r10k/settings.rb +1 -1
  32. data/lib/r10k/source.rb +1 -0
  33. data/lib/r10k/source/exec.rb +51 -0
  34. data/lib/r10k/source/git.rb +22 -2
  35. data/lib/r10k/source/hash.rb +32 -8
  36. data/lib/r10k/version.rb +4 -1
  37. data/locales/r10k.pot +33 -10
  38. data/r10k.gemspec +5 -1
  39. data/spec/unit/action/deploy/module_spec.rb +15 -2
  40. data/spec/unit/action/puppetfile/install_spec.rb +4 -1
  41. data/spec/unit/action/runner_spec.rb +2 -2
  42. data/spec/unit/forge/module_release_spec.rb +14 -10
  43. data/spec/unit/puppetfile_spec.rb +67 -2
  44. data/spec/unit/source/exec_spec.rb +81 -0
  45. data/spec/unit/source/git_spec.rb +37 -1
  46. data/spec/unit/source/hash_spec.rb +54 -0
  47. data/spec/unit/source/yaml_spec.rb +42 -0
  48. metadata +54 -16
  49. data/integration/scripts/README.mkd +0 -86
  50. data/integration/scripts/setup_r10k_env_centos5.sh +0 -23
  51. data/integration/scripts/setup_r10k_env_centos6.sh +0 -23
  52. data/integration/scripts/setup_r10k_env_rhel7.sh +0 -23
  53. data/integration/scripts/setup_r10k_env_sles11.sh +0 -23
  54. data/integration/scripts/setup_r10k_env_sles12.sh +0 -23
  55. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +0 -23
  56. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +0 -23
  57. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +0 -23
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'r10k/source'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ describe R10K::Source::Exec do
7
+
8
+ let(:environments_hash) do
9
+ {
10
+ 'production' => {
11
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
12
+ 'ref' => 'release-141',
13
+ 'modules' => {
14
+ 'puppetlabs-stdlib' => '6.1.0',
15
+ 'puppetlabs-ntp' => '8.1.0',
16
+ 'example-myapp1' => {
17
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
18
+ 'ref' => 'v1.3.0'
19
+ }
20
+ }
21
+ },
22
+ 'development' => {
23
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
24
+ 'ref' => 'master',
25
+ 'modules' => {
26
+ 'puppetlabs-stdlib' => '6.1.0',
27
+ 'puppetlabs-ntp' => '8.1.0',
28
+ 'example-myapp1' => {
29
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
30
+ 'ref' => 'v1.3.1'
31
+ }
32
+ }
33
+ }
34
+ }
35
+ end
36
+
37
+ describe 'initialize' do
38
+ context 'with a valid command' do
39
+ context 'that produces valid output' do
40
+ it 'accepts json' do
41
+ allow_any_instance_of(R10K::Util::Subprocess)
42
+ .to receive(:execute)
43
+ .and_return(double('result', stdout: environments_hash.to_json))
44
+
45
+ source = described_class.new('execsource', '/some/nonexistent/dir', command: '/path/to/command')
46
+ expect(source.environments.map(&:name)).to contain_exactly('production', 'development')
47
+ end
48
+
49
+ it 'accepts yaml' do
50
+ allow_any_instance_of(R10K::Util::Subprocess)
51
+ .to receive(:execute)
52
+ .and_return(double('result', stdout: environments_hash.to_yaml))
53
+
54
+ source = described_class.new('execsource', '/some/nonexistent/dir', command: '/path/to/command')
55
+ expect(source.environments.map(&:name)).to contain_exactly('production', 'development')
56
+ end
57
+
58
+ end
59
+
60
+ context 'that produces invalid output' do
61
+ it 'raises an error for non-json, non-yaml data' do
62
+ allow_any_instance_of(R10K::Util::Subprocess)
63
+ .to receive(:execute)
64
+ .and_return(double('result', stdout: "one:\ntwo\n"))
65
+
66
+ source = described_class.new('execsource', '/some/nonexistent/dir', command: '/path/to/command')
67
+ expect { source.environments }.to raise_error(/Error parsing command output/)
68
+ end
69
+
70
+ it 'raises an error for yaml data that is not a hash' do
71
+ allow_any_instance_of(R10K::Util::Subprocess)
72
+ .to receive(:execute)
73
+ .and_return(double('result', stdout: "[one, two]"))
74
+
75
+ source = described_class.new('execsource', '/some/nonexistent/dir', command: '/path/to/command')
76
+ expect { source.environments }.to raise_error(R10K::Error, /Environment source execsource.*did not return valid environment data.*one.*two.*/m)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -93,9 +93,45 @@ describe R10K::Source::Git do
93
93
  let(:ignore_prefixes) { ['dev', 'test'] }
94
94
 
95
95
  it "filters branches" do
96
- expect(subject.filter_branches(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
96
+ expect(subject.filter_branches_by_regexp(branches, ignore_prefixes)).to eq(['master', 'production', 'not_dev_test_me'])
97
97
  end
98
98
  end
99
+
100
+ describe "filtering branches with command" do
101
+ let(:branches) { ['master', 'development', 'production'] }
102
+ let(:filter_command) { 'sh -c "[ $R10K_BRANCH != development ]"' }
103
+
104
+ it "filters branches" do
105
+ expect(subject.filter_branches_by_command(branches, filter_command)).to eq(['master', 'production'])
106
+ end
107
+ end
108
+
109
+ describe "generate_environments respects filter_command setting" do
110
+ before do
111
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
112
+ subject.instance_variable_set(:@filter_command, '[ $R10K_BRANCH != master ]')
113
+ end
114
+
115
+ let(:environments) { subject.generate_environments }
116
+
117
+ it "creates an environment for each branch not filtered by filter_command" do
118
+ expect(subject.generate_environments.size).to eq(2)
119
+ end
120
+ end
121
+
122
+ describe "generate_environments respects filter_command setting and name" do
123
+ before do
124
+ allow(subject.cache).to receive(:branches).and_return ['master', 'development', 'production']
125
+ subject.instance_variable_set(:@filter_command, '[ $R10K_NAME = mysource ]')
126
+ end
127
+
128
+ let(:environments) { subject.generate_environments }
129
+
130
+ it "creates an environment for each branch not filtered by filter_command" do
131
+ expect(subject.generate_environments.size).to eq(3)
132
+ end
133
+ end
134
+
99
135
  end
100
136
 
101
137
  describe R10K::Source::Git, "handling invalid branch names" do
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'r10k/source'
3
+
4
+ describe R10K::Source::Hash do
5
+
6
+ describe '.valid_environments_hash?' do
7
+ it "rejects strings" do
8
+ expect(R10K::Source::Hash.valid_environments_hash?('200 OK'))
9
+ .to eq false
10
+ end
11
+ end
12
+
13
+ let(:environments_hash) do
14
+ {
15
+ 'production' => {
16
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
17
+ 'ref' => 'release-141',
18
+ 'modules' => {
19
+ 'puppetlabs-stdlib' => '6.1.0',
20
+ 'puppetlabs-ntp' => '8.1.0',
21
+ 'example-myapp1' => {
22
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
23
+ 'ref' => 'v1.3.0'
24
+ }
25
+ }
26
+ },
27
+ 'development' => {
28
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
29
+ 'ref' => 'master',
30
+ 'modules' => {
31
+ 'puppetlabs-stdlib' => '6.1.0',
32
+ 'puppetlabs-ntp' => '8.1.0',
33
+ 'example-myapp1' => {
34
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
35
+ 'ref' => 'v1.3.1'
36
+ }
37
+ }
38
+ }
39
+ }
40
+ end
41
+
42
+ describe "with a prefix" do
43
+ subject do
44
+ described_class.new('hashsource', '/some/nonexistent/dir',
45
+ prefix: 'prefixed', environments: environments_hash)
46
+ end
47
+
48
+ it "prepends environment names with a prefix" do
49
+ environments = subject.environments
50
+ expect(environments[0].dirname).to eq 'prefixed_production'
51
+ expect(environments[1].dirname).to eq 'prefixed_development'
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'r10k/source'
3
+
4
+ describe R10K::Source::Yaml do
5
+
6
+ let(:environments_hash) do
7
+ {
8
+ 'production' => {
9
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
10
+ 'ref' => 'release-141',
11
+ 'modules' => {
12
+ 'puppetlabs-stdlib' => '6.1.0',
13
+ 'puppetlabs-ntp' => '8.1.0',
14
+ 'example-myapp1' => {
15
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
16
+ 'ref' => 'v1.3.0'
17
+ }
18
+ }
19
+ },
20
+ 'development' => {
21
+ 'remote' => 'https://git.example.com/puppet/control-repo.git',
22
+ 'ref' => 'master',
23
+ 'modules' => {
24
+ 'puppetlabs-stdlib' => '6.1.0',
25
+ 'puppetlabs-ntp' => '8.1.0',
26
+ 'example-myapp1' => {
27
+ 'git' => 'https://git.example.com/puppet/example-myapp1.git',
28
+ 'ref' => 'v1.3.1'
29
+ }
30
+ }
31
+ }
32
+ }
33
+ end
34
+
35
+ describe "with valid yaml file" do
36
+ it "produces environments" do
37
+ allow(YAML).to receive(:load_file).with('/envs.yaml').and_return(environments_hash)
38
+ source = described_class.new('yamlsource', '/some/nonexistent/dir', config: '/envs.yaml')
39
+ expect(source.environments.map(&:name)).to contain_exactly('production', 'development')
40
+ end
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r10k
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Thebo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: cri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.15.6
33
+ version: 2.15.10
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.0
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - '='
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.15.10
44
+ - - "<"
39
45
  - !ruby/object:Gem::Version
40
- version: 2.15.6
46
+ version: 3.0.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: log4r
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +100,40 @@ dependencies:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0.24'
103
+ - !ruby/object:Gem::Dependency
104
+ name: fast_gettext
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.1.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.1.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: gettext
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 3.0.2
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: 3.3.0
127
+ type: :runtime
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 3.0.2
134
+ - - "<"
135
+ - !ruby/object:Gem::Version
136
+ version: 3.3.0
97
137
  - !ruby/object:Gem::Dependency
98
138
  name: rspec
99
139
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +201,9 @@ extensions: []
161
201
  extra_rdoc_files: []
162
202
  files:
163
203
  - ".gitattributes"
204
+ - ".github/pull_request_template.md"
164
205
  - ".github/workflows/docker.yml"
206
+ - ".github/workflows/release.yml"
165
207
  - ".gitignore"
166
208
  - ".travis.yml"
167
209
  - CHANGELOG.mkd
@@ -222,15 +264,6 @@ files:
222
264
  - integration/pre-suite/10_git_config.rb
223
265
  - integration/pre-suite/20_pe_r10k.rb
224
266
  - integration/pre-suite/README.mkd
225
- - integration/scripts/README.mkd
226
- - integration/scripts/setup_r10k_env_centos5.sh
227
- - integration/scripts/setup_r10k_env_centos6.sh
228
- - integration/scripts/setup_r10k_env_rhel7.sh
229
- - integration/scripts/setup_r10k_env_sles11.sh
230
- - integration/scripts/setup_r10k_env_sles12.sh
231
- - integration/scripts/setup_r10k_env_ubuntu1004.sh
232
- - integration/scripts/setup_r10k_env_ubuntu1204.sh
233
- - integration/scripts/setup_r10k_env_ubuntu1404.sh
234
267
  - integration/tests/Puppetfile/HTTP_PROXY_affects_forge_source.rb
235
268
  - integration/tests/Puppetfile/HTTP_PROXY_affects_git_source.rb
236
269
  - integration/tests/README.mkd
@@ -249,6 +282,7 @@ files:
249
282
  - integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb
250
283
  - integration/tests/git_source/HTTP_proxy_and_git_source.rb
251
284
  - integration/tests/git_source/git_source_git.rb
285
+ - integration/tests/git_source/git_source_repeated_remote.rb
252
286
  - integration/tests/git_source/git_source_ssh.rb
253
287
  - integration/tests/git_source/git_source_submodule.rb
254
288
  - integration/tests/git_source/negative/neg_git_broken_remote.rb
@@ -375,6 +409,7 @@ files:
375
409
  - lib/r10k/settings/uri_definition.rb
376
410
  - lib/r10k/source.rb
377
411
  - lib/r10k/source/base.rb
412
+ - lib/r10k/source/exec.rb
378
413
  - lib/r10k/source/git.rb
379
414
  - lib/r10k/source/hash.rb
380
415
  - lib/r10k/source/svn.rb
@@ -502,8 +537,11 @@ files:
502
537
  - spec/unit/settings/uri_definition_spec.rb
503
538
  - spec/unit/settings_spec.rb
504
539
  - spec/unit/source/base_spec.rb
540
+ - spec/unit/source/exec_spec.rb
505
541
  - spec/unit/source/git_spec.rb
542
+ - spec/unit/source/hash_spec.rb
506
543
  - spec/unit/source/svn_spec.rb
544
+ - spec/unit/source/yaml_spec.rb
507
545
  - spec/unit/source_spec.rb
508
546
  - spec/unit/svn/remote_spec.rb
509
547
  - spec/unit/svn/working_dir_spec.rb
@@ -538,7 +576,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
538
576
  - !ruby/object:Gem::Version
539
577
  version: '0'
540
578
  requirements: []
541
- rubygems_version: 3.0.6
579
+ rubygems_version: 3.0.3
542
580
  signing_key:
543
581
  specification_version: 4
544
582
  summary: Puppet environment and module deployment
@@ -1,86 +0,0 @@
1
- Scripts
2
- =======
3
-
4
- This folder contains helper scripts for setting up manual testing environments
5
- using [Beaker](https://github.com/puppetlabs/beaker) configuration files. The
6
- environments created by these scripts have "r10k" fully configured along with
7
- a Git repository with a valid "production" environment.
8
-
9
- These scripts are specific to the Puppet Labs environment and will not work in
10
- other environments without alteration!
11
-
12
- ## Prerequisites
13
-
14
- To utilize this test scripts you will need to have Ruby 1.9.3 or greater
15
- installed on your system along with Bundler. Also, the scripts utilize the
16
- "vmpooler" for virtual machine creation. Access to the "vmpooler" machines
17
- require having valid SSH private keys located on your local computer. Speak
18
- with a QA team member for more information on where to find the necessary
19
- SSH keys.
20
-
21
- ## Usage
22
-
23
- The scripts are written in Bash and should run on any Linux or Mac system as
24
- long as the prerequisites mentioned above are satisfied.
25
-
26
- ### Cloning
27
-
28
- First you will need to clone the "[r10k](https://github.com/puppetlabs/r10k)" repository on your local machine:
29
-
30
- ```bash
31
- git clone git@github.com:puppetlabs/r10k.git
32
- ```
33
-
34
- ### Executing Script
35
-
36
- Navigate to the integration tests "scripts" folder of the "r10k" repository
37
- clone:
38
-
39
- ```bash
40
- cd r10k/integration/scripts
41
- ```
42
-
43
- There are separate scripts for each supported platform. Select a desired
44
- platform and execute the script:
45
-
46
- ```bash
47
- bash setup_r10k_env_centos6.sh
48
- ```
49
-
50
- ## Connecting to Machines
51
-
52
- The setup process takes about 10 minutes to complete. Once finished Beaker
53
- will report that all tests have been run successfully. The output log will
54
- list the machines created. The Puppet master will have a name ending with
55
- "-master" which you can scrape from the Beaker console output. Example:
56
-
57
- ```
58
- a9lrs93vnujsrrg.delivery.puppetlabs.net (centos-6-x86_64-master) executed in 1.26 seconds
59
- ```
60
-
61
- The FQDN of the Puppet master ("a9lrs93vnujsrrg.delivery.puppetlabs.net" in the
62
- above example) will be printed to the left of the machine tag. The machine tag
63
- is a combination of the platform and role of the virtual machine.
64
-
65
- Now that you have the FQDN you can connect to the machine using SSH:
66
-
67
- ```bash
68
- ssh -i private_key root@a9lrs93vnujsrrg.delivery.puppetlabs.net
69
- ```
70
-
71
- *Note:* The correct SSH private key needs to be installed on your local machine
72
- first. Speak with a QA representative to get the correct key for "vmpooler"
73
- machines.
74
-
75
- ## Configuration Details
76
-
77
- Now that you have successfully connected to the Puppet master you can begin
78
- manual testing. The script has configured Git on the Puppet master to provide
79
- a working "production" environment for "r10k" testing. The Git repository
80
- serving the Puppet environments is located at "/git_repos/environments.git".
81
- There is a Git clone of the remote repository located at "/root/environments".
82
-
83
- When performing manual "r10k" testing you should utilize the Git clone
84
- repository located at "/root/environments". The "r10k" configuration file
85
- "/etc/puppetlabs/r10k/r10k.yaml" is already configured to use the remote Git
86
- repository for deployments.