Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions pkg/cli/baseimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/replicate/cog/pkg/config"
"github.com/replicate/cog/pkg/docker"
"github.com/replicate/cog/pkg/docker/command"
"github.com/replicate/cog/pkg/dockercontext"
"github.com/replicate/cog/pkg/dockerfile"
"github.com/replicate/cog/pkg/global"
Expand Down Expand Up @@ -110,6 +111,8 @@ func newBaseImageBuildCommand() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

dockerClient := docker.NewDockerCommand()

generator, err := baseImageGeneratorFromFlags()
if err != nil {
return err
Expand All @@ -125,8 +128,16 @@ func newBaseImageBuildCommand() *cobra.Command {
}
baseImageName := dockerfile.BaseImageName(baseImageCUDAVersion, baseImagePythonVersion, baseImageTorchVersion)

err = docker.Build(ctx, cwd, dockerfileContents, baseImageName, []string{}, buildNoCache, buildProgressOutput, config.BuildSourceEpochTimestamp, dockercontext.StandardBuildDirectory, nil)
if err != nil {
buildOpts := command.ImageBuildOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is such an amazing change, thanks for doing this!

WorkingDir: cwd,
DockerfileContents: dockerfileContents,
ImageName: baseImageName,
NoCache: buildNoCache,
ProgressOutput: buildProgressOutput,
Epoch: &config.BuildSourceEpochTimestamp,
ContextDir: dockercontext.StandardBuildDirectory,
}
if err := dockerClient.ImageBuild(ctx, buildOpts); err != nil {
return err
}
fmt.Println("Successfully built image: " + baseImageName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func cmdPredict(cmd *cobra.Command, args []string) error {
return err
}
} else {
if imageName, err = image.BuildBase(ctx, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput); err != nil {
if imageName, err = image.BuildBase(ctx, dockerCommand, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ func newRunCommand() *cobra.Command {
func run(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

dockerCommand := docker.NewDockerCommand()

cfg, projectDir, err := config.GetConfig(configFilename)
if err != nil {
return err
}
imageName, err := image.BuildBase(ctx, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput)
imageName, err := image.BuildBase(ctx, dockerCommand, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput)
if err != nil {
return err
}
Expand All @@ -71,8 +73,6 @@ func run(cmd *cobra.Command, args []string) error {
gpus = "all"
}

dockerCommand := docker.NewDockerCommand()

runOptions := docker.RunOptions{
Args: args,
Env: envFlags,
Expand Down
5 changes: 3 additions & 2 deletions pkg/cli/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ Generate and run an HTTP server based on the declared model inputs and outputs.`
func cmdServe(cmd *cobra.Command, arg []string) error {
ctx := cmd.Context()

dockerCommand := docker.NewDockerCommand()

cfg, projectDir, err := config.GetConfig(configFilename)
if err != nil {
return err
}

imageName, err := image.BuildBase(ctx, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput)
imageName, err := image.BuildBase(ctx, dockerCommand, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput)
if err != nil {
return err
}
Expand All @@ -72,7 +74,6 @@ func cmdServe(cmd *cobra.Command, arg []string) error {
"--await-explicit-shutdown", "true",
}

dockerCommand := docker.NewDockerCommand()
runOptions := docker.RunOptions{
Args: args,
Env: envFlags,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/train.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func cmdTrain(cmd *cobra.Command, args []string) error {
buildFast = cfg.Build.Fast
}

if imageName, err = image.BuildBase(ctx, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput); err != nil {
if imageName, err = image.BuildBase(ctx, dockerCommand, cfg, projectDir, buildUseCudaBaseImage, DetermineUseCogBaseImage(cmd), buildProgressOutput); err != nil {
return err
}

Expand Down
115 changes: 0 additions & 115 deletions pkg/docker/build.go

This file was deleted.

16 changes: 16 additions & 0 deletions pkg/docker/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ type Command interface {
ContainerLogs(ctx context.Context, containerID string, w io.Writer) error
ContainerInspect(ctx context.Context, id string) (*container.InspectResponse, error)
ContainerStop(ctx context.Context, containerID string) error

ImageBuild(ctx context.Context, options ImageBuildOptions) error
}

type ImageBuildOptions struct {
// Platform string
WorkingDir string
DockerfileContents string
ImageName string
Secrets []string
NoCache bool
ProgressOutput string
Epoch *int64
ContextDir string
BuildContexts map[string]string
Labels map[string]string
}
Loading