forked from arcalot/arcaflow-engine-deployer-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer.go
43 lines (36 loc) · 919 Bytes
/
container.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
package docker
import (
"context"
"fmt"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
type connectorContainer struct {
id string
hijackedResponse *types.HijackedResponse
cli *client.Client
multiplexedReader
}
func (c connectorContainer) Write(p []byte) (n int, err error) {
return c.hijackedResponse.Conn.Write(p)
}
func (c connectorContainer) Close() error {
if c.hijackedResponse != nil {
c.hijackedResponse.Close()
_ = c.hijackedResponse.CloseWrite()
}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
if err := c.cli.ContainerRemove(ctx, c.id, types.ContainerRemoveOptions{
Force: true,
}); err != nil {
if !client.IsErrNotFound(err) {
return fmt.Errorf("failed to remove container %s (%w)", c.id, err)
}
}
return nil
}
func (c connectorContainer) ID() string {
return c.id
}