Skip to content

Commit d7f828a

Browse files
authored
Basic Dockerfile template (#44)
* add basic imagespec example Signed-off-by: nikki everett <nikki@union.ai> * use latest base image and python 3.11 Signed-off-by: nikki everett <nikki@union.ai> * rename to distinguish from basic dockerfile template Signed-off-by: nikki everett <nikki@union.ai> * rename simple example Signed-off-by: nikki everett <nikki@union.ai> * update base image Signed-off-by: nikki everett <nikki@union.ai> * update repo README Signed-off-by: nikki everett <nikki@union.ai> * update imagespec Signed-off-by: nikki everett <nikki@union.ai> * comment out imagespec definition, make linter fixes Signed-off-by: nikki everett <nikki@union.ai> * update steps Signed-off-by: nikki everett <nikki@union.ai> * make documentation more procedural Signed-off-by: nikki everett <nikki@union.ai> * small edits Signed-off-by: nikki everett <nikki@union.ai> * remove docker section Signed-off-by: nikki everett <nikki@union.ai> * add hello world template Signed-off-by: nikki everett <nikki@union.ai> * rename directory to make it clear this is a template, remove unnecessary requirements, small edits to example python script Signed-off-by: nikki everett <nikki@union.ai> * this has been renamed Signed-off-by: nikki everett <nikki@union.ai> * rename template directory Signed-off-by: nikki everett <nikki@union.ai> * update with new template name Signed-off-by: nikki everett <nikki@union.ai> * update with hello world template Signed-off-by: nikki everett <nikki@union.ai> * add docker specific instructions back to readme Signed-off-by: nikki everett <nikki@union.ai> * use cookiecutter for hello world template Signed-off-by: nikki everett <nikki@union.ai> * use cookiecutter for basic imagespec template Signed-off-by: nikki everett <nikki@union.ai> * fix typo Signed-off-by: nikki everett <nikki@union.ai> * remove extra cookiecutter imagespec template Signed-off-by: nikki everett <nikki@union.ai> --------- Signed-off-by: nikki everett <nikki@union.ai>
1 parent 5781145 commit d7f828a

12 files changed

Lines changed: 34 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Compiled images for all templates can be found in our [ghcr.io registry](https:/
88

99
### ImageSpec vs Dockerfile
1010

11-
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.
11+
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.
1212

1313
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:
1414

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"project_name": "basic_example_dockerfile"
3+
}

simple-example/{{cookiecutter.project_name}}/.gitignore renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/.gitignore

File renamed without changes.

simple-example/{{cookiecutter.project_name}}/Dockerfile renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8-slim-buster
1+
FROM python:3.10-slim-buster
22

33
WORKDIR /root
44
ENV VENV /opt/venv

simple-example/{{cookiecutter.project_name}}/LICENSE renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/LICENSE

File renamed without changes.

simple-example/{{cookiecutter.project_name}}/README.md renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,19 @@ A template for the recommended layout of a Flyte enabled repository for code wri
77
To get up and running with your Flyte project, we recommend following the
88
[Flyte getting started guide](https://docs.flyte.org/en/latest/getting_started.html).
99

10+
This project includes a script `docker_build.sh` that you can use to build a
11+
Docker image for your Flyte project.
12+
13+
```
14+
# help
15+
./docker_build.sh -h
16+
17+
# build an image with defaults
18+
./docker_build.sh
19+
20+
# build an image with custom values
21+
./docker_build.sh -p {{ cookiecutter.project_name }} -r <REGISTRY> -v <VERSION>
22+
```
23+
1024
We recommend using a git repository to version this project, so that you can
1125
use the git sha to version your Flyte workflows.

simple-example/{{cookiecutter.project_name}}/docker_build.sh renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/docker_build.sh

File renamed without changes.

simple-example/{{cookiecutter.project_name}}/requirements.txt renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/requirements.txt

File renamed without changes.

simple-example/{{cookiecutter.project_name}}/workflows/__init__.py renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/workflows/__init__.py

File renamed without changes.

simple-example/{{cookiecutter.project_name}}/workflows/example.py renamed to basic-template-dockerfile/{{cookiecutter.project_name}}/workflows/example.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
"""A simple Flyte example."""
1+
"""A basic Flyte project template that uses a Dockerfile"""
22

33
import typing
44
from flytekit import task, workflow
55

66

7-
@task
7+
@task()
88
def say_hello(name: str) -> str:
9-
"""A simple Flyte task to say "hello".
9+
"""A simple Flyte task to say "Hello".
1010
11-
The @task decorator allows Flyte to use this function as a Flyte task, which
12-
is executed as an isolated, containerized unit of compute.
11+
The @task decorator allows Flyte to use this function as a Flyte task,
12+
which is executed as an isolated, containerized unit of compute.
1313
"""
14-
return f"hello {name}!"
14+
return f"Hello, {name}!"
1515

1616

17-
@task
17+
@task()
1818
def greeting_length(greeting: str) -> int:
1919
"""A task the counts the length of a greeting."""
2020
return len(greeting)
2121

22+
2223
@workflow
23-
def wf(name: str = "union") -> typing.Tuple[str, int]:
24+
def wf(name: str = "world") -> typing.Tuple[str, int]:
2425
"""Declare workflow called `wf`.
2526
26-
The @workflow decorator defines an execution graph that is composed of tasks
27-
and potentially sub-workflows. In this simple example, the workflow is
28-
composed of just one task.
27+
The @workflow decorator defines an execution graph that is composed of
28+
tasks and potentially sub-workflows. In this simple example, the workflow
29+
is composed of just one task.
2930
3031
There are a few important things to note about workflows:
3132
- Workflows are a domain-specific language (DSL) for creating execution
@@ -40,6 +41,6 @@ def wf(name: str = "union") -> typing.Tuple[str, int]:
4041

4142

4243
if __name__ == "__main__":
43-
# Execute the workflow, simply by invoking it like a function and passing in
44+
# Execute the workflow by invoking it like a function and passing in
4445
# the necessary parameters
45-
print(f"Running wf() { wf(name='passengers') }")
46+
print(f"Running wf() {wf(name='passengers')}")

0 commit comments

Comments
 (0)