r10k 3.4.1 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -3
- data/CHANGELOG.mkd +11 -0
- data/azure-pipelines.yml +2 -1
- data/doc/dynamic-environments/configuration.mkd +14 -0
- data/docker/Makefile +3 -1
- data/docker/r10k/Dockerfile +5 -2
- data/lib/r10k/action/deploy/environment.rb +5 -1
- data/lib/r10k/action/runner.rb +4 -4
- data/lib/r10k/source.rb +1 -0
- data/lib/r10k/source/exec.rb +51 -0
- data/lib/r10k/source/hash.rb +32 -8
- data/lib/r10k/version.rb +1 -1
- data/locales/r10k.pot +24 -5
- data/spec/unit/action/puppetfile/install_spec.rb +3 -1
- data/spec/unit/action/runner_spec.rb +2 -2
- data/spec/unit/source/exec_spec.rb +81 -0
- data/spec/unit/source/hash_spec.rb +54 -0
- data/spec/unit/source/yaml_spec.rb +42 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89108575df655aa63ddced0692fa8815939d0d472b85914ea29430e1f76985b9
|
4
|
+
data.tar.gz: 343319b5506fb72d905b3a510765d3dac0bb3643188a95fc24cdb83f90e4d490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d034cbfd986f11e9b0a3298a015d75a41db6800a06b8e437b06b1298dac0ea008a6fdd8c20546806faf3d8c58f1f964073a148609bcabb025610aa7e7b9425b6
|
7
|
+
data.tar.gz: 61629bc37a035d75b70a2cf70dd0cd91a0af8286215da2498518e7a6f698091584576c3afb31b734521edae36e4d371b34bc6f2e9ca08824d167d7748c4c646d
|
data/.travis.yml
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
|
-
services:
|
4
|
-
- docker
|
5
3
|
bundler_args: "--without system"
|
6
4
|
script: "bundle exec rspec --color --format documentation spec/unit"
|
7
5
|
notifications:
|
@@ -25,10 +23,20 @@ matrix:
|
|
25
23
|
- stage: r10k tests
|
26
24
|
rvm: jruby
|
27
25
|
- stage: r10k container tests
|
26
|
+
dist: bionic
|
28
27
|
language: ruby
|
29
|
-
|
28
|
+
services:
|
29
|
+
# bionic uses 18.06 but need 19.03+ for buildkit so upgrade later in relevant cell
|
30
|
+
- docker
|
31
|
+
rvm: 2.6.5
|
32
|
+
env:
|
33
|
+
# necessary to prevent overwhelming TravisCI build output limits
|
34
|
+
- DOCKER_BUILD_FLAGS="--progress plain"
|
30
35
|
script:
|
31
36
|
- |
|
32
37
|
set -ex
|
38
|
+
sudo apt update -y && sudo apt install -y docker.io
|
39
|
+
sudo systemctl unmask docker.service
|
40
|
+
sudo systemctl start docker
|
33
41
|
cd docker && make lint build test
|
34
42
|
set +x
|
data/CHANGELOG.mkd
CHANGED
@@ -4,8 +4,19 @@ CHANGELOG
|
|
4
4
|
Unreleased
|
5
5
|
----
|
6
6
|
|
7
|
+
|
8
|
+
3.5.0
|
9
|
+
-----
|
10
|
+
|
11
|
+
- Add exec environment source type. The exec source type allows for the
|
12
|
+
implementation of external environment sources
|
13
|
+
[#1042](https://github.com/puppetlabs/r10k/pull/1042).
|
14
|
+
- Improve atomicity of .r10k-deploy.json writes. Fixes
|
15
|
+
[#813](https://github.com/puppetlabs/r10k/issues/813)
|
16
|
+
|
7
17
|
3.4.1
|
8
18
|
----
|
19
|
+
|
9
20
|
- Add support for Ruby 2.7
|
10
21
|
- (RK-357) Restrict gettext and fast_gettext versions for compatibility with Ruby 2.4
|
11
22
|
- Bump cri to 2.15.10
|
data/azure-pipelines.yml
CHANGED
@@ -578,6 +578,20 @@ remote: git@github.com:puppetlabs/control-repo.git
|
|
578
578
|
ref: 8820892
|
579
579
|
```
|
580
580
|
|
581
|
+
### Exec environment Source
|
582
|
+
|
583
|
+
The exec environment source runs an external command which is expected to return on stdout content compatible with the YAML environment source data format. The command may return the data in JSON or YAML form. The exec environment source is similar in purpose to Puppet's exec node terminus, used to implement external node classifiers (ENCs). R10k's exec source type allows the the implementation of external environment sources.
|
584
|
+
|
585
|
+
```yaml
|
586
|
+
# r10k.yaml
|
587
|
+
---
|
588
|
+
sources:
|
589
|
+
puppet:
|
590
|
+
type: exec
|
591
|
+
basedir: /etc/puppetlabs/code/environments
|
592
|
+
command: /usr/local/bin/r10k-environments.sh
|
593
|
+
```
|
594
|
+
|
581
595
|
### Environment Modules
|
582
596
|
|
583
597
|
The environment modules feature allows module content to be attached to an environment at environment definition time. This happens before modules specified in a Puppetfile are attached to an environment, which does not happen until deploy time. Environment module implementation depends on the environment source type.
|
data/docker/Makefile
CHANGED
@@ -4,11 +4,12 @@ git_describe = $(shell git describe)
|
|
4
4
|
vcs_ref := $(shell git rev-parse HEAD)
|
5
5
|
build_date := $(shell date -u +%FT%T)
|
6
6
|
hadolint_available := $(shell hadolint --help > /dev/null 2>&1; echo $$?)
|
7
|
-
hadolint_command := hadolint
|
7
|
+
hadolint_command := hadolint
|
8
8
|
hadolint_container := hadolint/hadolint:latest
|
9
9
|
export BUNDLE_PATH = $(PWD)/.bundle/gems
|
10
10
|
export BUNDLE_BIN = $(PWD)/.bundle/bin
|
11
11
|
export GEMFILE = $(PWD)/Gemfile
|
12
|
+
export DOCKER_BUILDKIT = 1
|
12
13
|
|
13
14
|
ifeq ($(IS_RELEASE),true)
|
14
15
|
VERSION ?= $(shell echo $(git_describe) | sed 's/-.*//')
|
@@ -36,6 +37,7 @@ endif
|
|
36
37
|
|
37
38
|
build: prep
|
38
39
|
docker build \
|
40
|
+
${DOCKER_BUILD_FLAGS} \
|
39
41
|
--pull \
|
40
42
|
--build-arg vcs_ref=$(vcs_ref) \
|
41
43
|
--build-arg build_date=$(build_date) \
|
data/docker/r10k/Dockerfile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
FROM alpine:3.9 as build
|
2
2
|
|
3
|
+
# hadolint ignore=DL3018
|
3
4
|
RUN apk add --no-cache ruby git && \
|
4
5
|
mkdir /workspace
|
5
6
|
WORKDIR /workspace
|
@@ -39,13 +40,15 @@ LABEL org.label-schema.version="$version" \
|
|
39
40
|
org.label-schema.build-date="$build_date"
|
40
41
|
|
41
42
|
COPY --from=build /workspace/r10k.gem /
|
43
|
+
# ignore apk and gem pinning
|
44
|
+
# hadolint ignore=DL3018,DL3028
|
42
45
|
RUN chmod a+x /adduser.sh && \
|
43
46
|
# Add a puppet user to run r10k as for consistency with puppetserver
|
44
47
|
/adduser.sh && \
|
45
48
|
chmod +x /docker-entrypoint.sh && \
|
46
49
|
chown -R puppet: /docker-entrypoint.d /docker-entrypoint.sh && \
|
47
|
-
apk add --no-cache ruby openssh-client git ruby-rugged curl ruby-
|
48
|
-
gem install --no-doc /r10k.gem
|
50
|
+
apk add --no-cache ruby openssh-client git ruby-rugged curl ruby-json ruby-etc && \
|
51
|
+
gem install --no-doc /r10k.gem && \
|
49
52
|
rm -f /r10k.gem
|
50
53
|
|
51
54
|
USER puppet
|
@@ -157,7 +157,10 @@ module R10K
|
|
157
157
|
logger.debug("Unable to get environment module deploy data for .r10k-deploy.json at #{environment.path}")
|
158
158
|
end
|
159
159
|
|
160
|
-
|
160
|
+
# make this file write as atomic as possible in pure ruby
|
161
|
+
final = "#{environment.path}/.r10k-deploy.json"
|
162
|
+
staging = "#{environment.path}/.r10k-deploy.json~"
|
163
|
+
File.open(staging, 'w') do |f|
|
161
164
|
deploy_info = environment.info.merge({
|
162
165
|
:started_at => started_at,
|
163
166
|
:finished_at => Time.new,
|
@@ -167,6 +170,7 @@ module R10K
|
|
167
170
|
|
168
171
|
f.puts(JSON.pretty_generate(deploy_info))
|
169
172
|
end
|
173
|
+
FileUtils.mv(staging, final)
|
170
174
|
end
|
171
175
|
|
172
176
|
def undeployable_environment_names(environments, expected_names)
|
data/lib/r10k/action/runner.rb
CHANGED
@@ -43,10 +43,10 @@ module R10K
|
|
43
43
|
config_settings = settings_from_config(@opts[:config])
|
44
44
|
|
45
45
|
overrides = {}
|
46
|
-
overrides[:cachedir] = @opts[:cachedir]
|
47
|
-
overrides[:deploy] = {} if
|
48
|
-
overrides[:deploy][:puppet_path] = @opts[:'puppet-path']
|
49
|
-
overrides[:deploy][:generate_types] = @opts[:'generate-types']
|
46
|
+
overrides[:cachedir] = @opts[:cachedir] if @opts.key?(:cachedir)
|
47
|
+
overrides[:deploy] = {} if @opts.key?(:'puppet-path') || @opts.key?(:'generate-types')
|
48
|
+
overrides[:deploy][:puppet_path] = @opts[:'puppet-path'] if @opts.key?(:'puppet-path')
|
49
|
+
overrides[:deploy][:generate_types] = @opts[:'generate-types'] if @opts.key?(:'generate-types')
|
50
50
|
|
51
51
|
with_overrides = config_settings.merge(overrides) do |key, oldval, newval|
|
52
52
|
newval = oldval.merge(newval) if oldval.is_a? Hash
|
data/lib/r10k/source.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'r10k/util/subprocess'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class R10K::Source::Exec < R10K::Source::Hash
|
6
|
+
R10K::Source.register(:exec, self)
|
7
|
+
|
8
|
+
def initialize(name, basedir, options = {})
|
9
|
+
unless @command = options[:command]
|
10
|
+
raise ConfigError, _('Environment source %{name} missing required parameter: command') % {name: name}
|
11
|
+
end
|
12
|
+
|
13
|
+
# We haven't set the environments option yet. We will do that by
|
14
|
+
# overloading the #environments method.
|
15
|
+
super(name, basedir, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def environments_hash
|
19
|
+
@environments_hash ||= set_environments_hash(run_environments_command)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def run_environments_command
|
25
|
+
subproc = R10K::Util::Subprocess.new([@command])
|
26
|
+
subproc.raise_on_fail = true
|
27
|
+
subproc.logger = self.logger
|
28
|
+
procresult = subproc.execute
|
29
|
+
|
30
|
+
begin
|
31
|
+
environments = JSON.parse(procresult.stdout)
|
32
|
+
rescue JSON::ParserError => json_err
|
33
|
+
begin
|
34
|
+
environments = YAML.safe_load(procresult.stdout)
|
35
|
+
rescue Psych::SyntaxError => yaml_err
|
36
|
+
raise R10K::Error, _("Error parsing command output for exec source %{name}:\n" \
|
37
|
+
"Not valid JSON: %{j_msg}\n" \
|
38
|
+
"Not valid YAML: %{y_msg}\n" \
|
39
|
+
"Stdout:\n%{out}") % {name: name, j_msg: json_err.message, y_msg: yaml_err.message, out: procresult.stdout}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
unless R10K::Source::Hash.valid_environments_hash?(environments)
|
44
|
+
raise R10K::Error, _("Environment source %{name} command %{cmd} did not return valid environment data.\n" \
|
45
|
+
'Returned: %{data}') % {name: name, cmd: @command, data: environments}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return the resulting environments hash
|
49
|
+
environments
|
50
|
+
end
|
51
|
+
end
|
data/lib/r10k/source/hash.rb
CHANGED
@@ -120,6 +120,16 @@
|
|
120
120
|
#
|
121
121
|
class R10K::Source::Hash < R10K::Source::Base
|
122
122
|
|
123
|
+
include R10K::Logging
|
124
|
+
|
125
|
+
# @param hash [Hash] A hash to validate.
|
126
|
+
# @return [Boolean] False if the hash is obviously invalid. A true return
|
127
|
+
# means _maybe_ it's valid.
|
128
|
+
def self.valid_environments_hash?(hash)
|
129
|
+
# TODO: more robust schema valiation
|
130
|
+
hash.is_a?(Hash)
|
131
|
+
end
|
132
|
+
|
123
133
|
# @param name [String] The identifier for this source.
|
124
134
|
# @param basedir [String] The base directory where the generated environments will be created.
|
125
135
|
# @param options [Hash] An additional set of options for this source. The
|
@@ -131,19 +141,33 @@ class R10K::Source::Hash < R10K::Source::Base
|
|
131
141
|
# @option options [Hash] :environments The hash definition of environments
|
132
142
|
def initialize(name, basedir, options = {})
|
133
143
|
super(name, basedir, options)
|
144
|
+
end
|
134
145
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
146
|
+
# Set the environment hash for the source. The environment hash is what the
|
147
|
+
# source uses to generate enviroments.
|
148
|
+
# @param hash [Hash] The hash to sanitize and use as the source's environments.
|
149
|
+
# Should be formatted for use with R10K::Environment#from_hash.
|
150
|
+
def set_environments_hash(hash)
|
151
|
+
@environments_hash = hash.reduce({}) do |memo,(name,opts)|
|
152
|
+
R10K::Util::SymbolizeKeys.symbolize_keys!(opts)
|
153
|
+
memo.merge({
|
154
|
+
name => opts.merge({
|
155
|
+
:basedir => @basedir,
|
156
|
+
:dirname => R10K::Environment::Name.new(name, {prefix: @prefix, source: @name}).dirname
|
157
|
+
})
|
158
|
+
})
|
142
159
|
end
|
143
160
|
end
|
144
161
|
|
162
|
+
# Return the sanitized environments hash for this source. The environments
|
163
|
+
# hash should contain objects formatted for use with R10K::Environment#from_hash.
|
164
|
+
# If the hash does not exist it will be built based on @options.
|
165
|
+
def environments_hash
|
166
|
+
@environments_hash ||= set_environments_hash(@options.fetch(:environments, {}))
|
167
|
+
end
|
168
|
+
|
145
169
|
def environments
|
146
|
-
@environments ||=
|
170
|
+
@environments ||= environments_hash.map do |name, hash|
|
147
171
|
R10K::Environment.from_hash(name, hash)
|
148
172
|
end
|
149
173
|
end
|
data/lib/r10k/version.rb
CHANGED
@@ -2,5 +2,5 @@ module R10K
|
|
2
2
|
# When updating to a new major (X) or minor (Y) version, include `#major` or
|
3
3
|
# `#minor` (respectively) in your commit message to trigger the appropriate
|
4
4
|
# release. Otherwise, a new patch (Z) version will be released.
|
5
|
-
VERSION = '3.
|
5
|
+
VERSION = '3.5.0'
|
6
6
|
end
|
data/locales/r10k.pot
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# SOME DESCRIPTIVE TITLE.
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2020 Puppet, Inc.
|
3
3
|
# This file is distributed under the same license as the r10k package.
|
4
|
-
# FIRST AUTHOR <EMAIL@ADDRESS>,
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
|
5
5
|
#
|
6
6
|
#, fuzzy
|
7
7
|
msgid ""
|
8
8
|
msgstr ""
|
9
|
-
"Project-Id-Version: r10k 3.
|
9
|
+
"Project-Id-Version: r10k 3.4.1-20-g8fe925b\n"
|
10
10
|
"\n"
|
11
11
|
"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
|
12
|
-
"POT-Creation-Date:
|
13
|
-
"PO-Revision-Date:
|
12
|
+
"POT-Creation-Date: 2020-04-28 18:41+0000\n"
|
13
|
+
"PO-Revision-Date: 2020-04-28 18:41+0000\n"
|
14
14
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
15
15
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
16
16
|
"Language: \n"
|
@@ -423,6 +423,25 @@ msgstr ""
|
|
423
423
|
msgid "Setting %{name} requires a URL but '%{value}' could not be parsed as a URL"
|
424
424
|
msgstr ""
|
425
425
|
|
426
|
+
#: ../lib/r10k/source/exec.rb:10
|
427
|
+
msgid "Environment source %{name} missing required parameter: command"
|
428
|
+
msgstr ""
|
429
|
+
|
430
|
+
#: ../lib/r10k/source/exec.rb:36
|
431
|
+
msgid ""
|
432
|
+
"Error parsing command output for exec source %{name}:\n"
|
433
|
+
"Not valid JSON: %{j_msg}\n"
|
434
|
+
"Not valid YAML: %{y_msg}\n"
|
435
|
+
"Stdout:\n"
|
436
|
+
"%{out}"
|
437
|
+
msgstr ""
|
438
|
+
|
439
|
+
#: ../lib/r10k/source/exec.rb:44
|
440
|
+
msgid ""
|
441
|
+
"Environment source %{name} command %{cmd} did not return valid environment data.\n"
|
442
|
+
"Returned: %{data}"
|
443
|
+
msgstr ""
|
444
|
+
|
426
445
|
#: ../lib/r10k/source/git.rb:72
|
427
446
|
msgid "Fetching '%{remote}' to determine current branches."
|
428
447
|
msgstr ""
|
@@ -19,7 +19,9 @@ describe R10K::Action::Puppetfile::Install do
|
|
19
19
|
|
20
20
|
describe "installing modules" do
|
21
21
|
let(:modules) do
|
22
|
-
|
22
|
+
(1..4).map do |idx|
|
23
|
+
R10K::Module::Base.new("author/modname#{idx}", "/some/nonexistent/path/modname#{idx}", nil)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
before do
|
@@ -94,7 +94,7 @@ describe R10K::Action::Runner do
|
|
94
94
|
else
|
95
95
|
{ "#{conf_path}": override }
|
96
96
|
end
|
97
|
-
expect(global_settings).to receive(:evaluate).with(overrides).and_call_original
|
97
|
+
expect(global_settings).to receive(:evaluate).with(hash_including(overrides)).and_call_original
|
98
98
|
runner.call
|
99
99
|
end
|
100
100
|
end
|
@@ -109,7 +109,7 @@ describe R10K::Action::Runner do
|
|
109
109
|
else
|
110
110
|
{ "#{conf_path}": override }
|
111
111
|
end
|
112
|
-
expect(global_settings).to receive(:evaluate).with(overrides).and_call_original
|
112
|
+
expect(global_settings).to receive(:evaluate).with(hash_including(overrides)).and_call_original
|
113
113
|
runner.call
|
114
114
|
end
|
115
115
|
end
|
@@ -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
|
@@ -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
|
+
version: 3.5.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-
|
11
|
+
date: 2020-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|
@@ -408,6 +408,7 @@ files:
|
|
408
408
|
- lib/r10k/settings/uri_definition.rb
|
409
409
|
- lib/r10k/source.rb
|
410
410
|
- lib/r10k/source/base.rb
|
411
|
+
- lib/r10k/source/exec.rb
|
411
412
|
- lib/r10k/source/git.rb
|
412
413
|
- lib/r10k/source/hash.rb
|
413
414
|
- lib/r10k/source/svn.rb
|
@@ -535,8 +536,11 @@ files:
|
|
535
536
|
- spec/unit/settings/uri_definition_spec.rb
|
536
537
|
- spec/unit/settings_spec.rb
|
537
538
|
- spec/unit/source/base_spec.rb
|
539
|
+
- spec/unit/source/exec_spec.rb
|
538
540
|
- spec/unit/source/git_spec.rb
|
541
|
+
- spec/unit/source/hash_spec.rb
|
539
542
|
- spec/unit/source/svn_spec.rb
|
543
|
+
- spec/unit/source/yaml_spec.rb
|
540
544
|
- spec/unit/source_spec.rb
|
541
545
|
- spec/unit/svn/remote_spec.rb
|
542
546
|
- spec/unit/svn/working_dir_spec.rb
|