Check out the post.
Uses the default Django development server.
-
Rename .env.dev-sample to .env.dev.
-
Update the environment variables in the docker-compose.yml and .env.dev files.
-
Build the images and run the containers:
$ docker-compose up -d --build
Test it out at http://localhost:8000. The "app" folder is mounted into the container and your code changes apply automatically. The Hasura interface for local development startsby default at http://localhost:8080.
-
You may use make to run commands in local environment on docker:
Make commands are divided into two types: particles and actions. Particles are usually single line commands with names in form:
<catgory>-<name>
, which might be hard to remember.That's we there are also actions, with easy to remember names and grouping particle commands into workflows.
-
Install
- inst-prod - installs only production requirements
- inst-dev - installs only development requirements
- inst-pip - installs/upgrades pip
- inst-upg - upgrades both requirement files
- install-prod - upgrade pip and install production requirements
- install-dev - upgrade pip, install production and development requirements
- upgrade - upgrade requiement files and install-dev
-
Testing
- test-unit - runs python unit tests
- tst-unit-cov - runs python unit tests with coverage
- test-behave - runs behave tests
- test-behave-cov - runs behave tests with coverage
- test - run all tests
- test-cov - run all tests with coverage
- behave-dev - run behave tests in dev mode*
- pytest-dev - run unit tests in dev mode*
-
- more verbosity and stop on first fail
-
Formatting
- fmt-black - formats code using black
- fmt-isort - sorts imports in code
- format - runs both of above operations
Attention! Don't run
format
command inside docker! -
Linting
- lint-check - check i versions of installed packages match versions from requirement iles
- lint-black - check if code is formatted by black
- lint-isort - check if imports are sorted
- lint-pycodestyle - check Python Style Guide
- lint-bandit - check security
- lint-mypy - check types
- lint-pylint - run pylint
- lint - run all of them
-
Docker
- graph - create model graph
- messages - updates translation file
- django - run django admin command (syntax:
make django cmd='migrate'
)
For example, before creating a pull requests make sure you ran locally:
make install-dev format lint test-cov graph messages
(And check if there are no missing transactions) or simply:make prcheck
. -
-
Aliases for docker commands
Local aliases file to include docker aliases in your shell:
. .aliases
Available aliases:
dexdj
- Run command in django containerdexgq
- Run command in hasura containerdexpg
- Run command in postgresql containerdd-admin
- Run django admin command in Django containerdd-ipython
- Run ipython in Django containerdd-make
- Run make in Django containerdg-hasura
- Run hasura clidp-psql
- Run psql
To create an admin user, run the following command from inside your docker container:
python app/manage.py createsuperuser
You can open Hasura Console with
bash hasura/console.sh
To work offline, set following environment variables in ./compose/development/.env.hasura.
HASURA_GRAPHQL_ENABLE_CONSOLE=true
HASURA_GRAPHQL_CONSOLE_ASSETS_DIR=/srv/console-assets
Uses gunicorn + nginx.
-
Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables.
-
Build the images and run the containers:
$ docker-compose -f docker-compose.prod.yml up -d --build
Test it out at http://localhost:1337. No mounted folders. To apply changes, the image must be re-built.
Run Hasura Console with Hasura CLI, migrations are saved automatically.
Remote databases can be migrated with
hasura migrate apply --endpoint https://my-hasura.herokuapp.com