Skip to content

Commit ff4ca20

Browse files
Simplify idempotency of proxy boot
1 parent 73890ef commit ff4ca20

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

internal/docker/namespace.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,7 @@ func (n *Namespace) Setup(ctx context.Context) error {
144144
return err
145145
}
146146

147-
if n.proxy.Settings == nil {
148-
if err := n.proxy.Boot(ctx, ProxySettings{}); err != nil {
149-
return err
150-
}
151-
}
152-
153-
return nil
147+
return n.proxy.Boot(ctx, ProxySettings{})
154148
}
155149

156150
func (n *Namespace) EnsureNetwork(ctx context.Context) error {

internal/docker/proxy.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func (p *Proxy) Boot(ctx context.Context, settings ProxySettings) error {
7979
settings.MetricsPort = DefaultMetricsPort
8080
}
8181

82+
info, err := p.namespace.client.ContainerInspect(ctx, p.containerName())
83+
if err == nil {
84+
return p.ensureRunning(ctx, info)
85+
}
86+
if !errdefs.IsNotFound(err) {
87+
return fmt.Errorf("inspecting proxy container: %w", err)
88+
}
89+
8290
reader, err := p.namespace.client.ImagePull(ctx, proxyImage, image.PullOptions{})
8391
if err != nil {
8492
return fmt.Errorf("pulling proxy image: %w", err)
@@ -181,6 +189,25 @@ func (p *Proxy) containerName() string {
181189

182190
// Private
183191

192+
func (p *Proxy) ensureRunning(ctx context.Context, info container.InspectResponse) error {
193+
if !info.State.Running {
194+
if err := p.namespace.client.ContainerStart(ctx, info.ID, container.StartOptions{}); err != nil {
195+
return fmt.Errorf("starting proxy container: %w", err)
196+
}
197+
}
198+
199+
label := info.Config.Labels[labelKey]
200+
if label != "" {
201+
settings, err := UnmarshalProxySettings(label)
202+
if err != nil {
203+
return fmt.Errorf("unmarshalling proxy settings: %w", err)
204+
}
205+
p.Settings = &settings
206+
}
207+
208+
return nil
209+
}
210+
184211
func (p *Proxy) deployArgs(opts DeployOptions) []string {
185212
args := []string{"kamal-proxy", "deploy", opts.AppName, "--target", opts.Target, "--deploy-timeout", deployTimeout}
186213

0 commit comments

Comments
 (0)