Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox.

pawamoy, updated πŸ•₯ 2022-04-22 21:02:54

Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox

This is a Docker setup for a web application based on Django.

  • The Django application is served by Gunicorn (WSGI application).
  • We use NginX as reverse proxy and static files server. Static and media files are persistently stored in volumes.
  • Multiple Postgres databases can be used. Data are persistently stored in volumes.
  • Python dependencies are managed through pipenv, with Pipfile and Pipfile.lock.
  • Support for multiple environment settings (variable DJANGO_SETTINGS_MODULE is passed to the djangoapp service).
  • Tests are run using tox, pytest, and other tools such as safety, bandit, isort and prospector.
  • Continuous Integration is configured for GitLab with .gitlab-ci.yml. CI follows a Build-Test-Release flow. WARNING: this part is not fully functional yet.

Also a Makefile is available for convenience. You might need to use sudo make instead of just make because docker and docker-compose commands often needs admin privilege.

Requirements

You need to install Docker and Docker-Compose.

Build

docker-compose build or make build.

Migrate databases

docker-compose run --rm djangoapp hello/manage.py migrate or make migrate.

Collect static files

docker-compose run --rm djangoapp hello/manage.py collectstatic --no-input' or make collectstatic.

Run

docker-compose up or make run.

Tests

  • make checksafety
  • make checkstyle
  • make test
  • make coverage

Related blog post

Docker Compose with NginX, Django, Gunicorn and multiple Postgres databases

License

Software licensed under the ISC license.

Issues

Bump django from 2.2.26 to 2.2.28

opened on 2022-04-22 21:02:53 by dependabot[bot]

Bumps django from 2.2.26 to 2.2.28.

Commits
  • 5c33000 [2.2.x] Bumped version for 2.2.28 release.
  • 29a6c98 [2.2.x] Fixed CVE-2022-28347 -- Protected QuerySet.explain(**options) against...
  • 2c09e68 [2.2.x] Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), a...
  • 8352b98 [2.2.x] Added stub release notes for 2.2.28.
  • 2801f29 [2.2.x] Reverted "Fixed forms_tests.tests.test_renderers with Jinja 3.1.0+."
  • e03648f [2.2.x] Fixed forms_tests.tests.test_renderers with Jinja 3.1.0+.
  • 9d13d8c [2.2.x] Fixed typo in release notes.
  • 047ece3 [2.2.x] Added CVE-2022-22818 and CVE-2022-23833 to security archive.
  • 2427b2f [2.2.x] Post-release version bump.
  • e541f2d [2.2.x] Bumped version for 2.2.27 release.
  • Additional commits viewable in compare view


Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/pawamoy/docker-nginx-postgres-django-example/network/alerts).

Failed to do postgresql migration with authentication error

opened on 2020-07-13 16:01:18 by Franceshe

The problem:

Hi, I have a project ongoing and found your docker tutorial Docker Compose with NginX, Django, Gunicorn and multiple Postgres databases pretty helpful and had followed along the tutorial.

Unfortunately, I was stuck on the part that I can't migrate to postgresql as the following command sugguest: docker-compose run --rm djangoapp /bin/bash -c "cd hello; ./manage.py migrate" After executing the command above, i got error message complain about django.db.utils.OperationalError: FATAL: password authentication failed for user "database1_role" But I could still successfully build the dockerfile

How I try to solve it:

I try to run postgresql server but it complains about the host/local connection: ➜ test_docker git:(master) βœ— psql psql: error: could not connect to server: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? I look it up on stackoverflow and try to brew restart the service or rm postmaster.pid....But it does not work.

Also I try to investigate the config file pg_hba.conf which defines who gets to log in what database at /usr/local/var/postgres/pg_hba.conf.

81| # TYPE DATABASE USER ADDRESS METHOD 82| 83| # "local" is for Unix domain socket connections only 84| local all all trust 85| # IPv4 local connections: 86| host all all 127.0.0.1/32 trust 87| # IPv6 local connections: 88| host all all ::1/128 trust 89| # Allow replication connections from localhost, by a user with the 90| # replication privilege. 91| local replication all trust 92| host replication all 127.0.0.1/32 trust 93| host replication all ::1/128 trust 94| host all all 127.0.0.1/5432 trust

Still no luck. Wander anyone has some suggestions to solve the problem? Thanks!

SSL

opened on 2019-11-25 21:26:02 by ardydavari

Thank you for your excellent repo.

Just making a request for instructions regarding configuring SSL.

TimothΓ©e Mazzucotelli

I think I just like to create.

GitHub Repository

docker docker-compose docker-example nginx postgresql django gunicorn pipenv tox