Skip to content

Commit

Permalink
fix: explicitly need to pull docker images, fixes #1525 (#1526)
Browse files Browse the repository at this point in the history
The output is a bit messy but it at least will show progress, rather
than hiding the output.
  • Loading branch information
gak authored May 17, 2024
1 parent 059335a commit 384c2e7
Show file tree
Hide file tree
Showing 2 changed files with 41 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
36 changes: 36 additions & 0 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ 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()

logger := log.FromContext(ctx)
_, err = io.Copy(logger.WriterAt(log.Info), 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 +110,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 384c2e7

Please sign in to comment.