Skip to content

Commit 8d105b7

Browse files
author
Developer
committed
Add Dagger
Signed-off-by: Developer <developer@example.com>
1 parent 21ed4ca commit 8d105b7

8 files changed

Lines changed: 790 additions & 0 deletions

File tree

.dagger/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/sdk/** linguist-generated

.dagger/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.venv
2+
/**/__pycache__
3+
/sdk
4+
/.env

.dagger/pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "book"
3+
version = "0.1.0"
4+
requires-python = ">=3.13"
5+
dependencies = ["dagger-io"]
6+
7+
[build-system]
8+
requires = ["uv_build>=0.8.4,<0.9.0"]
9+
build-backend = "uv_build"
10+
11+
[tool.uv.sources]
12+
dagger-io = { path = "sdk", editable = true }

.dagger/src/book/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""A generated module for Book functions
2+
3+
This module has been generated via dagger init and serves as a reference to
4+
basic module structure as you get started with Dagger.
5+
6+
Two functions have been pre-created. You can modify, delete, or add to them,
7+
as needed. They demonstrate usage of arguments and return types using simple
8+
echo and grep commands. The functions can be called from the dagger CLI or
9+
from one of the SDKs.
10+
11+
The first line in this comment block is a short description line and the
12+
rest is a long description with more detail on the module's purpose or usage,
13+
if appropriate. All modules should have a short description.
14+
"""
15+
16+
from .main import Book as Book

.dagger/src/book/main.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import random
2+
from typing import Annotated
3+
from datetime import datetime
4+
5+
import dagger
6+
from dagger import Container, dag, Directory, DefaultPath, Doc, File, Secret, function, object_type, ReturnType
7+
8+
9+
@object_type
10+
class Book:
11+
12+
source: Annotated[dagger.Directory, DefaultPath(".")]
13+
14+
@function
15+
def env(self) -> dagger.Container:
16+
"""Returns a container with the Python environment and the source code mounted"""
17+
return (
18+
dag.container()
19+
.from_("python:3.11")
20+
.with_directory("/app", self.source)
21+
.with_workdir("/app")
22+
.with_mounted_cache("/root/.cache/pip", dag.cache_volume("python-pip"))
23+
.with_exec(["pip", "install", "-r", "requirements.txt"])
24+
.with_exposed_port(8000)
25+
.with_entrypoint(["fastapi", "run", "main.py"])
26+
)
27+
28+
@function
29+
async def test(self) -> str:
30+
"""Runs the tests in the source code and returns the output"""
31+
postgresdb = (
32+
dag.container()
33+
.from_("postgres:alpine")
34+
.with_env_variable("POSTGRES_DB", "app_test")
35+
.with_env_variable("POSTGRES_PASSWORD", "secret")
36+
.with_exposed_port(5432)
37+
.as_service(args=[], use_entrypoint=True)
38+
)
39+
40+
cmd = (
41+
self.env()
42+
.with_service_binding("db", postgresdb)
43+
.with_env_variable("DATABASE_URL", "postgresql://postgres:secret@db/app_test")
44+
.with_exec(["pytest"])
45+
)
46+
return await cmd.stdout()
47+
48+
@function
49+
async def ci(self) -> str:
50+
"""Tests and publishes the application container to a registry"""
51+
await self.test()
52+
return await (
53+
self.env()
54+
.publish(f"ttl.sh/my-fastapi-app-{random.randrange(10**8)}")
55+
)

.dagger/uv.lock

Lines changed: 671 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/dagger.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: dagger
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
dagger:
12+
name: dagger
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Build, test, publish
18+
id: test
19+
uses: dagger/dagger-for-github@8.0.0
20+
with:
21+
version: "0.19"
22+
verb: call
23+
args: ci

dagger.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "book",
3+
"engineVersion": "v0.18.16",
4+
"sdk": {
5+
"source": "python"
6+
},
7+
"source": ".dagger"
8+
}

0 commit comments

Comments
 (0)