diff --git a/content/en/docs/03/_index.md b/content/en/docs/03/_index.md index 1206a9a..d66c626 100644 --- a/content/en/docs/03/_index.md +++ b/content/en/docs/03/_index.md @@ -272,8 +272,8 @@ Hints: {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```python @function - def backend(self, context: dagger.Directory) -> dagger.Service: - """Returns a backend service from a container built with the given context, params and service bindings.""" + def backend(self, context: dagger.Directory) -> dagger.SContainer: + """Returns a backend container built with the given context, params and service bindings.""" return ( dag.container() .with_env_variable("MAX_WORKERS", "1") @@ -293,47 +293,27 @@ Hints: .with_service_binding("meilisearchd", self.meilisearch()) .with_service_binding("redisd", self.redis()) .build(context) - .as_service() ) ``` {{% /details %}} -For convenience, the function returns directly a Service. - And the `frontend`: {{% details title="show solution" mode-switcher="normalexpertmode" %}} ```python @function - def frontend(self, context: dagger.Directory) -> dagger.Service: - """Returns a frontend service from a container built with the given context and params.""" + def frontend(self, context: dagger.Directory) -> dagger.Container: + """Returns a frontend container built with the given context and params.""" return ( dag.container() .with_env_variable("API_URL", "http://api:8081") .with_env_variable("REDIS_URL", "redis://redisd:6379/0?decode_responses=True") .build(context) - .as_service() ) ``` {{% /details %}} -Now the two service bindings in the `proxy` function can be simplified a bit. - -Before: - -```python - .with_service_binding("frontend", self.build(context.directory("frontend")).as_service()) - .with_service_binding("api", self.build(context).as_service()) -``` - -After: - -```python - .with_service_binding("frontend", self.frontend(context.directory("frontend"))) - .with_service_binding("api", self.backend(context)) -``` - -Now we can finally run ClassQuiz locally: +Now we can run ClassQuiz locally: ```bash dagger call proxy --context=. --proxy-config=Caddyfile-docker up --ports=8000:8080 diff --git a/content/en/docs/03/solution/__init__.py b/content/en/docs/03/solution/__init__.py index 16396f8..2f17388 100644 --- a/content/en/docs/03/solution/__init__.py +++ b/content/en/docs/03/solution/__init__.py @@ -5,19 +5,18 @@ class ClassQuiz: @function - def frontend(self, context: dagger.Directory) -> dagger.Service: - """Returns a frontend service from a container built with the given context and params.""" + def frontend(self, context: dagger.Directory) -> dagger.Container: + """Returns a frontend container built with the given context and params.""" return ( dag.container() .with_env_variable("API_URL", "http://api:8081") .with_env_variable("REDIS_URL", "redis://redisd:6379/0?decode_responses=True") .build(context) - .as_service() ) @function - def backend(self, context: dagger.Directory) -> dagger.Service: - """Returns a backend service from a container built with the given context, params and service bindings.""" + def backend(self, context: dagger.Directory) -> dagger.Container: + """Returns a backend container built with the given context, params and service bindings.""" return ( dag.container() .with_env_variable("MAX_WORKERS", "1") @@ -37,7 +36,6 @@ def backend(self, context: dagger.Directory) -> dagger.Service: .with_service_binding("meilisearchd", self.meilisearch()) .with_service_binding("redisd", self.redis()) .build(context) - .as_service() ) @function @@ -79,8 +77,8 @@ def proxy(self, context: dagger.Directory, proxy_config: dagger.File) -> dagger. return ( dag.container() .from_("caddy:alpine") - .with_service_binding("frontend", self.frontend(context.directory("frontend"))) - .with_service_binding("api", self.backend(context)) + .with_service_binding("frontend", self.frontend(context.directory("frontend")).as_service()) + .with_service_binding("api", self.backend(context).as_service()) .with_file("/etc/caddy/Caddyfile", proxy_config) .with_exposed_port(8080) .as_service() diff --git a/content/en/docs/04/solution/__init__.py b/content/en/docs/04/solution/__init__.py index 09ca9a5..334aca8 100644 --- a/content/en/docs/04/solution/__init__.py +++ b/content/en/docs/04/solution/__init__.py @@ -22,19 +22,18 @@ async def vulnerability_scan(self, context: dagger.Directory) -> dagger.Director return directory @function - def frontend(self, context: dagger.Directory) -> dagger.Service: - """Returns a frontend service from a container built with the given context and params.""" + def frontend(self, context: dagger.Directory) -> dagger.Container: + """Returns a frontend container built with the given context and params.""" return ( dag.container() .with_env_variable("API_URL", "http://api:8081") .with_env_variable("REDIS_URL", "redis://redisd:6379/0?decode_responses=True") .build(context) - .as_service() ) @function - def backend(self, context: dagger.Directory) -> dagger.Service: - """Returns a backend service from a container built with the given context, params and service bindings.""" + def backend(self, context: dagger.Directory) -> dagger.Container: + """Returns a backend container built with the given context, params and service bindings.""" return ( dag.container() .with_env_variable("MAX_WORKERS", "1") @@ -54,7 +53,6 @@ def backend(self, context: dagger.Directory) -> dagger.Service: .with_service_binding("meilisearchd", self.meilisearch()) .with_service_binding("redisd", self.redis()) .build(context) - .as_service() ) @function @@ -96,8 +94,8 @@ def proxy(self, context: dagger.Directory, proxy_config: dagger.File) -> dagger. return ( dag.container() .from_("caddy:alpine") - .with_service_binding("frontend", self.frontend(context.directory("frontend"))) - .with_service_binding("api", self.backend(context)) + .with_service_binding("frontend", self.frontend(context.directory("frontend")).as_service()) + .with_service_binding("api", self.backend(context).as_service()) .with_file("/etc/caddy/Caddyfile", proxy_config) .with_exposed_port(8080) .as_service() diff --git a/content/en/docs/05/_index.md b/content/en/docs/05/_index.md index f57b29e..631760d 100644 --- a/content/en/docs/05/_index.md +++ b/content/en/docs/05/_index.md @@ -19,10 +19,11 @@ add another one which executes the Python tests: async def pytest(self, context: dagger.Directory) -> str: """Run pytest and return its output.""" return await ( - dag.container().build(context) + dag.container() .with_exec(["pip", "install", "--upgrade", "pip"]) .with_exec(["pip", "install", "--upgrade", "pytest"]) .with_exec(["pytest", "classquiz/tests/", "--ignore=classquiz/tests/test_server.py"]) + .build(context) .stdout() ) ``` diff --git a/content/en/docs/05/solution/__init__.py b/content/en/docs/05/solution/__init__.py index d797657..5f71a5c 100644 --- a/content/en/docs/05/solution/__init__.py +++ b/content/en/docs/05/solution/__init__.py @@ -14,10 +14,11 @@ async def ci(self, context: dagger.Directory) -> dagger.Directory: async def pytest(self, context: dagger.Directory) -> str: """Run pytest and return its output.""" return await ( - dag.container().build(context) + dag.container() .with_exec(["pip", "install", "--upgrade", "pip"]) .with_exec(["pip", "install", "--upgrade", "pytest"]) .with_exec(["pytest", "classquiz/tests/", "--ignore=classquiz/tests/test_server.py"]) + .build(context) .stdout() ) @@ -39,19 +40,18 @@ async def vulnerability_scan(self, context: dagger.Directory) -> dagger.Director return directory @function - def frontend(self, context: dagger.Directory) -> dagger.Service: - """Returns a frontend service from a container built with the given context and params.""" + def frontend(self, context: dagger.Directory) -> dagger.Container: + """Returns a frontend container built with the given context and params.""" return ( dag.container() .with_env_variable("API_URL", "http://api:8081") .with_env_variable("REDIS_URL", "redis://redisd:6379/0?decode_responses=True") .build(context) - .as_service() ) @function - def backend(self, context: dagger.Directory) -> dagger.Service: - """Returns a backend service from a container built with the given context, params and service bindings.""" + def backend(self, context: dagger.Directory) -> dagger.Container: + """Returns a backend container built with the given context, params and service bindings.""" return ( dag.container() .with_env_variable("MAX_WORKERS", "1") @@ -71,7 +71,6 @@ def backend(self, context: dagger.Directory) -> dagger.Service: .with_service_binding("meilisearchd", self.meilisearch()) .with_service_binding("redisd", self.redis()) .build(context) - .as_service() ) @function @@ -113,8 +112,8 @@ def proxy(self, context: dagger.Directory, proxy_config: dagger.File) -> dagger. return ( dag.container() .from_("caddy:alpine") - .with_service_binding("frontend", self.frontend(context.directory("frontend"))) - .with_service_binding("api", self.backend(context)) + .with_service_binding("frontend", self.frontend(context.directory("frontend")).as_service()) + .with_service_binding("api", self.backend(context).as_service()) .with_file("/etc/caddy/Caddyfile", proxy_config) .with_exposed_port(8080) .as_service()