As a non-German speaker living in Switzerland, I often need to quickly translate large texts, but I get annoyed by character limits on Google Translate or DeepL. Learning German may have been a way better call, but instead I decided to deploy a translation application. It's made of 3 containerized microservices:
- A Flask frontend to get inputs and display translations
- A FastAPI API backend to translate English text, using open-source models (SpaCy, Hugging Face)
- A MySQL database to store previous translations
In this repo, we deploy the app on a single node with Docker Compose, see also this blog post.
For the deployment on a Kubernetes cluster, see repo and this blog post.
We could deploy the app with Docker Compose but since Docker secrets are implemented for database credentials, we have to use Docker Swarm (it is actually not that clear and things are currently changing, see the official documentation, this issue and these pull requests: PR 1, PR 2). Using Docker Compose or a single-node swarm actually does not change anything from our perspective: the docker-compose.yaml
file is the same (except for the secrets!).
- Initiate Docker Swarm on your localhost
docker swarm init --advertise-addr 127.0.0.1
- Store credentials as Docker secrets:
db_root_password
: mandatory to create the MySQL databasedb_user
: user for the Flask front-end containerdb_password
: password for userdb_user
Syntax:
printf "<secret_value>" | docker secret create <secret_name> -
(pay attention to the ending hyphen)
e.g.
printf "Af_ey7hds7a45" | docker secret create db_root_password -
- Deploy app
docker stack deploy --compose-file docker-compose.yaml unlimited-translation
The app is deployed at http://localhost:5000
- Bring the app down
docker stack rm unlimited-translation
The data will be persisted in the database even if the stack is down. If you want to start with a fresh database for the next deployment, run:
docker volume rm unlimited-translation_unlimited_translation_database_volume
Finally, deactivate the Swarm mode if needed:
docker swarm leave --force