Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .dagger/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/sdk/** linguist-generated
4 changes: 4 additions & 0 deletions .dagger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.venv
/**/__pycache__
/sdk
/.env
12 changes: 12 additions & 0 deletions .dagger/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "book"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = ["dagger-io"]

[build-system]
requires = ["uv_build>=0.8.4,<0.9.0"]
build-backend = "uv_build"

[tool.uv.sources]
dagger-io = { path = "sdk", editable = true }
16 changes: 16 additions & 0 deletions .dagger/src/book/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""A generated module for Book 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.
"""

from .main import Book as Book
72 changes: 72 additions & 0 deletions .dagger/src/book/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import dagger
from dagger import dag, function, object_type
import random

@object_type
class Book:

## editttt
@function
def env(self, source: dagger.Directory) -> dagger.Container:
"""Return a base image"""
return (
dag.container()
.from_("python:3.11")
.with_exec(["sh","-c","apt-get update && apt-get install -y libpq-dev"])
.with_directory("/app", source)
.with_workdir("/app")
.with_mounted_cache("/root/.cache/pip",dag.cache_volume("python-pip"))
.with_exec(["pip","install","-r","requirements.txt"])
.with_exposed_port(8000)
.with_entrypoint(["fastapi", "run", "main.py", "--port", "8000"])
)

##edit
@function
async def test(self, source: dagger.Directory) -> str:
postgres = (
dag.container()
.from_("postgres:15-alpine")
.with_env_variable("POSTGRES_USER","app_user")
.with_env_variable("POSTGRES_PASSWORD","secret")
.with_file("/docker-entrypoint-initdb.d/init-dbs.sh", source.file("./init-dbs.sh"))
.with_exposed_port(5432)
.as_service(args=[], use_entrypoint=True)
)
return await (
self.env(source)
.with_service_binding("db",postgres)
.with_env_variable("DATABASE_URL","postgresql://app_user:secret@db/app_db")
.with_env_variable("TEST_DATABASE_URL","postgresql://app_user:secret@db/app_db_test")
.with_exec(["pytest"])
.stdout()
)


### edit
@function
async def publish(self, source: dagger.Directory) -> str:
"""Publishes the image"""
await self.test(source)
return await (
self.env(source)
.publish(f"ttl.sh/my-fast-api-app-{random.randrange(10000)}")
)


@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()
)
776 changes: 776 additions & 0 deletions .dagger/uv.lock

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions .github/workflows/dagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: dagger
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
dagger:
name: dagger
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test
id: test
uses: dagger/dagger-for-github@8.0.0
with:
version: "0.19.2"
verb: call
args: test --source=.
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
8 changes: 8 additions & 0 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "book",
"engineVersion": "v0.19.2",
"sdk": {
"source": "python"
},
"source": ".dagger"
}