Skip to content

Commit

Permalink
ADD basic torch container build
Browse files Browse the repository at this point in the history
  • Loading branch information
matbun committed Nov 5, 2024
1 parent da58cfc commit f6ed515
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/sdk/** linguist-generated
3 changes: 3 additions & 0 deletions ci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/sdk
/.venv
/**/__pycache__
6 changes: 6 additions & 0 deletions ci/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "itwinai",
"sdk": "python",
"source": ".",
"engineVersion": "v0.13.3"
}
12 changes: 12 additions & 0 deletions ci/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "main"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["dagger-io"]

[tool.uv.sources]
dagger-io = { path = "sdk", editable = true }

[build-system]
requires = ["hatchling==1.25.0"]
build-backend = "hatchling.build"
65 changes: 65 additions & 0 deletions ci/src/main/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""A generated module for Itwinai functions
This module has been generated via dagger init and serves as a reference to
basic module structure as you get started with Dagger.
Two functions have been pre-created. You can modify, delete, or add to them,
as needed. They demonstrate usage of arguments and return types using simple
echo and grep commands. The functions can be called from the dagger CLI or
from one of the SDKs.
The first line in this comment block is a short description line and the
rest is a long description with more detail on the module's purpose or usage,
if appropriate. All modules should have a short description.
"""

# NOTE: it's recommended to move your code into other files in this package
# and keep __init__.py for imports only, according to Python's convention.
# The only requirement is that Dagger needs to be able to import a package
# called "main" (i.e., src/main/).
#
# For example, to import from src/main/main.py:
# >>> from .main import Itwinai as Itwinai

from typing import Annotated

import dagger
from dagger import dag, function, object_type, Doc


@object_type
class Itwinai:

@function
def build_torch(
self,
src: Annotated[
dagger.Directory,
Doc("location of directory containing Dockerfile"),
],
) -> dagger.Container:
"""Build image from existing Dockerfile"""
return (
dag.container()
.with_directory("/src", src)
.with_workdir("/src")
.directory("/src")
.docker_build()
)

@function
def container_echo(self, string_arg: str) -> dagger.Container:
"""Returns a container that echoes whatever string argument is provided"""
return dag.container().from_("alpine:latest").with_exec(["echo", string_arg])

@function
async def grep_dir(self, directory_arg: dagger.Directory, pattern: str) -> str:
"""Returns lines that match a pattern in the files of the provided Directory"""
return await (
dag.container()
.from_("alpine:latest")
.with_mounted_directory("/mnt", directory_arg)
.with_workdir("/mnt")
.with_exec(["grep", "-R", pattern, "."])
.stdout()
)
573 changes: 573 additions & 0 deletions ci/uv.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dev = [
"ipykernel",
"ipython",
"isort",
"dagger",
"tensorflow==2.16.*", # needed by tests on tensorboard
]

Expand Down

0 comments on commit f6ed515

Please sign in to comment.