Skip to content

Commit

Permalink
Merge pull request #4 from Awesome-Movie-Database/v1.0.0
Browse files Browse the repository at this point in the history
V1.0.0
  • Loading branch information
madnoberson authored Mar 10, 2024
2 parents 7d05899 + 7c0cf89 commit f6678fe
Show file tree
Hide file tree
Showing 268 changed files with 5,124 additions and 4,296 deletions.
28 changes: 0 additions & 28 deletions .env.template

This file was deleted.

4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ repos:
hooks:
- id: mypy
files: ^src/
additional_dependencies: [types-redis]
additional_dependencies:
- types-redis
- types-toml
26 changes: 26 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
line-length = 79
src = ["src"]
include = ["src/**.py", "tests/**.py"]

extend-select = [
"N", # https://docs.astral.sh/ruff/settings/#pep8-naming
"EM", # https://docs.astral.sh/ruff/settings/#flake8-errmsg
"ISC", # https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"Q", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
]
select = [
"F401", # unused-import
"F406", # undefined-local-with-nested-import-star-usage
"COM812", # missing-trailing-comma
"DTZ003", # call-datetime-utcnow
"EM102", # f-string-in-exception
"INP001", # implicit-namespace-package
"PIE794", # duplicate-class-field-definition
"PIE796", # non-unique-enums
"T201", # print
"SLF001", # private-member-access
]

[format]
quote-style = "double"
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ FROM base AS web_api

COPY --from=builder ./app/dist ./

RUN $(printf "pip install %s[web_api,cli]" amdb*.whl)
RUN $(printf "pip install %s[web_api]" amdb*.whl)

CMD ["amdb-web_api"]
CMD ["amdb", "web-api"]

FROM base AS worker

COPY --from=builder ./app/dist ./

RUN pip install amdb*.whl

CMD ["amdb", "worker"]
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,66 @@
</a>
</p>

## How to run:

### Using docker-compose:
## Used technologies:

