-
Notifications
You must be signed in to change notification settings - Fork 528
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
Image deploy hooks #1881
Image deploy hooks #1881
Conversation
c62d51c
to
ccfcdaf
Compare
builder/docker/builder.go
Outdated
@@ -172,16 +223,50 @@ func runCommandInContainer(client provision.BuilderDockerClient, evt *event.Even | |||
} | |||
waiter, err := client.AttachToContainerNonBlocking(attachOptions) | |||
if err != nil { | |||
return err | |||
return "", err |
There was a problem hiding this comment.
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.
builder/docker/builder.go
Outdated
|
||
return map[string]interface{}{ | ||
"healthcheck": yaml.Healthcheck, | ||
"hooks": map[string]interface{}{ |
There was a problem hiding this comment.
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.
path := defaultArchivePath + "/current" | ||
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
@cezarsa PTAL |
7320cd1
to
266ffed
Compare
fmt.Fprintf(evt, " ---> Running %q\n", cmd) | ||
containerID, err := runCommandInContainer(client, evt, imageID, cmd, app, evt, evt) | ||
if err != nil { | ||
return "", err |
There was a problem hiding this comment.
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.
Set deploy hooks when deploying from an image