feat(webhooks): Add Tag Support (#2871)

* feat(webhooks): Add Tag Support

* feat(webhooks): Add Tag Support
pull/2331/merge
Steven Kang 2019-05-08 10:41:31 +12:00 committed by Anthony Lapenna
parent 7b3ef7f1a2
commit dc9a3de88f
1 changed files with 12 additions and 4 deletions

View File

@ -39,16 +39,18 @@ func (handler *Handler) webhookExecute(w http.ResponseWriter, r *http.Request) *
} else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint with the specified identifier inside the database", err}
}
imageTag, _ := request.RetrieveQueryParameter(r, "tag", true)
switch webhookType {
case portainer.ServiceWebhook:
return handler.executeServiceWebhook(w, endpoint, resourceID)
return handler.executeServiceWebhook(w, endpoint, resourceID, imageTag)
default:
return &httperror.HandlerError{http.StatusInternalServerError, "Unsupported webhook type", portainer.ErrUnsupportedWebhookType}
}
}
func (handler *Handler) executeServiceWebhook(w http.ResponseWriter, endpoint *portainer.Endpoint, resourceID string) *httperror.HandlerError {
func (handler *Handler) executeServiceWebhook(w http.ResponseWriter, endpoint *portainer.Endpoint, resourceID string, imageTag string) *httperror.HandlerError {
dockerClient, err := handler.DockerClientFactory.CreateClient(endpoint, "")
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Error creating docker client", err}
@ -62,8 +64,14 @@ func (handler *Handler) executeServiceWebhook(w http.ResponseWriter, endpoint *p
service.Spec.TaskTemplate.ForceUpdate++
service.Spec.TaskTemplate.ContainerSpec.Image = strings.Split(service.Spec.TaskTemplate.ContainerSpec.Image, "@sha")[0]
if imageTag != "" {
service.Spec.TaskTemplate.ContainerSpec.Image = strings.Split(service.Spec.TaskTemplate.ContainerSpec.Image, ":")[0] + ":" + imageTag
} else {
service.Spec.TaskTemplate.ContainerSpec.Image = strings.Split(service.Spec.TaskTemplate.ContainerSpec.Image, "@sha")[0]
}
_, err = dockerClient.ServiceUpdate(context.Background(), resourceID, service.Version, service.Spec, dockertypes.ServiceUpdateOptions{QueryRegistry: true})
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Error updating service", err}
}