Skip to content

Image deploy hooks#1881

Merged
ggarnier merged 14 commits intomasterfrom
image-deploy-hooks
Dec 13, 2017
Merged

Image deploy hooks#1881
ggarnier merged 14 commits intomasterfrom
image-deploy-hooks

Conversation

@ggarnier
Copy link
Copy Markdown
Member

Set deploy hooks when deploying from an image

waiter, err := client.AttachToContainerNonBlocking(attachOptions)
if err != nil {
return err
return "", err
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.

We should return cont.ID both here and after a StartContainer error to allow the container to be removed even after a failure. Another possibility is removing the container inside this function if we are to return an error.


return map[string]interface{}{
"healthcheck": yaml.Healthcheck,
"hooks": map[string]interface{}{
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 think having "hooks": yaml.Hooks, would work here.

cmd := fmt.Sprintf("(cat %s/tsuru.yml || cat %s/tsuru.yaml || cat %s/app.yml || cat %s/app.yaml || true) 2>/dev/null", path, path, path, path)
var buf bytes.Buffer
err := runCommandInContainer(client, evt, imageID, cmd, app, &buf, nil)
containerID, err := runCommandInContainer(client, evt, imageID, cmd, app, &buf, nil)
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.

What do you think about moving the defer RemoveContainer(containerID) call to this function instead of returning the ID and making the parent remove it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The problem is that I call runCommandInContainer also in runBuildHooks function, and I can't remove it there, because it's commited

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.

Oh right, you can only remove it after it's been pushed. 👍

repo, tag := splitImageName(imageID)
opts := docker.CommitContainerOptions{
Container: containerID,
Repository: repo,
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 think the only reason why Repository and Tag is needed here is because of a bug in docker-cluster, as it isn't storing information about the image if they are not present. Let's leave it like this for now but we may be able to simplify this in the future.

@ggarnier
Copy link
Copy Markdown
Member Author

@cezarsa PTAL

fmt.Fprintf(evt, " ---> Running %q\n", cmd)
containerID, err := runCommandInContainer(client, evt, imageID, cmd, app, evt, evt)
if err != nil {
return "", err
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.

Return containerID here to ensure removal in case of partial failure.

@ggarnier ggarnier merged commit 8afb354 into master Dec 13, 2017
@ggarnier ggarnier deleted the image-deploy-hooks branch December 13, 2017 13:54
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.

3 participants