Skip to content

Commit

Permalink
Add webserver example
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Jun 5, 2024
1 parent 6ffb4ad commit 7bfae7d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/webserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pixi/
output/
__pycache__/
13 changes: 13 additions & 0 deletions examples/webserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Webserver

This is a simple web server that runs FastAPI.

## Run the server

```bash
rattler-build build -r recipe/recipe.yaml
pixi-pack pack -e prod --platform win-64 --inject output/noarch/my-webserver-*.conda
```

> [!NOTE]
> The file `my-webserver-0.1.0-pyh4616a5c_0.conda` is only for testing, in a real scenario it would be in the `output/noarch` directory generated by `rattler-build`.
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/webserver/my_webserver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def hello():
return "Hello, World!"
21 changes: 21 additions & 0 deletions examples/webserver/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[project]
name = "pixi-docker-example"
channels = ["conda-forge"]
platforms = ["osx-arm64", "linux-64", "linux-aarch64", "win-64"]

[tasks]
dev = "uvicorn my_project:app --reload"
start = "uvicorn my_project:app --host 0.0.0.0"

[dependencies]
fastapi = "*"
uvicorn = "*"

[feature.dev.dependencies]
pytest = "*"
ruff = "*"
mypy = "*"

[environments]
default = { features = ["dev"], solve-group = "prod" }
prod = { features = [], solve-group = "prod" }
16 changes: 16 additions & 0 deletions examples/webserver/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my-webserver"
description = "Example web server"
version = "0.1.0"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.12"
# pixi handles the dependencies
# since we don't want to distribute this to pypi, we don't need to specify them here
dependencies = []
31 changes: 31 additions & 0 deletions examples/webserver/recipe/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

package:
name: my-webserver
version: '0.1.0'

source:
path: ../

build:
number: 0
noarch: python
script:
- python -m pip install . --no-deps --ignore-installed -vv --no-build-isolation --disable-pip-version-check

requirements:
host:
- python >=3.12
- pip
- hatchling
run:
- python >=3.12
- fastapi

tests:
- python:
imports:
- my_webserver
- package_contents:
site_packages:
- my_webserver/__init__.py

0 comments on commit 7bfae7d

Please sign in to comment.