1. Provide `.env` file with variables from `.env.template`
* [Python 3](https://www.python.org/downloads/)
* [FastAPI](https://github.com/tiangolo/fastapi) - Framework for building WEB APIs
* [FastStream](https://github.com/airtai/faststream) - Framework for building message queues
* [Typer](https://github.com/tiangolo/typer) - Framework for buildig CLIs
* [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy) - Toolkit for building high level db integrations
* [alembic](https://github.com/sqlalchemy/alembic) - Tool for writing db migrations
* [redis-py](https://github.com/redis/redis-py) - Redis python client
* [Dishka](https://github.com/reagento/dishka) - DI framework
* [PostgreSQL](https://www.postgresql.org/)
* [Redis](https://redis.io/)

2. Run docker-compose

```sh
docker-compose --env-file ./.env up web_api
```
## How to run:

### Manually:

1. Install

```sh
pip install -e ".[web_api,cli]"
pip install -e ".[web_api]"
```

2. Provide env variables from `.env.template`
2. Create [config](./config/prod_config.template.toml) file

3. Provide `CONFIG_PATH` env variable

3. Run server
4. Run migrations

```sh
amdb-web_api
amdb alembic upgrade head
```

4. Run cli
5. Run worker

```sh
amdb-cli
amdb worker
```

## How to run migrations:
6. Run server

1. Provide env variables for postgres from `.env.template`
```sh
amdb web_api
```

2. Run migrations:
### Using docker-compose:

1. Create [config](./config/prod_config.template.toml) file

2. Provide `CONFIG_PATH`, `REDIS_PASSWORD`, `REDIS_PORT_NUMBER`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DB`, `SERVER_HOST`, `SERVER_PORT` env variables

3. Run worker and server

```sh
docker-compose up web_api
```
amdb-cli migration alembic upgrade head

4. Run migrations

```sh
docker exec amdb_backend.web_api amdb alembic upgrade head
```
8 changes: 8 additions & 0 deletions config/prod_config.template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[postgres]
url = "postgresql://postgres:1234@127.0.0.1:5432/amdb"

[redis]
url = "redis://:1234@127.0.0.1:6379/0"

[auth-session]
lifetime = 3600 # Minutes
5 changes: 5 additions & 0 deletions config/test_config.template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[postgres]
url = "postgresql://postgres:1234@127.0.0.1:5433/amdb_test"

[redis]
url = "redis://:1234@127.0.0.1:6378/1"
47 changes: 22 additions & 25 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,49 @@ version: "3"

services:
web_api:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.web_api
depends_on: [postgres, redis]
ports: ["${UVICORN_HOST}:${UVICORN_PORT}:${UVICORN_PORT}"]
depends_on: [postgres, redis, worker]
ports: ["${SERVER_HOST:-0.0.0.0}:${SERVER_PORT:-8000}:8000"]
restart: unless-stopped

build:
context: ./
dockerfile: ./Dockerfile
target: web_api
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_HOST=postgres
- POSTGRES_PORT

- FASTAPI_VERSION

- UVICORN_HOST=0.0.0.0
- UVICORN_PORT
- CONFIG_PATH

- REDIS_HOST=redis
- REDIS_PORT
- REDIS_DB
- REDIS_PASSWORD
worker:
profiles: [web_api, worker]
container_name: amdb_backend.worker
depends_on: [postgres, redis]
restart: unless-stopped

- SESSION_LIFETIME
build:
context: ./
dockerfile: ./Dockerfile
target: worker
environment:
- CONFIG_PATH

postgres:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.postgres
image: postgres:15-alpine
restart: unless-stopped

environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-1234}
- POSTGRES_DB=${POSTGRES_DB:-amdb}

redis:
profiles: [web_api]
profiles: [web_api, worker]
container_name: amdb_backend.redis
image: bitnami/redis:7.2
restart: unless-stopped

environment:
- REDIS_PASSWORD
- REDIS_PORT_NUMBER=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD:-1234}
- REDIS_PORT_NUMBER=${REDIS_PORT:-6379}
30 changes: 30 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Changelog

## [v1.0.0](https://github.com/Awesome-Movie-Database/amdb-backend/releases/tag/v1.0.0) (2024-03-10)

### Added

- `User` now can list `detailed reviews`
- `User` now can get `detailed movie`
- `User` now can list his `detailed ratings`
- `User` now can get `non detailed movie`
- `User` now can export his `ratings` in CSV format
- `User` now can request export his `ratings` in CSV format

### Changed

- Now `Create movie` and `Delete movie` don't require permissions
- [*Breaking change*] Now `Review` type is a string
- [*Breaking change*] Removed ability to list `Movies`
- [*Breaking change*] Removed ability to list `Ratings`
- [*Breaking change*] Removed ability to get `Movie`
- [*Breaking change*] Removed ability to get `Review`

### Fixed

- Race condition during rating `Movie` by many `Users` at the same time

### Echancements

- Added permissions table
- Now you can run server and worker using CLI


## [v0.5.0](https://github.com/Awesome-Movie-Database/amdb-backend/releases/tag/v0.5.0) (2024-01-29)

### Added
Expand Down
76 changes: 21 additions & 55 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
where = ["src"]
include = ["amdb*"]

[tool.setuptools.package-data]
amdb = ["infrastructure/persistence/alembic/alembic.ini"]

[project]
name = "amdb"
description = "Awesome Movie Database Backend"
Expand All @@ -17,74 +24,33 @@ maintainers = [
{ name = "madnoberson", email = "baseddepartmentzx77@gmail.com" },
]
dependencies = [
"uuid7",
"sqlalchemy==2.0.23",
"psycopg2-binary==2.9.9",
"alembic==1.13.0",
"redis>=5.0.0",
"uuid7==0.1.*",
"toml==0.10.*",
"dishka==0.6.*",
"sqlalchemy==2.0.*",
"psycopg2-binary==2.9.*",
"alembic==1.13.*",
"redis==5.0.*",
"faststream[redis]==0.4.*",
"typer[all]==0.9.*",
]

[project.optional-dependencies]
web_api = [
"fastapi==0.103.*",
"uvicorn==0.22.*",
]
cli = [
"typer[all]==0.9.*",
]
style = [
"mypy==1.8.0",
"ruff==0.1.9",
"types-redis",
dev = [
"mypy==1.8.*",
"ruff==0.1.*",
"pre-commit==3.5.*",
]
test = [
"pytest",
]
coverage = [
"pytest-cov",
]
dev = [
"amdb[web_api,cli,style,test,coverage]",
"pre-commit==3.5.0",
]

[project.scripts]
amdb-cli = "amdb.main.cli.__main__:main"
amdb-web_api = "amdb.main.web_api.__main__:main"

[tool.setuptools.packages.find]
where = ["src"]
include = ["amdb*"]

[tool.setuptools.package-data]
amdb = ["infrastructure/persistence/alembic/alembic.ini"]

[tool.pytest.ini_options]
pythonpath = "src/"

[tool.ruff.lint]
extend-select = [
"N", # https://docs.astral.sh/ruff/settings/#pep8-naming
"EM", # https://docs.astral.sh/ruff/settings/#flake8-errmsg
"ISC", # https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"Q", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
]
select = [
"F401", # unused-import
"F406", # undefined-local-with-nested-import-star-usage
"COM812", # missing-trailing-comma
"DTZ003", # call-datetime-utcnow
"EM102", # f-string-in-exception
"INP001", # implicit-namespace-package
"PIE794", # duplicate-class-field-definition
"PIE796", # non-unique-enums
"T201", # print
"SLF001", # private-member-access
]

[tool.ruff]
line-length = 99

[tool.ruff.format]
quote-style = "double"
amdb = "amdb.main.cli.app:run_cli"
Loading

0 comments on commit f6678fe

Please sign in to comment.