/shallow_compose

Shallow dive into docker-compose - demo repository for the talk on use of docker-compose

Primary LanguagePythonMIT LicenseMIT

Shallow Compose

Shallow dive into docker-compose - a demo repository for my tech talk presenting use case of docker-compose.

The django project

This project has simple functionality for the demo purposes. It provides model Message for creating e-mail messages with receipient address in one field and text to be sent in the second.

Django admin provides three actions for the demonstration:

  • send to console - displays message and recipient in the console log
  • send directly to mail - sends an e-mail to the recipient directly from django (will not work in the final stage due to network separation of django app from mail sending service)
  • send to mail - sends an e-mail to the recipient by adding message to the queue and handling it in the celery worker

The e-mail is not sent right away. Instead the celery task (with Rabbit queue between) is scheduled and ran by celery worker later. The worker uses django email backend setup to send the email.

Using docker-compose

  1. Rename .env.example to .env
  2. Run docker-compose build
  3. Run docker-compose run --rm web python manage.py migrate
  4. Run docker-compose run --rm web python manage.py createsuperuser
  5. Run docker-compose up
  6. Login to localhost:8000/admin/ as an admin
  7. Add new Message object
  8. On the Messages list select message and from a dropdown list of actions pick send to console or email. Click go to run action.
  9. Check email displayed in the logs

Also check .compose_stages dir for different stages of the docker-compose development.

Manual setup & usage without docker-compose

  1. Create python virtualenv for python 3.7 on your host machine
  2. Run pip install -r requirements.txt to install required libraries
  3. Run ./manage.py migrate to migrate database
  4. Run ./manage.py createsuperuser to create admin user
  5. Run ./manage.py runserver 0.0.0.0:8000 to run server at port 8000