Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Allow users to bring their own Dockerfile #773

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

dleviminzi
Copy link
Collaborator

@dleviminzi dleviminzi commented Dec 10, 2024

Resolve BE-2084

This feature adds a new operator to the Image abstraction that allows users to specify a path to a Dockerfile that they wish to use as the base of their Image. We use buildah and umoci to build their Dockerfile and gather the bundle needed to run it.

It can be used as follows:

from beta9 import Image, endpoint

image = Image().from_dockerfile("./Dockerfile").add_python_packages(["numpy"])


@endpoint(image=image, name="test_dockerfile")
def handler():
    return "pass"

Where ./Dockerfile is:

FROM ubuntu:22.04
RUN echo hello
ENV FOO=bar

Note: when testing locally, you might need to build gateway again to get make start to work because the go version is bumped.

@dleviminzi dleviminzi requested review from luke-lombardi, nickpetrovic and jsun-m and removed request for nickpetrovic December 10, 2024 20:06
@dleviminzi dleviminzi marked this pull request as ready for review December 10, 2024 22:57
Comment on lines +170 to +175
if opts.Dockerfile != "" {
fmt.Fprint(h, opts.Dockerfile)
}
if opts.BuildCtxObject != "" {
fmt.Fprint(h, opts.BuildCtxObject)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This feels pretty hacky to me, but I don't think we can change hash body.

docker/Dockerfile.worker Outdated Show resolved Hide resolved
pkg/worker/image.go Outdated Show resolved Hide resolved
@@ -25,7 +25,7 @@ FROM base AS build

WORKDIR /workspace

RUN apt-get install -y libfuse3-dev && \
RUN apt-get install -y libfuse3-dev libbtrfs-dev libgpgme-dev && \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there may have been an issue with libgpg + cedana, we should look into if it causes any issues with C/R

@@ -93,6 +115,11 @@ RUN apt-get install -y --no-install-recommends nvidia-container-toolkit-base nvi

RUN apt-get update && apt-get install -y fuse3 libfuse2 libfuse3-dev libfuse-dev bash-completion

RUN apt-get install -y libbtrfs-dev libgpgme11-dev
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

fmt.Fprintf(&b, " \"ExistingImageUri\": %q,", o.ExistingImageUri)
fmt.Fprintf(&b, " \"ExistingImageCreds\": %#v,", o.ExistingImageCreds)
fmt.Fprintf(&b, " \"Dockerfile\": %q,", o.Dockerfile)
fmt.Fprintf(&b, " \"BuildCtxObject\": %q,", o.BuildCtxObject)
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly is in this var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The object ID of the synced build context directory

pkg/abstractions/image/build.go Outdated Show resolved Hide resolved
@@ -201,6 +263,8 @@ func (b *Builder) Build(ctx context.Context, opts *BuildOpts, outputChan chan co
ImageId: baseImageId,
SourceImage: &sourceImage,
SourceImageCreds: opts.BaseImageCreds,
Dockerfile: dockerfile,
BuildCtxObject: &opts.BuildCtxObject,
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like that this is top level on the ContainerRequest. It might seem out of scope but I think we should nest these under a BuildOptions struct on the container request

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bumped it out

@@ -101,6 +111,16 @@ func (c *ContainerRequest) RequiresGPU() bool {
return len(c.GpuRequest) > 0 || c.Gpu != ""
}

func (c *ContainerRequest) ImageSourceType() ImageSourceType {
if c.Dockerfile != nil {
return ImageSourceTypeBuild
Copy link
Contributor

Choose a reason for hiding this comment

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

probably would call this just ImageSource

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I'd rather it be a method on a BuildOptions struct

Copy link
Contributor

Choose a reason for hiding this comment

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

We also already have an isBuildRequest thing so it's more fitting under that struct IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just removed this entirely as I don't think it was really needed

if err != nil {
return err
switch request.ImageSourceType() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think after moving this to the build options struct, it would be cleaner to refactor this to first check if it's a build request using the container ID, etc. And then handle these clauses in a separate function so it's logically separate from the standard container execution flow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants