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

driver/docker: pull image with digest #4298

Merged
merged 5 commits into from
May 21, 2018
Merged

driver/docker: pull image with digest #4298

merged 5 commits into from
May 21, 2018

Conversation

justenwalker
Copy link
Contributor

@justenwalker justenwalker commented May 14, 2018

Fixes #4290
Fixes #4211

Add digest support to the docker driver image config. This commit
factors out some common code to print the repo:tag (dockerImageRef) for
events/logs as well as parsing the image to retreive the repo,tag
(parseDockerImage) so that the results are consistent/sane for both
repo:tag and repo@sha256:... references.

When pulling an image with a digest, the tag is blank and the repo
contains the digest. See:
https://github.com/fsouza/go-dockerclient/blob/master/image_test.go#L471

GH #4290

Add digest support to the docker driver image config. This commit
factors out some common code to print the repo:tag (dockerImageRef) for
events/logs as well as parsing the image to retreive the repo,tag
(parseDockerImage) so that the results are consistent/sane for both
repo:tag and repo@sha256:... references.

When pulling an image with a digest, the tag is blank and the repo
contains the digest. See:
https://github.com/fsouza/go-dockerclient/blob/master/image_test.go#L471

func parseDockerImage(image string) (repo, tag string) {
repo, tag = docker.ParseRepositoryTag(image)
if tag == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

if tag != "" { return repo, tag }

reduce indentation and make it explicit whats returned :)

if tag != "" {
return repo, tag
}
if i := strings.IndexRune(image, '@'); i > -1 { // Has digest (@sha256:...)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a risk of someone using @ in their repo name/url/tag? wonder if its more safe to actually sniff for @sha256: in its entirely - not aware of the docker repo spec if its invalid or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure that '@' is not a valid repo name. The official spec is codified here:
https://github.com/docker/distribution/blob/master/reference/regexp.go

Copy link
Member

@nickethier nickethier left a comment

Choose a reason for hiding this comment

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

I commented on a couple of nit picky things with tests. Overall looks great. Thanks for your contribution to nomad!

t.Run(test.Image, func(t *testing.T) {
repo, tag := parseDockerImage(test.Image)
if repo != test.Repo {
t.Errorf("expected repo '%s' but got '%s'", test.Repo, repo)
Copy link
Member

Choose a reason for hiding this comment

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

Could you change these to use the require package: https://godoc.org/github.com/stretchr/testify/require#Equal


waitForExist(t, client, handle)

_, err := client.InspectContainer(handle.ContainerID())
Copy link
Member

Choose a reason for hiding this comment

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

Check that the inspected container's image is whats expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do this, but the remote digest won't match the local digest due to "reasons" so I'll have to just hard-code in another id for the local digest to match against. Not ideal

waitForExist(t, client, handle)

_, err := client.InspectContainer(handle.ContainerID())
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

return repo, tag
}

func dockerImageRef(repo string, tag string) string {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding a quick test for this. Could even just be a line in TestParseDockerImage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TestDockerImageRef added

@dadgar dadgar merged commit d7fd033 into hashicorp:master May 21, 2018
@justenwalker justenwalker deleted the docker-driver-digest-tags branch May 21, 2018 22:22
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants