Welcome to the SAEMicroServices project! This document provides an overview of how to set up and run the project in both development and production environments using Docker.
If you are using windows, you may encounter an issue with the line endings. To fix this, you can change the line ending of .sh
files to LF. You can use the following script to do this:
@echo off
setlocal enabledelayedexpansion
set "rootDir=."
:: Loop through all .sh files in the directory and its subdirectories
for /r "%rootDir%" %%f in (*.sh) do (
:: Use 'type' command to display the file content and redirect output to a temporary file with Unix line endings (LF)
type "%%f" | findstr /v /r "^$" > "%%f.tmp"
move /y "%%f.tmp" "%%f" >nul
)
echo Conversion to LF completed.
endlocal
The [Docker-test
] directory contains the Docker configuration for the development environment. It includes Dockerfiles for the API, Frontend, and other needed services, as well as a [docker-compose.yml
] file for orchestrating the containers.
-
Copy the [
.env.example
] file in the [Docker-test
] directory to a new file named.env
and adjust the environment variables according to your development setup.cp Docker-test/.env.example Docker-test/.env
-
The
.env
file includes configurations for Postgres, PgAdmin, Django, NATS, and Traefik. Make sure to set theDJANGO_ENVIRONMENT
variable totest
for the development setup (standalon development of the applications usesdevelopment
but this is when ran outside docker). -
To start the development environment, navigate to the
Docker-test
directory and run:docker-compose up --build
This will build and start all the necessary containers for the development environment, including the Django API, Frontend, and the required services like Postgres and NATS.
- Django API: Accessible at
https://api.your-domain/api/common
- Frontend: Accessible at
https://your-domain
- PgAdmin: Accessible at
https://pgadmin.your-domain
Edit and use the hosts.sh
or hosts.bat
script (as admin or sudo) to add the domain to your hosts file if it's a local setup.
your-domain
should be set under the ENV variable DOMAIN
.
The [Docker
] directory contains the Docker configuration for the production environment. It includes Dockerfiles for the API, Frontend, and other needed services, along with a [docker-compose.yml
] file for orchestrating the containers.
The difference between the development and production environments is that the production environment uses nginx to serve static as it uses daphne, an asgi, as a web server and doesn't launch the pgadmin docker.
It also uses the DJANGO_ENVIRONMENT
variable set to production
in the .env
file and secure the DEBUG_MODE
, DJANGO_SECRET_KEY
, DJANGO_ALLOWED_HOSTS
, and CSRF_ALLOWED_ORIGINS
variables.
-
Copy the [
.env.example
] file in the [Docker
] directory to a new file named.env
and adjust the environment variables according to your production setup.cp Docker/.env.example Docker/.env
-
The
.env
file includes configurations for Postgres, Django, NATS, and Traefik. Make sure to set theDJANGO_ENVIRONMENT
variable toproduction
for the production setup. -
To start the production environment, navigate to the
Docker
directory and run:docker-compose up --build
This will build and start all the necessary containers for the production environment, including the Django API, Frontend, Database, and NATS.
- Django API: Accessible at
https://api.your-domain/api/common
- Frontend: Accessible at
https://your-domain
Edit and use the hosts.sh
or hosts.bat
script (as admin or sudo) to add the domain to your hosts file if it's a local setup.
your-domain
should be set under the ENV variable DOMAIN
.
- For detailed information on the environment variables and their purposes, refer to the [
Docker-test/.env.example
] and [Docker/.env.example
] files. - Ensure that the Docker and Docker-compose are installed on your system to use these configurations.
- The project uses NATS for messaging, Postgres for the database, and Django for both the API and frontend in development. Adjustments may be necessary based on your specific requirements (as an example, you may use real certificates for the production environment).
For more information on the individual components, refer to the README files located in their respective directories.