Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DI-2712] Some minor improvements #90

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions {{ cookiecutter.project_slug }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,69 @@

[![Code style: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://docs.astral.sh/ruff/formatter/)

### List of services: ###
## List of services

* Dev server: [https://{{ cookiecutter.domain_name }}/](https://{{ cookiecutter.domain_name }}/)

### Documentation: ###
## Documentation

* [Architecture overview](docs/architecture_overview.md)
* [Backend: Routine tasks](docs/commands.md)
* [Backend: Pre-commit hook](docs/pre_commit_hook.md)
* [Backend: Docker configuration](docs/docker.md)

### API documentation: ###
## API documentation

* ReDoc web UI: [https://{{ cookiecutter.domain_name }}/_platform/docs/v1/redoc/](https://{{ cookiecutter.domain_name }}/_platform/docs/v1/redoc/)
* Swagger web UI: [https://{{ cookiecutter.domain_name }}/_platform/docs/v1/swagger/](https://{{ cookiecutter.domain_name }}/_platform/docs/v1/swagger/)
* Schema YAML: [https://{{ cookiecutter.domain_name }}/_platform/docs/v1/schema/](https://{{ cookiecutter.domain_name }}/_platform/docs/v1/schema/)

### First run: ###
## First run
Application is running in docker containers.

### Prerequisites
Installed [docker](https://docs.docker.com/engine/install/)

Copy initial settings for Django project:
### Copy initial settings for Django project

```bash
cp ./api/.env.example ./api/.env
```
> [!IMPORTANT]
> It is highly advised to use custom admin location instead of default `admin/`.
> To do that you need set `{{ cookiecutter.__env_prefix }}DJANGO_ADMIN_URL` environment variable in `./api/.env` file
> with custom value.
Run application with required services:
### Run application with required services

```bash
make compose-up
```

Your application will be available at [http://localhost:8000](http://localhost:8000)

How it works:
- `make compose-up` will run docker-compose with (all services)[docker/docker.md]
- if images is missed it will build them
- if there is no `poetry.lock` file present, Poetry simply resolves all dependencies listed in your
`api/pyproject.toml` file and downloads the latest version of their files.
But in any case it's good practice to lock your dependencies and share the lock file with your team,
to do that run `make poetry-lock` command, and commit `poetry.lock` file to the repository.
- it will use `api/.env` file to set environment variables for `api` and `celery` services. Check `env_file` section in [docker-compose.yml](docker/docker-compose.yml)
#### How it works
- `make compose-up` will run docker-compose with [all services](docker/docker.md)
- if images is missed it will build them
- if there is no `poetry.lock` file present, Poetry simply resolves all dependencies listed in your
`api/pyproject.toml` file and downloads the latest version of their files.
But in any case it's good practice to lock your dependencies and share the lock file with your team,
to do that run `make api-lock` command, and commit `poetry.lock` file to the repository.
- it will use `api/.env` file to set environment variables for `api` and `celery` services. Check `env_file` section in [docker-compose.yml](docker/docker-compose.yml)

Any changes in docker files or python dependency will require to rebuild images, to do that run `make compose-build` command.

### Create superuser
Run bash on `api` docker container
```bash
make api-bash
```
Run `createsuperuser` manage.py command
```bash
python manage.py createsuperuser
```
Follow instructions

### Docker
Application is running in docker containers. It allows to run application in the same environment on any machine with
minimal setup.
Expand Down
3 changes: 2 additions & 1 deletion {{ cookiecutter.project_slug }}/api/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ cookiecutter.__env_prefix }}ALLOWED_HOSTS=127.0.0.1,
{{ cookiecutter.__env_prefix }}ALLOWED_HOSTS=127.0.0.1,0.0.0.0,localhost
{{ cookiecutter.__env_prefix }}SECRET_KEY=secret-key

{{ cookiecutter.__env_prefix }}DEBUG=on
Expand All @@ -12,6 +12,7 @@
{{ cookiecutter.__env_prefix }}EMAIL_PORT=1025
{{ cookiecutter.__env_prefix }}EMAIL_USE_TLS=off

{{ cookiecutter.__env_prefix }}DJANGO_ADMIN_URL=admin/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I open for suggestion to replace default admin/


# Minio credentials
AWS_S3_ACCESS_KEY_ID={{ cookiecutter.__minio_access_key }}
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ check-fix:
ruff format .
ruff check --fix-only --show-fixes --statistics .

run:migrate collectstatic
run: migrate collectstatic
python manage.py runserver_plus 0.0.0.0:8000 --nostatic

celery-worker-run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def save(self, **kwargs):

class ConfirmResetPasswordSerializer(serializers.Serializer):
password = serializers.CharField(max_length=128, write_only=True, style={"input_type": "password"})
signature = serializers.CharField(max_length=71, write_only=True)
signature = serializers.CharField(max_length=128, write_only=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact value for current configuration is 87 but then we will have no margin. I as I understand length of signature can be different if we change algorithm so I decide give it some margin.


def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ..django import TIME_ZONE as DJANGO_TIME_ZONE
from ..environment import env


Expand All @@ -7,6 +6,6 @@

CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_TASK_SERIALIZER = CELERY_RESULT_SERIALIZER = "json"
CELERY_TIMEZONE = DJANGO_TIME_ZONE
CELERY_TIMEZONE = env.str("{{ cookiecutter.__env_prefix }}TIME_ZONE", default="UTC")

CELERYBEAT_SCHEDULE = {}
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
"django.db.backends.schema": {"handlers": ["console"], "level": "DEBUG", "propagate": False},
},
}

ADMIN_URL = env.str("{{ cookiecutter.__env_prefix }}DJANGO_ADMIN_URL", default="admin/")
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]

urlpatterns = [
path("admin/", admin.site.urls),
path(settings.ADMIN_URL, admin.site.urls),
*api_v1_urlpatterns,
]

Expand Down