Skip to content
Open
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
6 changes: 0 additions & 6 deletions .env

This file was deleted.

5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
OPEN5E_DEBUG=True
SECRET_KEY=replace-me-with-a-random-secret-key
SERVER_NAME=localhost
CERTFILE=selfsigned.crt
KEYFILE=selfsigned.key
25 changes: 13 additions & 12 deletions .github/workflows/pr_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: '3.11'
cache: pipenv
- name: Install Pipenv
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
- name: Install Dependencies
run: pipenv install --dev
enable-cache: true
prune-cache: false
- name: Install Python
run: uv python install 3.11
- name: Install dependencies
run: uv sync
- name: Run migrations
run: pipenv run python manage.py quicksetup --noindex
run: uv run python manage.py quicksetup --noindex
- name: Run Tests
run: |
pipenv run python manage.py runserver 0.0.0.0:8000 &
uv run python manage.py runserver 0.0.0.0:8000 &
sleep 5 &&
pipenv run pytest
uv run pytest
- name: Validate Data
run: |
pipenv run python ./scripts/data_test.py --dir ./data/v2 &
pipenv run python ./manage.py
uv run python ./scripts/data_test.py --dir ./data/v2 &
uv run python ./manage.py
build:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Environment and configuration files
.env
local.env
*.local
.python-version
Expand Down
30 changes: 16 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
FROM python:3.11-slim
FROM python:3.11-slim AS builder

RUN mkdir -p /opt/services/open5e-api
WORKDIR /opt/services/open5e-api
# copy our project code
WORKDIR /build

COPY --from=ghcr.io/astral-sh/uv:0.10 /uv /usr/local/bin/uv

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project

# install our dependencies
RUN pip install pipenv gunicorn
COPY . /opt/services/open5e-api
COPY . .
RUN uv run python manage.py quicksetup

RUN pipenv install
FROM python:3.11-slim

WORKDIR /opt/services/open5e-api

# migrate the db, load content, and index it
RUN pipenv run python manage.py quicksetup
COPY --from=builder /build/.venv /opt/services/open5e-api/.venv
COPY --from=builder /build /opt/services/open5e-api

# remove .env file (set your env vars via docker-compose.yml or your hosting provider)
RUN rm .env
ENV PATH="/opt/services/open5e-api/.venv/bin:$PATH"

#run gunicorn.
CMD ["pipenv", "run", "gunicorn","-b", ":8888", "server.wsgi:application"]
CMD ["gunicorn", "-b", ":8888", "server.wsgi:application"]
27 changes: 0 additions & 27 deletions Pipfile

This file was deleted.

1,165 changes: 0 additions & 1,165 deletions Pipfile.lock

This file was deleted.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,23 @@ The API uses the Django REST Framework for it's browsability and ease of use whe
## Requirements

- [Python 3.11](https://www.python.org/downloads/)

- [Pipenv](https://pipenv.pypa.io/en/latest/installation.html)
- [uv](https://docs.astral.sh/uv/getting-started/installation/)

## Dependencies

Pipenv is used to install all required packages from the `Pipfile` at the project root. Use the following command after cloning the project or switching branches.
uv is used to manage dependencies and run commands. Install all dependencies after cloning the project or switching branches:

```bash
pipenv install --dev
uv sync
```

# Development

## Build

Crate a local database and import game content.
Create a local database and import game content.
```bash
pipenv run python manage.py quicksetup --noindex
uv run python manage.py quicksetup --noindex
```

To make sure the API is always using your updated code, this command must be run again if:
Expand All @@ -99,15 +98,15 @@ To make sure the API is always using your updated code, this command must be run

To use the search function, you must build the search index by running the above command without the `--noindex` flag.
```bash
pipenv run python manage.py quicksetup
uv run python manage.py quicksetup
```

## Run

Run the server locally. This server is only for development and shall __not__ be used in production. The server will be available at `http://localhost:8000`.

```bash
pipenv run python manage.py runserver
uv run python manage.py runserver
```

### Self-hosting
Expand All @@ -123,17 +122,17 @@ You can use our Dockerfile as inspiration, but it likely will not work without s

After completing a build, you can generate an OAS file to be used by another application.
```bash
pipenv run python manage.py spectacular --color --file openapi-schema.yml` to build the OAS file.
uv run python manage.py spectacular --color --file openapi-schema.yml
```

# Contributing
See [contribution guide](.github/CONTRIBUTING.md).
# Tests

Tests are located in the `api/tests` directory. These should be run before pushing new changes to the main repository. These tests require that the api is [running](##run) at `http://localhost:8000`.
Tests are located in the `api/tests` directory. These should be run before pushing new changes to the main repository.

```bash
pipenv run pytest
uv run pytest
```

## Approval tests
Expand Down
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[project]
name = "open5e-api"
version = "2.1.0"
requires-python = "==3.11.*"
dependencies = [
"django>=5.2,<5.3",
"djangorestframework",
"django-filter",
"django-cors-headers",
"newrelic",
"requests",
"whitenoise",
"gunicorn",
"drf-spectacular[sidecar]",
"numpy",
"rapidfuzz",
"scikit-learn",
]

[dependency-groups]
dev = [
"pytest",
"pytest-django",
"approvaltests",
"pytest-approvaltests",
]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "server.settings"
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

7 changes: 5 additions & 2 deletions server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
DEBUG = os.environ.get("OPEN5E_DEBUG", "") != "False"

# SECURITY WARNING: keep the secret key used in production secret!
assert "SECRET_KEY" in os.environ, "Set SECRET_KEY in your .env or local OS!"
SECRET_KEY = os.environ["SECRET_KEY"]
_DEV_KEY = "open5e-local-dev-insecure-do-not-use-in-production"
SECRET_KEY = os.environ.get("SECRET_KEY", _DEV_KEY)

if not DEBUG and SECRET_KEY == _DEV_KEY:
raise ValueError("SECRET_KEY env var must be set in production.")

# Flags to include v1 data and index.
INCLUDE_V1_DATA = True
Expand Down
Loading
Loading