mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
- Add main Dockerfile for production builds - Add Dockerfile.runtime for secure code execution - Add Dockerfile.runtime.fixed with improved configuration - Include .dockerignore for build optimization - Add integration documentation and publishing guides - Update API and CLI components for better runtime support - Enhance sandbox and container management features
40 lines
1012 B
Go
40 lines
1012 B
Go
// Copyright 2025 Hanzo Industries Inc.
|
|
// SPDX-License-Identifier: AGPL-3.0
|
|
|
|
package docker
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (d *DockerClient) commitContainer(ctx context.Context, containerId, imageName string) error {
|
|
const maxRetries = 3
|
|
|
|
for attempt := 1; attempt <= maxRetries; attempt++ {
|
|
log.Infof("Committing container %s (attempt %d/%d)...", containerId, attempt, maxRetries)
|
|
|
|
commitResp, err := d.apiClient.ContainerCommit(ctx, containerId, container.CommitOptions{
|
|
Reference: imageName,
|
|
Pause: false,
|
|
})
|
|
if err == nil {
|
|
log.Infof("Container %s committed successfully with image ID: %s", containerId, commitResp.ID)
|
|
return nil
|
|
}
|
|
|
|
if attempt < maxRetries {
|
|
log.Warnf("Failed to commit container %s (attempt %d/%d): %v", containerId, attempt, maxRetries, err)
|
|
continue
|
|
}
|
|
|
|
return fmt.Errorf("failed to commit container after %d attempts: %w", maxRetries, err)
|
|
}
|
|
|
|
return nil
|
|
}
|