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

Basic Dockerfile template #44

Merged
merged 27 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Compiled images for all templates can be found in our [ghcr.io registry](https:/

### ImageSpec vs Dockerfile

Flytekit uses the `basic-template-imagespec` template by default when you initialize a new project with `pyflyte init`. That template uses [ImageSpec](https://docs.flyte.org/projects/cookbook/en/latest/auto_examples/customizing_dependencies/image_spec.html#image-spec-example), which builds Docker images without a Dockerfile, so doesn't contain a Dockerfile or `docker-build.sh` script.
Flytekit uses the `basic-template-imagespec` template by default when you initialize a new project with `pyflyte init`. That template uses [ImageSpec](https://docs.flyte.org/en/latest/user_guide/customizing_dependencies/imagespec.html), which builds Docker images without a Dockerfile, so doesn't contain a Dockerfile or `docker-build.sh` script.

However, some templates in this repository contain a Dockerfile and `docker-build.sh` script that you can use to build a Docker image for your Flyte project:

Expand Down
3 changes: 3 additions & 0 deletions basic-template-dockerfile/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"project_name": "basic_example_dockerfile"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-buster
FROM python:3.10-slim-buster

WORKDIR /root
ENV VENV /opt/venv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ A template for the recommended layout of a Flyte enabled repository for code wri
To get up and running with your Flyte project, we recommend following the
[Flyte getting started guide](https://docs.flyte.org/en/latest/getting_started.html).

This project includes a script `docker_build.sh` that you can use to build a
Docker image for your Flyte project.

```
# help
./docker_build.sh -h

# build an image with defaults
./docker_build.sh

# build an image with custom values
./docker_build.sh -p {{ cookiecutter.project_name }} -r <REGISTRY> -v <VERSION>
```

We recommend using a git repository to version this project, so that you can
use the git sha to version your Flyte workflows.
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
"""A simple Flyte example."""
"""A basic Flyte project template that uses a Dockerfile"""

import typing
from flytekit import task, workflow


@task
@task()
def say_hello(name: str) -> str:
"""A simple Flyte task to say "hello".
"""A simple Flyte task to say "Hello".

The @task decorator allows Flyte to use this function as a Flyte task, which
is executed as an isolated, containerized unit of compute.
The @task decorator allows Flyte to use this function as a Flyte task,
which is executed as an isolated, containerized unit of compute.
"""
return f"hello {name}!"
return f"Hello, {name}!"


@task
@task()
def greeting_length(greeting: str) -> int:
"""A task the counts the length of a greeting."""
return len(greeting)


@workflow
def wf(name: str = "union") -> typing.Tuple[str, int]:
def wf(name: str = "world") -> typing.Tuple[str, int]:
"""Declare workflow called `wf`.

The @workflow decorator defines an execution graph that is composed of tasks
and potentially sub-workflows. In this simple example, the workflow is
composed of just one task.
The @workflow decorator defines an execution graph that is composed of
tasks and potentially sub-workflows. In this simple example, the workflow
is composed of just one task.

There are a few important things to note about workflows:
- Workflows are a domain-specific language (DSL) for creating execution
Expand All @@ -40,6 +41,6 @@ def wf(name: str = "union") -> typing.Tuple[str, int]:


if __name__ == "__main__":
# Execute the workflow, simply by invoking it like a function and passing in
# Execute the workflow by invoking it like a function and passing in
# the necessary parameters
print(f"Running wf() { wf(name='passengers') }")
print(f"Running wf() {wf(name='passengers')}")
3 changes: 0 additions & 3 deletions simple-example/cookiecutter.json

This file was deleted.

2 changes: 1 addition & 1 deletion templates.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{"template_name": "mnist-training", "workflow_name": "mnist_workflow_cpu"},
{"template_name": "mnist-training", "workflow_name": "mnist_workflow_gpu"},
{"template_name": "simple-example", "workflow_name": "wf"},
{"template_name": "basic-template-dockerfile", "workflow_name": "wf"},
{"template_name": "wine-classification", "workflow_name": "training_workflow"},
{"template_name": "basic-template-imagespec", "workflow_name": "wf"},
{"template_name": "hello-world", "workflow_name": "hello_world_wf"}
Expand Down
Loading