This is an example microservice written in Django, intended to be used as part of 2hog's Docker trainings.
Implements a single endpoint (GET /) which:
- Requires session authentication
- Requests a greeting via a
POSTrequest from the greeting service - Requests an HTML fragment for the received greeting via a
GETrequest from the content service - Returns an HTML document to the user, including the received HTML fragment
The Django Sample Microservice accepts configuration via environment variables:
POSTGRES_HOST: The hostname of the Postgres server (default:postgres)POSTGRES_USER: The Postgres user of the database (default:postgres)POSTGRES_PASSWORD: The password of the Postgres user(default:password)POSTGRES_PORT: The port to which the Postgres server listens (default:5432)ALLOWED_HOSTS: TheHostheader values allowed to be used in this microservice (default:localhost)POSTGRES_DB: The Postgres database to use (default:postgres)SECRET_KEY: Secret key used by Django for cookie signing (default:thisshouldstaysecretforchristssake)GREETING_APP_URL: The host of the greeting service (default:http://greeting:4567/)GREETING_APP_USER: The user to use for Basic Authentication in the greeting service (default:paris)GREETING_APP_PASSWORD: The password to use for Basic Authentication in the greeting service (default:kasidiaris)CONTENT_APP_URL: The host of the content service (default:http://content:5000/)CONTENT_APP_USER: The user to use for Basic Authentication in the content service (default:antonis)CONTENT_APP_PASSWORD: The password to use for Basic Authentication in the content service (default:kalipetis)
The Django Sample Microservice also accepts and prefers configuration as secret files for the following settings:
/run/secrets/database_url: The full connection URL for the PostgreSQL database/run/secrets/greeting_app_url: The host of the greeting service/run/secrets/greeting_app_user: The user to use for Basic Authentication in the greeting service/run/secrets/greeting_app_password: The password to use for Basic Authentication in the greeting service/run/secrets/content_app_url: The host of the content service/run/secrets/content_app_user: The user to use for Basic Authentication in the content service/run/secrets/content_app_password: The password to use for Basic Authentication in the content service
docker secret create micro-django-database-url -
docker secret create micro-django-secret-key -
docker secret create micro-django-greeting-app-url -
docker secret create micro-django-greeting-app-user -
docker secret create micro-django-greeting-app-password -
docker secret create micro-django-content-app-url -
docker secret create micro-django-content-app-user -
docker secret create micro-django-content-app-password -
docker stack deploy -c docker-compose.yml docker-training-samples-micro-djangokubectl create secret generic docker-training-samples-micro-django-configmap \
--from-literal=allowed_hosts="${HOSTNAME}.akalipetis.com"
kubectl create secret generic docker-training-samples-micro-django-secret \
--from-literal=database_url=postgres://postgres:password@docker-training-samples-postgres:5432/postgres \
--from-literal=postgres_host=docker-training-samples-postgres \
--from-literal=postgres_user=postgres \
--from-literal=postgres_password=password \
--from-literal=postgres_port=5432 \
--from-literal=postgres_db=postgres \
--from-literal=secret_key=thisshouldstaysecretforchristssake \
--from-literal=greeting_app_url=http://docker-training-samples-sinatra:4567/ \
--from-literal=greeting_app_user=paris \
--from-literal=greeting_app_password=kasidiaris \
--from-literal=content_app_url=http://docker-training-samples-flask:5000/ \
--from-literal=content_app_user=antonis \
--from-literal=content_app_password=kalipetis
kubectl apply -f kube/To develop the Django Sample Microservice, follow these steps:
- Install Docker (docs) and Docker Compose (docs)
- Clone this repository:
git clone https://github.com/2hog/docker-training-samples-micro-django - Launch the app with Docker Compose:
docker-compose up - Open your repository with your editor and rock n' roll!
This software is MIT licensed.