Files
runtime/apps/runner/pkg/services/sandbox.go
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- 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
2025-08-16 23:03:39 -05:00

58 lines
1.3 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package services
import (
"context"
"github.com/hanzoai/runner/pkg/cache"
"github.com/hanzoai/runner/pkg/docker"
"github.com/hanzoai/runner/pkg/models"
"github.com/hanzoai/runner/pkg/models/enums"
)
type SandboxService struct {
cache cache.IRunnerCache
docker *docker.DockerClient
}
func NewSandboxService(cache cache.IRunnerCache, docker *docker.DockerClient) *SandboxService {
return &SandboxService{
cache: cache,
docker: docker,
}
}
func (s *SandboxService) GetSandboxStatesInfo(ctx context.Context, sandboxId string) *models.CacheData {
sandboxState, err := s.docker.DeduceSandboxState(ctx, sandboxId)
if err == nil {
s.cache.SetSandboxState(ctx, sandboxId, sandboxState)
}
data := s.cache.Get(ctx, sandboxId)
if data == nil {
return &models.CacheData{
SandboxState: enums.SandboxStateUnknown,
BackupState: enums.BackupStateNone,
DestructionTime: nil,
}
}
return data
}
func (s *SandboxService) RemoveDestroyedSandbox(ctx context.Context, sandboxId string) error {
info := s.GetSandboxStatesInfo(ctx, sandboxId)
if info != nil && info.SandboxState != enums.SandboxStateDestroyed && info.SandboxState != enums.SandboxStateDestroying {
err := s.docker.Destroy(ctx, sandboxId)
if err != nil {
return err
}
}
return nil
}