Skip to content

Commit

Permalink
handle SIGINT better during the creation process
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Oct 17, 2022
1 parent 3390f62 commit b42c4d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 13 additions & 8 deletions internal/infra/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,29 @@ func NewProxy(ctx context.Context, cli *client.Client, params *RunParams, nets .
if err != nil {
return nil, fmt.Errorf("failed to create proxy container: %w", err)
}

proxy := &Proxy{
cli: cli,
containerID: proxyContainer.ID,
containerName: hostName,
url: fmt.Sprintf("http://%s:1080", hostName),
CertPath: certPath,
proxyConfigPath: proxyConfigPath,
}

for _, n := range nets {
if err := cli.NetworkConnect(ctx, n.ID, proxyContainer.ID, &network.EndpointSettings{}); err != nil {
_ = proxy.Close()
return nil, fmt.Errorf("failed to connect to network: %w", err)
}
}

if err := cli.ContainerStart(ctx, proxyContainer.ID, types.ContainerStartOptions{}); err != nil {
_ = proxy.Close()
return nil, fmt.Errorf("failed to start container: %w", err)
}

return &Proxy{
cli: cli,
containerID: proxyContainer.ID,
containerName: hostName,
url: fmt.Sprintf("http://%s:1080", hostName),
CertPath: certPath,
proxyConfigPath: proxyConfigPath,
}, nil
return proxy, nil
}

func (p *Proxy) TailLogs(ctx context.Context, cli *client.Client) {
Expand Down
9 changes: 5 additions & 4 deletions internal/infra/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ func NewUpdater(ctx context.Context, cli *client.Client, net *Networks, params *
return nil, fmt.Errorf("failed to create updater container: %w", err)
}

if err := cli.ContainerStart(ctx, updaterContainer.ID, types.ContainerStartOptions{}); err != nil {
return nil, fmt.Errorf("failed to start updater container: %w", err)
}

updater := &Updater{
cli: cli,
containerID: updaterContainer.ID,
Expand All @@ -123,6 +119,11 @@ func NewUpdater(ctx context.Context, cli *client.Client, net *Networks, params *
inputPath: inputPath,
}

if err := cli.ContainerStart(ctx, updaterContainer.ID, types.ContainerStartOptions{}); err != nil {
updater.Close()
return nil, fmt.Errorf("failed to start updater container: %w", err)
}

return updater, nil
}

Expand Down

0 comments on commit b42c4d7

Please sign in to comment.