Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/unreleased/Fixed-20250613-172229.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Fix issue with missing DatabaseID during validation and ensure Docker image is pulled before container run to prevent volume validation failures.
time: 2025-06-13T17:22:29.424057+05:30
3 changes: 3 additions & 0 deletions server/internal/api/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ func apiToDatabaseSpec(id, tID *string, apiSpec *api.DatabaseSpec) (*database.Sp
if err != nil {
return nil, fmt.Errorf("failed to parse database ID: %w", err)
}
if databaseID == uuid.Nil {
databaseID = uuid.New()
}
var tenantID *uuid.UUID
if tID != nil {
parsedTenantID, err := parseUUID(*tID)
Expand Down
2 changes: 1 addition & 1 deletion server/internal/database/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewService(orchestrator Orchestrator, store *Store, hostSvc *host.Service)

func (s *Service) CreateDatabase(ctx context.Context, spec *Spec) (*Database, error) {
if spec.DatabaseID == uuid.Nil {
spec.DatabaseID = uuid.New()
return nil, fmt.Errorf("DatabaseID must be set before creating a Database")
}
specExists, err := s.store.Spec.ExistsByKey(spec.DatabaseID).Exec(ctx)
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions server/internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/swarm"
Expand Down Expand Up @@ -84,6 +85,14 @@ type ContainerRunOptions struct {
}

func (d *Docker) ContainerRun(ctx context.Context, opts ContainerRunOptions) (string, error) {
if opts.Config != nil {
if opts.Config.Image == "" {
return "", errors.New("image must be specified in container config")
}
if err := d.ensureDockerImage(ctx, opts.Config.Image); err != nil {
return "", fmt.Errorf("failed to ensure docker image %q: %w", opts.Config.Image, err)
}
}
resp, err := d.client.ContainerCreate(ctx, opts.Config, opts.Host, opts.Net, opts.Platform, opts.Name)
if err != nil {
return "", fmt.Errorf("failed to create container: %w", err)
Expand Down Expand Up @@ -453,6 +462,31 @@ func (d *Docker) Shutdown() error {
return nil
}

func (d *Docker) ensureDockerImage(ctx context.Context, img string) error {
// Check if the image exists
images, err := d.client.ImageList(ctx, image.ListOptions{Filters: filters.NewArgs(filters.Arg("reference", img))})
if err != nil {
return fmt.Errorf("failed to list images: %w", err)
}
if len(images) > 0 {
return nil // Image already exists
}

// Pull the image if it doesn't exist
reader, err := d.client.ImagePull(ctx, img, image.PullOptions{})
if err != nil {
return fmt.Errorf("failed to pull image %q: %w", img, err)
}
defer reader.Close()

// Read the output from the pull operation
if _, err := io.Copy(io.Discard, reader); err != nil {
return fmt.Errorf("failed to read image pull output: %w", err)
}

return nil
}

type NetworkInfo struct {
Name string
ID string
Expand Down