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

Fix docker_container.tag to use last element of image #2052

Merged
merged 1 commit into from
Aug 10, 2017
Merged

Fix docker_container.tag to use last element of image #2052

merged 1 commit into from
Aug 10, 2017

Conversation

mattlqx
Copy link
Contributor

@mattlqx mattlqx commented Aug 3, 2017

Fixes #2051

Images with repos containing port numbers will have multiple colons.

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

Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great bugfix thank you @mattlqx !!

@@ -78,7 +78,7 @@ def repo
end

def tag
image.split(':')[1] unless image.nil?
image.split(':')[-1] unless image.nil? || !image.index(':')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerryaldrichiii added the suggestion to change this from index to include? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting on the colon like this could potentially introduce a problem if a non-default repohost was present but no tag was present. For example, if we received docker ps output that included: repo.example.com:5000/ubuntu, the tag we'd return would be 5000/ubuntu

I'd rather see us treat the non-default repo host as a standalone unit and split on /, and we need to fix both #repo and #tag... perhaps something like this:

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

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

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

What do you think, @mattlqx?

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mattlqx and thanks for your PR!

Thanks for finding this bug and proposing a fix. I have a small concern about splitting on a colon for a particular edge case, and I've left a comment accordingly. Please let me know what you think.

@@ -78,7 +78,7 @@ def repo
end

def tag
image.split(':')[1] unless image.nil?
image.split(':')[-1] unless image.nil? || !image.index(':')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting on the colon like this could potentially introduce a problem if a non-default repohost was present but no tag was present. For example, if we received docker ps output that included: repo.example.com:5000/ubuntu, the tag we'd return would be 5000/ubuntu

I'd rather see us treat the non-default repo host as a standalone unit and split on /, and we need to fix both #repo and #tag... perhaps something like this:

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

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

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

What do you think, @mattlqx?

Fixes #2051

Images with repos containing port numbers will have multiple colons.

Signed-off-by: Matt Kulka <mkulka@parchment.com>
@mattlqx
Copy link
Contributor Author

mattlqx commented Aug 4, 2017

Thanks for bringing up this additional case. Your suggestion works well, so let's go with that. I've added an additional test case for it as well.

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first PR to InSpec, @mattlqx! This LGTM. 👍

@adamleff adamleff requested a review from a team August 4, 2017 15:43
@adamleff adamleff added the Type: Bug Feature not working as expected label Aug 4, 2017
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix @mattlqx

@chris-rock chris-rock merged commit 0fc870d into inspec:master Aug 10, 2017
aaronlippold added a commit to aaronlippold/inspec that referenced this pull request Aug 12, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants