-
Cloning and accessing the repository:
git clone \ https://github.com/RenanMMaciel/technical-challenge-cubos-devops.git && \ cd technical-challenge-cubos-devops/
-
Make the setup script executable and run the setup script:
chmod +x ./setup.sh && ./setup.sh -
After running the setup script
setup.sh, the following steps will be performed:-
The script checks if the repository already contains the
.envfile in thebackenddirectory. -
If the
.envfile exists, the script will verify whether the required variables are defined:POSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_DBDATABASE_ADMIN_PASSWORD
-
If the
.envfile does not exist or is missing any of the required variables, the script will:- Prompt the user to input the missing variables.
- Either create a new
.envfile in thebackenddirectory or update the existing one with the missing variables.
-
-
After that, the infrastructure will be set up, and the services will go up.
-
Frontend: A static web application served by Nginx, configured to act as a reverse proxy to the backend service.
Access URL: http://localhost:80 -
Backend: A Node.js application that interacts with the database, exposing an API for the frontend to consume.
Access URL: http://localhost:8080/api -
Database: A PostgreSQL database instance used to store application data, including user credentials and other structured information.
Access: Accessible internally by backend atdatabase:5432. Usepsqlfor direct access. -
Prometheus: A monitoring and alerting toolkit used to scrape and collect metrics from services frontend, backend and database.
Access URL: http://localhost:9090 -
Grafana: A visualization and analytics platform used to create dashboards and analyze metrics collected by Prometheus.
Access URL: http://localhost:3000 -
Postgres Exporter: A Prometheus exporter used to collect PostgreSQL database metrics, exposing them for Prometheus to scrape.
Access URL: http://localhost:9187
-
Internal:
A private network used for communication between backend and database.
Services: Backend and Database. -
External:
A public-facing network that connects the frontend service to external clients and allows communication with the backend.
Services: Frontend and Backend. -
Monitoring:
A dedicated network for monitoring services like Prometheus and Grafana, ensuring isolation from application traffic.
Services: Frontend, Backend, Database, Prometheus, Grafana and Postgres Exporter.
-
The
setup.shscript is designed to verify the operating system in use and dynamically adjust theDOCKER_HOSTvariable for the Docker provider in the Terraform configuration. This ensures that the correct communication path is used for Docker, depending on the environment.- For Linux systems, the
DOCKER_HOSTvariable is set tounix:///var/run/docker.sock. - For Windows systems, the
DOCKER_HOSTvariable is set tonpipe:////./pipe/docker_engine.
The adjusted variable is then passed to the Terraform docker provider configuration, ensuring that all Docker-related operations, such as building images and managing containers, are executed correctly on the target OS.
- For Linux systems, the
-
All containers are configured with a
restart: alwayspolicy to ensure that services automatically restart in case of failure or system reboot. -
Persistent volumes (
database_dataanddatabase_logs) ensure data durability across container restarts.
technical-challenge-cubos-devops/
├── README.md
├── backend
│ ├── Dockerfile
│ ├── index.js
│ └── package.json
├── database
│ └── script.sh
├── frontend
│ ├── Dockerfile
│ ├── index.html
│ └── nginx.conf
├── monitoring
│ ├── grafana
│ │ └── prometheus-datasource.yml
│ └── prometheus
│ └── prometheus.yml
├── setup.sh
└── terraform
├── containers.tf
├── images.tf
├── networks.tf
├── providers.tf
├── variables.tf
└── volumes.tf