flytekit icon indicating copy to clipboard operation
flytekit copied to clipboard

Add docker commands in ImageSpec

Open mao3267 opened this issue 1 year ago • 1 comments

Why are the changes needed?

We want to support adding other docker commands while creating ImageSpec.

What changes were proposed in this pull request?

  1. Add a new "docker_commands" member in ImageSpec, which is a list of docker commands.
  2. Insert these commands into the Dockerfile template.

How was this patch tested?

It can not use the new ImageSpec while creating a container remotely, therefore, we didn't add test at this time. We provide an example of building an image.

from flytekit.image_spec import ImageSpec
from flytekit import task, workflow
import flytekit

image_spec = ImageSpec(
    name="my_image",
    registry="localhost:30000",
    builder="default",
    apt_packages=["wget", "git", "build-essential"],
    docker_commands=[
        "RUN git config --global user.email '[email protected]'",
        "RUN git config --global user.name 'mao3267'",
        "RUN git clone https://github.com/mao3267/flytekit.git",
        "RUN wget https://raw.githubusercontent.com/opensource4you/gossip/main/README.md",
        "COPY . /root",
    ],
)


@task(container_image=image_spec)
def my_task() -> str:
    try:
        with open("/root/README.md", "r") as f:
            return f.read().split("\n")[0]
    except Exception as e:
        return str(e) + f" {flytekit.__version__}"


@workflow
def my_wf() -> str:
    return my_task()

As the screenshots show, the image is successfully built. However, the task will fail since the flytekit version of the remote container is still 1.13.

Setup process

git clone https://github.com/mao3267/flytekit.git
git checkout add-docker-commands
make setup && pip install -e .

Screenshots

image image

Check all the applicable boxes

  • [ ] I updated the documentation accordingly.
  • [ ] All new and existing tests passed.
  • [x] All commits are signed-off.

Related PRs

None

Docs link

None

mao3267 avatar Aug 11 '24 12:08 mao3267

Codecov Report

Attention: Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.57%. Comparing base (9666f15) to head (0a85ccc). Report is 8 commits behind head on master.

Files Patch % Lines
flytekit/image_spec/image_spec.py 22.22% 7 Missing :warning:
...lytekit-envd/flytekitplugins/envd/image_builder.py 50.00% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2676       +/-   ##
===========================================
- Coverage   93.48%   80.57%   -12.91%     
===========================================
  Files          17      292      +275     
  Lines         859    24420    +23561     
  Branches        0     4009     +4009     
===========================================
+ Hits          803    19677    +18874     
- Misses         56     4080     +4024     
- Partials        0      663      +663     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 11 '24 17:08 codecov[bot]