Repository navigation
Linux WSL2 Production Setup v2
This page provides detailed instructions for configuring and deploying the v2 production environment for The Wall API on Linux. It outlines the steps for preparing required files, setting up services, and managing the application for a reliable production deployment. The main difference from the v1 production setup is the use of Docker Swarm for orchestrating services instead of standalone Docker Compose.
📝 All console commands in this section must be executed from the folder, where the config folder is placed.
1. Set up the PROD(v2) environment configuration:
-
Ensure the following folder structure and files are placed in a folder of your choice:
-
Application configuration files:
config/envs/common/redis.confconfig/envs/prod/the_wall_api_prod.env
💡 Check the *.example files in the
config/envs/folder of the repository for example values. -
Linux scripts files:
💡 If the files were manually copied or downloaded instead of using git clone, ensure that they have executable permissions:
chmod +x config/scripts/linux/refresh_allowed_hosts_wsl2.sh chmod +x config/scripts/linux/common_utils.sh
-
Docker secrets files (containing the PostgreSQL and Redis credentials):
config/secrets/django_secret_key.txtconfig/secrets/postgres_db.txtconfig/secrets/postgres_password.txtconfig/secrets/postgres_user.txtconfig/secrets/redis_password.txt
💡 Check the *.example files in the
config/secrets/folder of the repository for example values.
-
2. Init docker swarm mode
docker swarm init
3. Create the host machine docker secrets for the PostgreSQL and Redis passwords:
docker secret create django_secret_key config/secrets/django_secret_key.txt
docker secret create postgres_db config/secrets/postgres_db.txt
docker secret create postgres_password config/secrets/postgres_password.txt
docker secret create postgres_user config/secrets/postgres_user.txt
docker secret create redis_password config/secrets/redis_password.txt
💡 Verify that the secrets are created correctly:
docker secret ls
🗒️ Note: Secrets are securely mounted as files when the app's docker containers are initialized, allowing the relevant services to use them during runtime. In docker swarm mode, secrets are encrypted and securely managed by the swarm manager, ensuring credentials are not hardcoded insecurely.
❗ Important: In real-life scenarios backup the passwords and remove the secrets files from the config/secrets/ folder after the secrets are created.
4. Docker stack deploy:
- Ensure the
docker-compose-prod-v2.ymlfile from the repository is placed in theconfig/docker/folder.
🗒️ Note: Once the secrets are created in the system, the files and folders outlined in sections 1. and 4. are sufficient to initialize and start the app without any additional files from the repository.
5. Workflow to start and manage the application:
-
5.1 Start the app, the Redis and PostgreSQL services, the Celery workers and the Celery beat service by deploying the prod_stack:
config/scripts/linux/refresh_allowed_hosts_wsl2.sh --deployment_mode=prod_v2 docker stack deploy -c config/docker/docker-compose-prod-v2.yml prod_stack --detach=true
💡 Verify that all containers in the stack are running:
docker stack ps prod_stack
-
5.2 Send requests to the API endpoints:
- http://
WSL2 IP:8000/api/v2/swagger-ui/
💡 Refer to the description of the
refresh_allowed_hosts_wsl2.shscript forWSL2 IPdetails. - http://
-
5.3 To stop the app:
docker stack rm prod_stack
📌 Action required: To use the other setups, remove all images and volumes, related to the app and the Celery services:
💡 Verify that there are no running containers first:
docker stack ps prod_stack
💡 When all containers are stopped:
docker volume rm the_wall_api_redis_data_prod
docker volume rm the_wall_api_postgres_data_prod
docker volume rm the_wall_api_celery_beat_schedule_prod
docker volume rm the_wall_api_shared_sim_logs_prod
docker rmi ghcr.io/alexandar83/the-wall-api
docker rmi ghcr.io/alexandar83/celery-lightweight
🗒️ Note: The images for the Redis and PostgreSQL services can be reused in all setups.
💡 Verify that the volumes and images are removed:
docker volume ls
docker images
💡 If either of the images becomes untagged, it has to be removed by its image id:
docker rmi <image_id>Return to Top
Installation Instructions Index
Home Page
📌 Notable Technical Sections
👤 Author
LinkedIn: Aleksandar Dimitrov
Yahoo: sasho_1983@yahoo.com