diff --git a/internal/infra/proxy.go b/internal/infra/proxy.go index 1efc075..2a99888 100644 --- a/internal/infra/proxy.go +++ b/internal/infra/proxy.go @@ -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) { diff --git a/internal/infra/updater.go b/internal/infra/updater.go index 7e98217..9a09aae 100644 --- a/internal/infra/updater.go +++ b/internal/infra/updater.go @@ -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, @@ -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 }