Skip to content

Commit

Permalink
chore: add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
AtticusZeller committed Jan 13, 2024
1 parent f80de2c commit 1b89e1c
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 14 deletions.
76 changes: 76 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
*.manifest
*.spec
pip-log.txt
pip-delete-this-directory.txt
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
*.mo
*.pot
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
instance/
.webassets-cache
.scrapy
docs/_build/
.pybuilder/
target/
.ipynb_checkpoints
profile_default/
ipython_config.py
.pdm.toml
__pypackages__/
celerybeat-schedule
celerybeat.pid
*.sage.py
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.spyderproject
.spyproject
.ropeproject
/site
.mypy_cache/
.dmypy.json
dmypy.json
.pyre/
.pytype/
cython_debug/
1 change: 1 addition & 0 deletions .idea/fastapi_supabase_template.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 第一阶段:使用 Poetry 安装依赖
FROM python:3.11-rc-slim as builder

WORKDIR /app

RUN pip install poetry

COPY poetry.lock pyproject.toml /app/
# TODO: login docker register plugin
# 安装依赖,忽略项目本身
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev --no-root

# 第二阶段:构建最终镜像
FROM python:3.11-rc-slim

WORKDIR /app

# 从 builder 阶段复制安装好的依赖
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# 复制整个项目到容器中
COPY . /app

# 设置环境变量
ENV PORT=5000

# 暴露端口
EXPOSE 5000

# 运行 FastAPI 应用
CMD ["uvicorn", "src.app.main:app", "--host", "0.0.0.0", "--port", "5000"]
103 changes: 89 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,84 @@
</p>

# ⚡SupaFast⚡

___
> supabase & fastapi crud template
![supafast.drawio.png](assets%2Fsupafast.drawio.png)

## Features 🚀

___
> supabase & fastapi crud template

### FastAPI&supabase

1. works of authorization all handled by supabase-py and fastapi **dependency** without any extra code
2. supabase-py crud integration with **pydantic** model validation

### Pytest

1. pytest integration with **pytest-cov**
2. pytest **fixtures** for fastapi client and supabase client
3. pytest **fixtures** for access_token and refresh_token
4. test for **CRUD** operations
5. test for **api** operations

### CI/CD

1. **codecov** for coverage report
2. **poetry** for dependency management and pytest integration
3. **pre-commit** for code quality
4. **latest_changes.yml** for auto update README.md
5. **Semantic Release** for auto release and changelog

[//]: # ( 4. **docker** for deployment)

## How to use it

___
![](assets/usage.gif)

1. create your github repo and clone your repo

2. cd your repo and install dependencies

```shell
poetry install
```
3. set your supabase env

```shell
export SUPABASE_URL=your_supabase_url
export SUPABASE_KEY=your_supabase_key
```
4. config fastapi settings
```python
# src/app/core/config.py
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
SUPABASE_URL: str = Field(default_factory=lambda: os.getenv("SUPABASE_URL"))
SUPABASE_KEY: str = Field(default_factory=lambda: os.getenv("SUPABASE_KEY"))
SUPERUSER_EMAIL: str = Field(default_factory=lambda: os.getenv("SUPERUSER_EMAIL"))
SUPERUSER_PASSWORD: str = Field(default=lambda: os.getenv("SUPERUSER_PASSWORD"))
# SERVER_NAME: str
SERVER_HOST: AnyHttpUrl = "https://localhost"
SERVER_PORT: int = 8000
BACKEND_CORS_ORIGINS: list[AnyHttpUrl] = []
PROJECT_NAME: str = "fastapi supabase template"
Config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True)
```
5. run server
```shell
poetry run uvicorn src.app.main:app --reload
```

## Roadmap 🫶
___

- [x] FastAPI backend
- [x] **standard** structure for <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">**FastAPI**</a> project
- [x] **standard** structure
for <a href="https://github.com/tiangolo/fastapi" class="external-link" target="_blank">**FastAPI**</a> project
```text
── src
│ └── app
Expand Down Expand Up @@ -62,27 +134,29 @@ ___
│ └── main.py
...
```
- [x] **auto-auth** by fastapi dependency with supabase-auth
- [x] Full coverage of **CRUD** operations and **api** tests
- [x] pytest integration
- [x] **auto-auth** by fastapi dependency with supabase-auth
- [x] **CRUD** operations pytest
- [x] **api** requests pytest
- [ ] Supabase integration
- [x] crud supabase-postgresql
- [ ] websocket with supabase-realtime
- [ ] curd supabase-storage
- [ ] supafunc integration
- [x] crud supabase-postgresql
- [ ] websocket with supabase-realtime
- [ ] curd supabase-storage
- [ ] supafunc integration
- [ ] deployment
- [ ] Full **Docker** integration (Docker based).

- [ ] Full **Docker** integration (Docker based).

## How to use it
___
![](assets/usage.gif)
## Release Notes 🥸

___

### Latest Changes

### 2024-01-13 by Atticuszz - feat: update ci and README.md

- 🚚 [img.png](img.png) <- img.png

### 2024-01-13 by Atticuszz - upgrade: release 0.1.0

- 🔨 [items.py](src/app/api/api_v1/endpoints/items.py)
- 🔨 [deps.py](src/app/api/deps.py)
- 🔨 [config.py](src/app/core/config.py)
Expand All @@ -91,6 +165,7 @@ ___
- 🔨 [__init__.py](src/app/schemas/__init__.py)
- 🔨 [auth.py](src/app/schemas/auth.py)
- 🔨 [base.py](src/app/schemas/base.py)

## License

This project is licensed under the terms of the MIT license.

0 comments on commit 1b89e1c

Please sign in to comment.