Skip to content

Commit

Permalink
fix: explicitly need to pull docker images, fixes #1525
Browse files Browse the repository at this point in the history
  • Loading branch information
gak committed May 17, 2024
1 parent ce6abd2 commit 3d32ecd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/ftl/cmd_schema_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func (s *schemaImportCmd) setup(ctx context.Context) error {
}
_ = l.Close()

err = container.Pull(ctx, "ollama/ollama")
if err != nil {
return err
}

err = container.Run(ctx, "ollama/ollama", ollamaContainerName, s.OllamaPort, 11434, optional.Some(ollamaVolume))
if err != nil {
return err
Expand Down
35 changes: 35 additions & 0 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ func DoesExist(ctx context.Context, name string) (bool, error) {
return len(containers) > 0, nil
}

// Pull pulls the given image.
func Pull(ctx context.Context, image string) error {
cli, err := dockerClient.Get(ctx)
if err != nil {
return err
}

reader, err := cli.ImagePull(ctx, image, types.ImagePullOptions{})
if err != nil {
return fmt.Errorf("failed to pull %s image: %w", image, err)
}
defer reader.Close()

_, err = io.Copy(os.Stderr, reader)
if err != nil {
return fmt.Errorf("failed to stream pull: %w", err)
}

return nil
}

// Run starts a new detached container with the given image, name, port map, and (optional) volume mount.
func Run(ctx context.Context, image, name string, hostPort, containerPort int, volume optional.Option[string]) error {
cli, err := dockerClient.Get(ctx)
Expand Down Expand Up @@ -88,6 +109,20 @@ func RunDB(ctx context.Context, name string, port int) error {
return err
}

const containerName = "postgres"

exists, err := DoesExist(ctx, containerName)
if err != nil {
return err
}

if !exists {
err = Pull(ctx, "postgres:latest")
if err != nil {
return err
}
}

config := container.Config{
Image: "postgres:latest",
Env: []string{"POSTGRES_PASSWORD=secret"},
Expand Down

0 comments on commit 3d32ecd

Please sign in to comment.