Skip to content

builder,provision: adding the latest tag to deploy image#1973

Merged
guilhermebr merged 4 commits into
tsuru:masterfrom
jonnyguio:latest_tag
Mar 26, 2018
Merged

builder,provision: adding the latest tag to deploy image#1973
guilhermebr merged 4 commits into
tsuru:masterfrom
jonnyguio:latest_tag

Conversation

@jonnyguio

Copy link
Copy Markdown
Contributor

This PR is related to #1945. Now, whenever you deploy a new version of your app, you can pull the last image using the tag latest.

Comment thread provision/docker/container/container.go Outdated
for i, tag := range tags {
opts := docker.CommitContainerOptions{Container: c.ID, Repository: repository, Tag: tag}
done := limiter.Start(c.HostAddr)
image, err := client.CommitContainer(opts)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Calling client.CommitContainer for each tag is not necessary and it may cause a performance hit, it should be called only once (for the original tag), after the Commit is done we should call client.TagImage to tag the latest tag. This will also allow us to move the commit logic and the image size logic to outside the for loop (removing the ugly if i == 0 block).
Only the PushImage logic should be inside this for loop.

Comment thread provision/kubernetes/deploy.go Outdated
}
params.cmds = cmds
destinationImageWithoutTag := params.destinationImage
parts := strings.Split(params.destinationImage, ":")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should use the more robust image.SplitImageName (in the app/image pkg) function to split the image as it already handle some corner cases.

echo " ---> Sending image to repository (${sz})"
docker push "${img}"
`, params.destinationImage, baseName, buildIntercontainerStatus, buildIntercontainerDone),
strings.Join(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick, moving this line and the line below it to the line above should allow us to preserve the old indentation level shortening the diff for this PR. Something like:

"sh", "-ec", strings.Join(append([]string{fmt.Sprintf(`
...
`, ...

@cezarsa cezarsa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've just noticed that this PR is missing changes to the swarm provisioner. It'll be similar to the docker provisioner but somewhere around

func commitPushBuildImage(client *docker.Client, img, contID string, app provision.App) (string, error) {
parts := strings.Split(img, ":")
repository := strings.Join(parts[:len(parts)-1], ":")
tag := parts[len(parts)-1]
_, err := client.CommitContainer(docker.CommitContainerOptions{
Container: contID,
Repository: repository,
Tag: tag,
})
if err != nil {
return "", errors.WithStack(err)
}
err = dockercommon.PushImage(client, repository, tag, dockercommon.RegistryAuthConfig())
if err != nil {
return "", err
}
return img, nil
}

Comment thread provision/swarm/provisioner_test.go Outdated
attached := s.attachRegister(c, s.clusterSrv, true, a)
tags := []string{}
s.clusterSrv.CustomHandler("/images/.*/push", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Assert(r.URL.Path, check.Equals, "/images/"+fmt.Sprintf("registry.tsuru.io/tsuru/app-myapp")+"/push")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for Sprintf() and concat here, just make it a single string.

@jonnyguio jonnyguio Mar 26, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

true. fixed that

@guilhermebr guilhermebr merged commit db61391 into tsuru:master Mar 26, 2018
@jonnyguio jonnyguio deleted the latest_tag branch March 26, 2018 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants