Skip to content

Commit

Permalink
Basic Dockerfile template (#44)
Browse files Browse the repository at this point in the history
* add basic imagespec example

Signed-off-by: nikki everett <[email protected]>

* use latest base image and python 3.11

Signed-off-by: nikki everett <[email protected]>

* rename to distinguish from basic dockerfile template

Signed-off-by: nikki everett <[email protected]>

* rename simple example

Signed-off-by: nikki everett <[email protected]>

* update base image

Signed-off-by: nikki everett <[email protected]>

* update repo README

Signed-off-by: nikki everett <[email protected]>

* update imagespec

Signed-off-by: nikki everett <[email protected]>

* comment out imagespec definition, make linter fixes

Signed-off-by: nikki everett <[email protected]>

* update steps

Signed-off-by: nikki everett <[email protected]>

* make documentation more procedural

Signed-off-by: nikki everett <[email protected]>

* small edits

Signed-off-by: nikki everett <[email protected]>

* remove docker section

Signed-off-by: nikki everett <[email protected]>

* add hello world template

Signed-off-by: nikki everett <[email protected]>

* rename directory to make it clear this is a template, remove unnecessary requirements, small edits to example python script

Signed-off-by: nikki everett <[email protected]>

* this has been renamed

Signed-off-by: nikki everett <[email protected]>

* rename template directory

Signed-off-by: nikki everett <[email protected]>

* update with new template name

Signed-off-by: nikki everett <[email protected]>

* update with hello world template

Signed-off-by: nikki everett <[email protected]>

* add docker specific instructions back to readme

Signed-off-by: nikki everett <[email protected]>

* use cookiecutter for hello world template

Signed-off-by: nikki everett <[email protected]>

* use cookiecutter for basic imagespec template

Signed-off-by: nikki everett <[email protected]>

* fix typo

Signed-off-by: nikki everett <[email protected]>

* remove extra cookiecutter imagespec template

Signed-off-by: nikki everett <[email protected]>

---------

Signed-off-by: nikki everett <[email protected]>
  • Loading branch information
neverett authored Apr 10, 2024
1 parent 5781145 commit d7f828a
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 19 deletions.
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

0 comments on commit d7f828a

Please sign in to comment.