-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker_service_deploy.go
More file actions
43 lines (32 loc) · 988 Bytes
/
docker_service_deploy.go
File metadata and controls
43 lines (32 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"errors"
"github.com/docker/docker/api/types/swarm"
"github.com/fsouza/go-dockerclient"
)
type DockerServiceDeploy struct {
client *docker.Client
}
func (d DockerServiceDeploy) Deploy(payload *Payload) error {
s, err := d.client.InspectService(payload.ServiceName)
if err != nil {
return err
}
if !d.isUpdatable(s) {
return errors.New("Service is not labeled as being updatable: set deployer.allowUpdates=true as service label")
}
// Update needs to include the current full spec, as well as the current version number
opts := docker.UpdateServiceOptions{
ServiceSpec: s.Spec,
Version: s.Version.Index,
}
opts.ServiceSpec.TaskTemplate.ContainerSpec.Image = payload.Artifact
// Update by service name doesn't work.
if err := d.client.UpdateService(s.ID, opts); err != nil {
return err
}
return nil
}
func (d DockerServiceDeploy) isUpdatable(s *swarm.Service) bool {
return s.Spec.Labels["deployer.allowUpdates"] == "true"
}