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

Some improvements to the dev experience #865

Merged
merged 4 commits into from
Aug 1, 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
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@ Part of that means that the API follows the HAL-JSON style.

# Installation

## Using Docker Compose (recommended for development)

Run docker compose:
```
docker compose up
```

Navigate to `localhost:8090`.

By default a collection of example datasets is loaded, and a local database is setup and initialized.
This behaviour can be changed with environment variables as described below.

### Environment

The following environment variables are useful for configuring a local development environment.

* `DATABASE_URL`: the postgresql URL of the database the application should connect to.
The default is the `database` container in the compose file.
* `INITIALIZE_DB`: Initialize the database with django migrate and import schema's. Default `true`.
* `MOCK_DATA`: Fill the initialized database with autogenerated mock data. Default: `false`.
* `SCHEMA_URL`: URL of the dataset schemas. To use the production schemas set this to:
"https://schemas.data.amsterdam.nl/datasets/"
Default is the `schemas` container in the compose file.

To connect to an authentication provider, setup the following environment variables:
* `OAUTH_CLIENT_ID`: The client id of the application
* `OAUTH_JWKS_URL`: The JWKS URL of the authentication provider.
* `OAUTH_URL`: The auth URL of the authentication provider.

#### Example
A local setup using the production dataset schema's with mock data:
```
export INITIALIZE_DB=true
export MOCK_DATA=true
export SCHEMA_URL="https://schemas.data.amsterdam.nl/datasets/"
compose up
```

## Without Docker Compose
See the instructions at: <https://dso-api.readthedocs.io/en/latest/howto/install.html>

These instructions can also be found in the ``dev-docs/source/howto/install.rst`` file.
Expand Down
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ services:
shm_size: 128mb
healthcheck:
test: ["CMD-SHELL", "pg_isready", "-U", "$${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 2s
interval: 10s
timeout: 60s
retries: 5
start_period: 1s
start_period: 20s
ports:
- "5415:5432"
environment:
Expand All @@ -31,6 +31,8 @@ services:
depends_on:
database:
condition: service_healthy
redis:
condition: service_started
environment:
UWSGI_HTTP_SOCKET: ":8000"
UWSGI_MODULE: "dso_api.wsgi"
Expand All @@ -53,6 +55,7 @@ services:
DJANGO_DEBUG: 1
APIKEY_ENABLED: "${APIKEY_ENABLED}"
INITIALIZE_DB: "${INITIALIZE_DB:-true}"
MOCK_DATA: "${MOCK_DATA:-false}"
SCHEMA_URL: "http://schemas/datasets/" # "https://schemas.data.amsterdam.nl/datasets/"
volumes:
- ./src:/app
Expand Down
1 change: 1 addition & 0 deletions src/dso_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
"Accept-Crs",
"Content-Crs",
]
SECURE_CROSS_ORIGIN_OPENER_POLICY = "unsafe-none"

HEALTH_CHECKS = {
"app": lambda request: True,
Expand Down
7 changes: 7 additions & 0 deletions src/initialize_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ then
./manage.py migrate;
./manage.py import_schemas --create-tables;
schema permissions apply --auto --revoke --create-roles --execute -a "datasets_dataset:SELECT;scope_openbaar" -a "datasets_datasettable:SELECT;scope_openbaar" -a "datasets_datasetfield:SELECT;scope_openbaar" -a "datasets_datasetprofile:SELECT;scope_openbaar";

# Fill tables with mock data if MOCK_DATA is set. Continue on errors.
if "$MOCK_DATA" = "true";
then
django create_mock_data --size 20 --exclude None || true;
django relate_mock_data --exclude None || true;
fi
fi