Infrastructure

This document provides an overview and documentation for the API implemented using Docker containers and the provided configuration files (Dockerfile, docker-compose.yml, and .env).

Docker Container Setup

The API is designed to run inside a Docker container. The container includes the necessary dependencies and configurations for the API to function properly. The Docker container is built using the provided Dockerfile.

Dockerfile

FROM node:20-alpine

LABEL maintainer="Hxtninfosec | MasterBigD | Ezeqielle"

# Create App directory for the project
RUN mkdir /app

# Change directory to /app
WORKDIR /app

# Copy all necessary files
COPY . .

RUN npm install --save
# If you are building your code for production
# RUN npm ci --omit=dev

# Set timezone
ENV TZ="Europe/Paris"

EXPOSE 5000

CMD [ "node", "app.js" ]

The Dockerfile sets up the Docker container by:

  1. Using the node:20-alpine base image.
  2. Creating an /app directory inside the container.
  3. Changing the working directory to /app.
  4. Copying all files from the current directory (the API source code) into the container's /app directory.
  5. Installing the required dependencies using npm install.
  6. Setting the timezone to Europe/Paris (change as needed).
  7. Exposing port 5000 for the API to listen on.
  8. Specifying the command to run the API using CMD [ "node", "app.js" ].

Docker Compose Setup

To simplify the deployment and management of the API and its dependencies, Docker Compose is used. The docker-compose.yml file defines the services and their configurations.

docker-compose.yml

version: '3.1'

services:
  mariadb:
    image: mariadb
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASS}
    volumes:
    - ./main.sql:/docker-entrypoint-initdb.d/dump.sql
    networks:
      - backend

  adminer:
    image: adminer
    restart: always
    environment:
      ADMINER_DEFAULT_SERVER: mariadb
    depends_on:
      - mariadb
    networks:
      - backend
      - frontend
    ports:
      - 8080:${ADMINER_PORT}

  backend:
    build: ./backend
    depends_on:
      - mariadb
    volumes:
      - ./backend/app.js:/app/app.js
      - cthulhu-backend:/CTHULHU
    environment:
      DB_HOST: mariadb
      DB_USER: ${DB_USER}
      DB_MAIN: ${DB_MAIN}
      DB_PASS: ${DB_ROOT_PASS}
    networks:
      - backend
      - frontend
    ports:
      - 5000:${BACKEND_PORT}

  frontend:
    restart: always
    build: ./frontend
    ports:
      - 443:443
    networks:
      - frontend

networks:
  backend:
  frontend:

volumes:
  cthulhu-backend:

The docker-compose.yml file defines three services: mariadb, adminer, and backend.

mariadb Service

The mariadb service runs a MariaDB database server. It uses the specified root password and is connected to the backend network.

adminer Service

MariaDB service (mariadb).

The adminer service provides a web-based database management interface. It depends on the mariadb service and is connected to both the backend and frontend networks. The specified port is exposed for accessing the Adminer interface.

backend Service

The backend service builds the API using the source code located in the ./backend directory. It depends on the mariadb service and mounts the local app.js file and the cthulhu-backend named volume. The environment variables define the database connection details. It is connected to both the backend and frontend networks, and the specified port is exposed for accessing the API.

.env File

DB_ROOT_PASS=toor
DB_USER=root
DB_MAIN=CTHULHU
BACKEND_PORT=5000
ADMINER_PORT=8080

The .env file contains environment variable definitions used by the Docker Compose configuration. It includes the following variables:

Make sure to adjust these values as needed for your specific deployment.