Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from upstream #1

Merged
merged 56 commits into from
Jun 21, 2019
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
de3f000
Fix frozen string error (#434)
khaefeli Feb 18, 2019
593d234
Update metadata.json (#429)
davejrt Feb 18, 2019
686e2ae
adding in type/provider for docker stack (#433)
davejrt Feb 18, 2019
ff48787
updating acceptance tests for cve-2019-5736 (#430)
davejrt Feb 18, 2019
f13f62b
including docker class in all tests of docker::run (#437)
davejrt Feb 19, 2019
d5ec192
fixing errors with bundle file conditional statement (#436)
davejrt Feb 19, 2019
1cc4296
Add docker socket group overrides for systemd (service and socket) (#…
esalberg Feb 25, 2019
4ba9cfe
changing permissions to remove systemd warning (#440)
davejrt Feb 25, 2019
16764c3
adding in documentation for use of stack type/provider (#443)
davejrt Feb 25, 2019
01932d7
release for v3.4.0 (#442)
davejrt Feb 25, 2019
a204679
docker::services: Fix using multiple published ports (#447)
jacksgt Mar 4, 2019
059d8a8
Add ability to override After for docker.service (#446)
esalberg Mar 4, 2019
226be6c
Add ability to set service_after_override to false (#448)
esalberg Mar 8, 2019
15ee0e4
Docker::Services: Add networks parameter for swarm services (#450)
jacksgt Mar 8, 2019
fb2d756
Docker::Services:: fix command parameter used with an array (#452)
jacksgt Mar 11, 2019
1352bb6
making dependency ranges more logical (#453)
davejrt Mar 11, 2019
c8b5902
adding in capability to attach multiple networks to container (#451)
davejrt Mar 12, 2019
84e8edc
fix(syntax): Remove duplicate parenthesis (#454)
jfroche Mar 13, 2019
e59ec60
release 3.5.0 (#458)
davejrt Mar 14, 2019
ddd99ac
Update readme for aws logging options (#459)
acurus-puppetmaster Mar 18, 2019
e01a33f
Allow images tagged latest to update on each run
electrofelix Apr 2, 2019
d4dac10
Fix docker::image to not run images (#465)
hugotanure Apr 3, 2019
043395e
Introduced docker machine support (#466)
acurus-puppetmaster Apr 8, 2019
e9f906c
Fix publish flag being erroneously added to docker service commands (…
twistedduck Apr 9, 2019
0506ec8
Fix container running check to work for windows hosts
florindragos Apr 8, 2019
f9e4c88
Add missing apostrophe in array. (#473)
towo Apr 16, 2019
1cbcf1e
Merge pull request #470 from florindragos/master
tphoney Apr 16, 2019
c36e36b
Fix supported operating systems in the readme
florindragos Apr 16, 2019
9b6ea2b
Merge pull request #475 from florindragos/master
tphoney Apr 16, 2019
813dcbd
Merge pull request #468 from electrofelix/noop-latest-images
Apr 18, 2019
4b57d04
Add service_provider parameter to docker::run
jameslikeslinux Dec 20, 2017
2a0f381
Add missing single quote (#478)
DavidS May 1, 2019
a77179b
Merge pull request #376 from iamjamestl/run-systemd
May 2, 2019
d7473eb
Update docker volume documentation
benningm May 6, 2019
d93316c
Merge pull request #480 from benningm/master
May 7, 2019
9781179
(MODULES-9034) Fix Ubuntu and Debian tests
eimlav May 7, 2019
b95529d
(MODULES-9035) Fix RedHat acceptance tests
eimlav May 8, 2019
1808b95
(MODULES-9036) Fix Windows acceptance tests
eimlav May 13, 2019
fd094e8
Merge pull request #483 from eimlav/modules-9034
sheenaajay May 15, 2019
d4f1cfb
(MODULES-9029) Update pdk template to 46a1deb
eimlav May 15, 2019
a2fa909
(MODULES-9029) Fix rubocop offenses
eimlav May 16, 2019
afe885c
(MODULES-9029) Fix Windows acceptance tests
eimlav May 16, 2019
9575cfd
Merge pull request #484 from eimlav/modules-9029
sheenaajay May 17, 2019
e25e5e0
(FM-8100) Update minimum supported Puppet version to 5.5.10
eimlav May 22, 2019
3bf6b92
Merge pull request #486 from eimlav/fm-8100
lionce May 22, 2019
b7e0e24
(MODULES-9177) Fix version validation regex
eimlav May 28, 2019
519eb5d
Merge pull request #489 from eimlav/modules-9177
sheenaajay May 29, 2019
76f38e8
(MODULES-9193) Revert part of MODULES-9177
eimlav May 30, 2019
6fee44d
Merge pull request #490 from eimlav/modules-9193
sheenaajay May 30, 2019
70c1421
(FM-8151) Add Windows Server 2019 support
eimlav Jun 5, 2019
9cac9f5
Additional changes to account for incompatible image
eimlav Jun 7, 2019
7bf3ea6
Modify tests to fix permissions issues
eimlav Jun 11, 2019
efd5759
Merge pull request #493 from eimlav/fm-8151
sheenaajay Jun 12, 2019
763fd4c
fix typo
thde Jun 13, 2019
a213541
Merge pull request #496 from thde/patch-1
florindragos Jun 18, 2019
28265e6
Fix #239 local_user permission denied (#497)
thde Jun 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding in type/provider for docker stack (puppetlabs#433)
davejrt authored and sheenaajay committed Feb 18, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 686e2ae621f20a255a561fd990bdd29f388af4e4
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -626,6 +626,8 @@ Please note you should supply your master docker-compose file as the first eleme

If you are using a v3.2 compose file or above on a Docker Swarm cluster, use the `docker::stack` class. Include the file resource before you run the stack command.

NOTE: this define will be deprecated in a future release in favor of the [docker type](#types)

To deploy the stack, add the following code to the manifest file:

```puppet
@@ -927,7 +929,6 @@ docker::plugin {'foo/fooplugin:latest'
ensure => 'absent',
force_remove => true,
}
thub.com
```

## Reference
@@ -974,6 +975,7 @@ thub.com
* docker_compose: A type that represents a docker compose file.
* docker_network: A type that represents a docker network.
* docker_volume: A type that represents a docker volume.
* docker_stack: A type that repsents a docker stack.

### Parameters

@@ -1057,6 +1059,20 @@ Additional options for the volume driver.

The location that the volume is mounted to.

The following parameters are available in the `docker_stack` type:

#### 'bundle_file'

A path to a Distributed Application Bundle file.

#### 'compose_files'

An array containing the docker compose file paths.

#### `up_args`

Arguments to be passed directly to docker stack deploy.

#### Docker class parameters

#### `version`
90 changes: 90 additions & 0 deletions lib/puppet/provider/docker_stack/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# frozen_string_literal: true

require 'deep_merge'

Puppet::Type.type(:docker_stack).provide(:ruby) do
desc 'Support for Puppet running Docker Stacks'

mk_resource_methods
commands docker: 'docker'

def exists?
Puppet.info("Checking for stack #{name}")
stack_services = {}
stack_containers = []
resource[:compose_files].each do |file|
compose_file = YAML.safe_load(File.read(file), [], [], true)
# rubocop:disable Style/StringLiterals
containers = docker([
'ps',
'--format',
"{{.Label \"com.docker.swarm.service.name\"}}-{{.Image}}",
'--filter',
"label=com.docker.stack.namespace=#{name}",
]).split("\n").each do |c|
c.slice!("#{name}_")
end
stack_containers.push(*containers)
stack_containers.uniq!
# rubocop:enable Style/StringLiterals
case compose_file['version']
when %r{^3(\.[0-7])?$}
stack_services.merge!(compose_file['services'])
else
raise(Puppet::Error, "Unsupported docker compose file syntax version \"#{compose_file['version']}\"!")
end
end

if stack_services.count != stack_containers.count
return false
end
counts = Hash[*stack_services.each.map { |key, array|
image = (array['image']) ? array['image'] : get_image(key, stack_services)
Puppet.info("Checking for compose service #{key} #{image}")
["#{key}-#{image}", stack_containers.count("#{key}-#{image}")]
}.flatten]
# No containers found for the project
if counts.empty? ||
# Containers described in the compose file are not running
counts.any? { |_k, v| v.zero? }
false
else
true
end
end

def get_image(service_name, stack_services)
image = stack_services[service_name]['image']
unless image
if stack_services[service_name]['extends']
image = get_image(stack_services[service_name]['extends'], stack_services)
elsif stack_services[service_name]['build']
image = "#{name}_#{service_name}"
end
end
image
end

def create
Puppet.info("Running stack #{name}")
args = ['stack', 'deploy', compose_files, name].insert(1, bundle_file).insert(4, resource[:up_args]).compact
docker(args)
end

def destroy
Puppet.info("Removing docker stack #{name}")
rm_args = ['stack', 'rm', name]
docker(rm_args)
end

def bundle_file
return unless resource[:bundle_file].nil?
resource[:bundle_file].map { |x| ['-c', x] }.flatten
end

def compose_files
resource[:compose_files].map { |x| ['-c', x] }.flatten
end

private
end
33 changes: 33 additions & 0 deletions lib/puppet/type/docker_stack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

Puppet::Type.newtype(:docker_stack) do
@doc = 'A type representing a Docker Stack'

ensurable

newparam(:bundle_file) do
desc 'Path to a Distributed Application Bundle file.'
validate do |value|
raise _('bundle files should be a string') unless value.is_a? String
end
end

newparam(:compose_files, array_matching: :all) do
desc 'An array of Docker Compose Files paths.'
validate do |value|
raise _('compose files should be an array') unless value.is_a? Array
end
end

newparam(:up_args) do
desc 'Arguments to be passed directly to docker stack deploy.'
validate do |value|
raise _('up_args should be a String') unless value.is_a? String
end
end

newparam(:name) do
isnamevar
desc 'The name of the stack'
end
end
3 changes: 3 additions & 0 deletions manifests/stack.pp
Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@

include docker::params

deprecation('docker::stack','The docker stack define type will be deprecated in a future release. Please migrate to the docker_stack type/provider.')


$docker_command = "${docker::params::docker_command} stack"

if $::osfamily == 'windows' {
22 changes: 9 additions & 13 deletions spec/acceptance/stack_spec.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
tmp_path = 'C:/cygwin64/tmp'
test_container = 'nanoserver-sac2016'
wait_for_container_seconds = 120

else
docker_args = ''
tmp_path = '/tmp'
@@ -31,8 +32,7 @@ class { 'docker': #{docker_args} }

context 'Creating stack' do
let(:install) {"
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml'],
ensure => present,
}"
@@ -60,21 +60,20 @@ class { 'docker': #{docker_args} }

context 'Destroying stack' do
let(:install) {"
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml'],
ensure => present,
}"
}
let(:destroy) {"
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml'],
ensure => absent,
}"
}
it 'should run successfully' do
apply_manifest(destroy, :catch_failures=>true)
sleep 10
end

it 'should be idempotent' do
@@ -94,8 +93,7 @@ class { 'docker': #{docker_args} }

before(:all) do
@install_code = <<-code
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml', '#{tmp_path}/docker-stack-override.yml'],
ensure => present,
}
@@ -113,8 +111,7 @@ class { 'docker': #{docker_args} }
context 'Destroying project with multiple compose files' do
before(:all) do
@install_code = <<-code
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml', '#{tmp_path}/docker-stack-override.yml'],
ensure => present,
}
@@ -123,15 +120,14 @@ class { 'docker': #{docker_args} }
apply_manifest(@install_code, :catch_failures=>true)

@destroy_code = <<-code
docker::stack { 'web':
stack_name => 'web',
docker_stack { 'web':
compose_files => ['#{tmp_path}/docker-stack.yml', '#{tmp_path}/docker-stack-override.yml'],
ensure => absent,
}
code

apply_manifest(@destroy_code, :catch_failures=>true)
sleep 10 # wait for containers to stop
sleep 10# wait for containers to stop
end

it 'should be idempotent' do
36 changes: 36 additions & 0 deletions spec/unit/docker_stack_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'

stack = Puppet::Type.type(:docker_stack)

describe stack do

let :params do
[
:name,
:provider,
:up_args,
]
end

let :properties do
[
:ensure,
]
end

it 'should have expected properties' do
properties.each do |property|
expect(stack.properties.map(&:name)).to be_include(property)
end
end

it 'should have expected parameters' do
params.each do |param|
expect(stack.parameters).to be_include(param)
end
end

it 'should require up_args to be a string' do
expect(stack).to require_string_for('up_args')
end
end