-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
50 lines (45 loc) · 1.32 KB
/
controller.go
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
44
45
46
47
48
49
50
package controller
import (
"context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/voltaire/render-controller/renderer"
)
type Controller struct {
Docker *client.Client
}
func (ctrl *Controller) StartForRender(ctx context.Context, cfg renderer.Config, backupTarballUri string) error {
container, err := ctrl.Docker.ContainerCreate(ctx, &container.Config{
Image: cfg.RenderControllerImage,
Env: renderer.BuildContainerEnv(cfg, backupTarballUri),
Labels: map[string]string{
"service": "renderer",
"world": cfg.OverworldName,
"function": "render-controller",
},
}, &container.HostConfig{
AutoRemove: true,
LogConfig: container.LogConfig{
Type: "awslogs",
Config: map[string]string{
"awslogs-group": "render-controller/controller",
"awslogs-create-group": "true",
"awslogs-region": cfg.AwsRegion,
},
},
Mounts: []mount.Mount{
{
Type: mount.TypeBind,
Source: "/var/run/docker.sock",
Target: "/var/run/docker.sock",
},
},
}, &network.NetworkingConfig{}, "")
if err != nil {
return err
}
return ctrl.Docker.ContainerStart(ctx, container.ID, types.ContainerStartOptions{})
}