Skip to content

Commit

Permalink
merge with upstream (#3)
Browse files Browse the repository at this point in the history
* Fix docker_container.tag to properly fetch from image name (inspec#2052)

Fixes inspec#2051

Images with repos containing port numbers will have multiple colons.

Signed-off-by: Matt Kulka <mkulka@parchment.com>

* Bump version to 1.32.3 by Chef Expeditor

* Bump project minor version, bump train dependency version (inspec#2058)

Bumping InSpec's minor version to 1.33 because a recent PR added
new functionality. Also bumping train to 0.26 to pick up a recent
bug fix.

Signed-off-by: Adam Leff <adam@leff.co>

* Bump version to 1.33.1 by Chef Expeditor

* Update CHANGELOG.md to reflect the promotion of 1.33.1 to stable
  • Loading branch information
aaronlippold committed Aug 12, 2017
1 parent f579733 commit af71bb1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 19 deletions.
21 changes: 11 additions & 10 deletions CHANGELOG.md
@@ -1,20 +1,22 @@
# Change Log

<!-- latest_release 1.32.2 -->
## [v1.32.2](https://github.com/chef/inspec/tree/v1.32.2) (2017-08-07)

#### Features & Enhancements
- New &#39;be_in&#39; matcher for matching against values in a list [#2022](https://github.com/chef/inspec/pull/2022) ([rx294](https://github.com/rx294))
<!-- latest_release -->
<!-- latest_release -->

<!-- release_rollup since=1.32.1 -->
### Changes since 1.32.1 release
<!-- release_rollup -->
<!-- release_rollup -->

<!-- latest_stable_release -->
## [v1.33.1](https://github.com/chef/inspec/tree/v1.33.1) (2017-08-10)

#### Features & Enhancements
- New &#39;be_in&#39; matcher for matching against values in a list [#2022](https://github.com/chef/inspec/pull/2022) ([rx294](https://github.com/rx294)) <!-- 1.32.2 -->
<!-- release_rollup -->
- New &#39;be_in&#39; matcher for matching against values in a list [#2022](https://github.com/chef/inspec/pull/2022) ([rx294](https://github.com/rx294))

#### Merged Pull Requests
- Fix docker_container.tag to use last element of image [#2052](https://github.com/chef/inspec/pull/2052) ([mattlqx](https://github.com/mattlqx))
- Bump project minor version, bump train dependency version [#2058](https://github.com/chef/inspec/pull/2058) ([adamleff](https://github.com/adamleff))
<!-- latest_stable_release -->

## [v1.32.1](https://github.com/chef/inspec/tree/v1.32.1) (2017-08-03)

#### Merged Pull Requests
Expand All @@ -25,7 +27,6 @@
- Fix issue when xinetd.conf does not end in newline [#2040](https://github.com/chef/inspec/pull/2040) ([kareiva](https://github.com/kareiva))
- catch newline issues in xinet.d [#2043](https://github.com/chef/inspec/pull/2043) ([arlimus](https://github.com/arlimus))
- Prep for 1.32.0 release [#2046](https://github.com/chef/inspec/pull/2046) ([adamleff](https://github.com/adamleff))
<!-- latest_stable_release -->



Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.32.2
1.33.1
2 changes: 1 addition & 1 deletion inspec.gemspec
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.1'

spec.add_dependency 'train', '>=0.24.0', '<1.0'
spec.add_dependency 'train', '~> 0.26'
spec.add_dependency 'thor', '~> 0.19'
spec.add_dependency 'json', '>= 1.8', '< 3.0'
spec.add_dependency 'rainbow', '~> 2'
Expand Down
2 changes: 1 addition & 1 deletion lib/inspec/version.rb
Expand Up @@ -4,5 +4,5 @@
# author: Christoph Hartmann

module Inspec
VERSION = '1.32.2'.freeze
VERSION = '1.33.1'.freeze
end
16 changes: 14 additions & 2 deletions lib/resources/docker_container.rb
Expand Up @@ -74,11 +74,13 @@ def image
end

def repo
image.split(':')[0] unless image.nil?
return if image_name_from_image.nil?
image_name_from_image.split(':')[0]
end

def tag
image.split(':')[1] unless image.nil?
return if image_name_from_image.nil?
image_name_from_image.split(':')[1]
end

def to_s
Expand All @@ -88,6 +90,16 @@ def to_s

private

def image_name_from_image
return if image.nil?
# possible image names include:
# alpine
# ubuntu:14.04
# repo.example.com:5000/ubuntu
# repo.example.com:5000/ubuntu:1404
image.include?('/') ? image.split('/')[1] : image
end

def container_info
return @info if defined?(@info)
opts = @opts
Expand Down
1 change: 1 addition & 0 deletions test/unit/mock/cmd/docker-images
@@ -1,3 +1,4 @@
{ "id": "sha256:4a415e3663882fbc554ee830889c68a33b3585503892cc718a4698e91ef2a526", "repository": "alpine", "tag": "latest", "size": "3.99 MB", "digest": "\u003cnone\u003e", "createdat": "2017-03-03 21:32:37 +0100 CET", "createdsize": "7 weeks" }
{ "id": "sha256:978d85d02b87aea199e4ae8664f6abf32fdea331884818e46b8a01106b114cee", "repository": "debian", "tag": "8", "size": "123 MB", "digest": "\u003cnone\u003e", "createdat": "2017-02-27 21:34:37 +0100 CET", "createdsize": "7 weeks" }
{ "id": "sha256:0ef2e08ed3fabfc44002ccb846c4f2416a2135affc3ce39538834059606f32dd", "repository": "ubuntu", "tag": "16.04", "size": "130 MB", "digest": "\u003cnone\u003e", "createdat": "2017-02-27 20:42:10 +0100 CET", "createdsize": "7 weeks" }
{ "id": "sha256:c4e5744dbe11a4f1970ba36d0aa3944c347ab232bb58fb86b240f1bb18a360c2", "repository": "repo.example.com:5000/ubuntu", "tag": "14.04", "size": "125 MB", "digest": "\u003cnone\u003e", "createdat": "2017-02-27 20:42:10 +0100 CET", "createdsize": "7 weeks" }
2 changes: 2 additions & 0 deletions test/unit/mock/cmd/docker-ps-a
@@ -1,2 +1,4 @@
{"Command":"\"/bin/bash\"","CreatedAt":"2017-04-24 10:29:12 +0200 CEST","ID":"3def9aa450f8bd772c3d5b07e27ec934e5f58575e955367a0aca2d93e0687536","Image":"ubuntu:12.04","Labels":"","LocalVolumes":"0","Mounts":"","Names":"sleepy_khorana","Networks":"bridge","Ports":"","RunningFor":"29 minutes","Size":"0 B","Status":"Exited (127) 2 seconds ago"}
{"Command":"\"/bin/sh\"","CreatedAt":"2017-04-22 22:44:42 +0200 CEST","ID":"d94f854370d2b02912e8fc636502bc72b74fbd567a7eba3fc6a52045bb28904e","Image":"alpine","Labels":"","LocalVolumes":"0","Mounts":"","Names":"laughing_austin","Networks":"bridge","Ports":"","RunningFor":"36 hours","Size":"0 B","Status":"Exited (0) 35 hours ago"}
{"Command":"\"/bin/sh\"","CreatedAt":"2017-08-03 12:56:03 +0200 CEST","ID":"5a83c301f30ccd48579a74a84af6fdd0c0e0d66aacc7bb52abfa2ba2544c6c0c","Image":"repo.example.com:5000/ubuntu:14.04","Labels":"","LocalVolumes":"0","Mounts":"","Names":"heuristic_almeida","Networks":"bridge","Ports":"","RunningFor":"5 hours","Size":"0 B","Status":"Exited (0) 24 hours ago"}
{"Command":"\"/bin/sh\"","CreatedAt":"2017-08-03 12:56:03 +0200 CEST","ID":"5a83c301f30ccd48579a74a84af6fdd0c0e0d66aacc7bb52abfa2ba2544c6c0c","Image":"repo.example.com:5000/ubuntu","Labels":"","LocalVolumes":"0","Mounts":"","Names":"laughing_lamport","Networks":"bridge","Ports":"","RunningFor":"5 hours","Size":"0 B","Status":"Exited (0) 24 hours ago"}
12 changes: 12 additions & 0 deletions test/unit/resources/docker_container_test.rb
Expand Up @@ -26,6 +26,18 @@
_(resource.ports).must_equal ''
end

it 'check image containing repo with port and tag gives correct tag' do
resource = load_resource('docker_container', 'heuristic_almeida')
_(resource.image).must_equal 'repo.example.com:5000/ubuntu:14.04'
_(resource.tag).must_equal '14.04'
end

it 'check image containing repo with port and no tag gives correct tag' do
resource = load_resource('docker_container', 'laughing_lamport')
_(resource.image).must_equal 'repo.example.com:5000/ubuntu'
_(resource.tag).must_be_nil
end

it 'prints as a docker resource' do
resource = load_resource('docker_container', 'laughing_austin')
resource.to_s.must_equal 'Docker Container laughing_austin'
Expand Down
8 changes: 4 additions & 4 deletions test/unit/resources/docker_test.rb
Expand Up @@ -8,14 +8,14 @@
describe 'docker' do
it 'check docker container parsing' do
resource = load_resource('docker')
_(resource.containers.ids).must_equal ['3def9aa450f8bd772c3d5b07e27ec934e5f58575e955367a0aca2d93e0687536', 'd94f854370d2b02912e8fc636502bc72b74fbd567a7eba3fc6a52045bb28904e']
_(resource.containers.names).must_equal ['sleepy_khorana', 'laughing_austin']
_(resource.containers.ids).must_equal ['3def9aa450f8bd772c3d5b07e27ec934e5f58575e955367a0aca2d93e0687536', 'd94f854370d2b02912e8fc636502bc72b74fbd567a7eba3fc6a52045bb28904e', '5a83c301f30ccd48579a74a84af6fdd0c0e0d66aacc7bb52abfa2ba2544c6c0c', '5a83c301f30ccd48579a74a84af6fdd0c0e0d66aacc7bb52abfa2ba2544c6c0c']
_(resource.containers.names).must_equal ['sleepy_khorana', 'laughing_austin', 'heuristic_almeida', 'laughing_lamport']
end

it 'check docker image parsing' do
resource = load_resource('docker')
_(resource.images.ids).must_equal ['sha256:4a415e3663882fbc554ee830889c68a33b3585503892cc718a4698e91ef2a526', 'sha256:978d85d02b87aea199e4ae8664f6abf32fdea331884818e46b8a01106b114cee', 'sha256:0ef2e08ed3fabfc44002ccb846c4f2416a2135affc3ce39538834059606f32dd']
_(resource.images.repositories).must_equal ["alpine", "debian", "ubuntu"]
_(resource.images.ids).must_equal ['sha256:4a415e3663882fbc554ee830889c68a33b3585503892cc718a4698e91ef2a526', 'sha256:978d85d02b87aea199e4ae8664f6abf32fdea331884818e46b8a01106b114cee', 'sha256:0ef2e08ed3fabfc44002ccb846c4f2416a2135affc3ce39538834059606f32dd', 'sha256:c4e5744dbe11a4f1970ba36d0aa3944c347ab232bb58fb86b240f1bb18a360c2']
_(resource.images.repositories).must_equal ["alpine", "debian", "ubuntu", "repo.example.com:5000/ubuntu"]
end

it 'check docker version parsing' do
Expand Down

0 comments on commit af71bb1

Please sign in to comment.