Infrastructure

This section covers the infrastructure setup required for OCS.io deployment.

Basically, you do not need to change anything in the docker-compose-infra.yml file:

version: "3.4"


networks:
  ocs-app-network:
    external: true


services:

  # *** Database PostgreSQL ***
  ocs-db-server:
    container_name: ${DNS_DB_SERVER}
    build:
      context: ./postgres
      dockerfile: dockerfile
    image: 'ocs-postgres'
    restart: always
    environment: 
      POSTGRES_DB: '${POSTGRES_DATABASE}'
      POSTGRES_USER: '${POSTGRES_USERNAME}'
      POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
      LC_COLLATE: '${POSTGRES_COLLATE}'
      LC_CTYPE: '${POSTGRES_CTYPE}'
    volumes: 
      - "${FS_POSTGRES_DATA}:/var/lib/postgresql/data"
    ports:
      - "${POSTGRES_PORT_EXT}:${POSTGRES_PORT_INT}"
    networks:
      - ocs-app-network

#  # *** Redis Cache Server ***
  ocs-cache-server:
    container_name: ${DNS_CACHE_SERVER}
    build:
      context: ./redis
      dockerfile: dockerfile
    image: 'ocs-redis'
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    restart: always
    ports:
      - "${REDIS_PORT_EXT}:${REDIS_PORT_INT}"
    volumes:
      - "./redis/redis.conf:/usr/local/etc/redis/redis.conf"
    networks:
      - ocs-app-network

  # *** Rabbit MQ incl. Management console ***
  ocs-rabbitmq:
    container_name: ${DNS_RABBITMQ}
    image: rabbitmq:3-management
    restart: always
    environment:
      RABBITMQ_DEFAULT_USER: '${RABBIT_USERNAME}'
      RABBITMQ_DEFAULT_PASS: '${RABBIT_PASSWORD}'
    ports:
      - "${RABBIT_PORT_EXT}:${RABBIT_PORT_INT}"
      - "${RABBIT_MGMT_PORT_EXT}:${RABBIT_MGMT_PORT_INT}"
    networks:
      - ocs-app-network

Now, let’s break down each component of the infrastructure:

Docker Network

Network name cannot be defined as Environment variable, hence pay attention to define network inside Docker-Compose files. By default, network name is ocs-app-network and is defined as external:

networks:
  ocs-app-network:
    external: true

To create an External network, you have to do this like:

docker network create ocs-app-network

OCS DB Server

The OCS DB Server is created from a standard PostgreSQL container which is little bit tweaked. It is essential for storing OCS.io’s data.

First, we create ./postgres/dockerfile for our custom PostgreSQL container.

# Use the official PostgreSQL image as the base image
FROM postgres:latest

# Install locales package and generate the C.utf8 locale
RUN apt-get update && apt-get install -y locales && locale-gen C.utf8

The purpose of custom dockerfile is to install support for C.utf8 locale which is crucial for some SQL queries performed in the OCS.io.

Service section for ocs-db-server in docker-compose-infra.yml file looks like:

  # *** Database PostgreSQL ***
  ocs-db-server:
    container_name: ${DNS_DB_SERVER}
    build:
      context: ./postgres
      dockerfile: dockerfile
    image: 'ocs-postgres'
    restart: always
    environment:
      POSTGRES_DB: ${POSTGRES_DATABASE}
      POSTGRES_USER: ${POSTGRES_USERNAME}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      LC_COLLATE: ${POSTGRES_COLLATE}
      LC_CTYPE: ${POSTGRES_CTYPE}
    volumes:
      - ${FS_POSTGRES_DATA}:/var/lib/postgresql/data
    ports:
      - "${POSTGRES_PORT_EXT}:${POSTGRES_PORT_INT}"
    networks:
      - ocs-app-network

Please pay special attention to the environment section, particularly the LC_COLLATE and LC_CTYPE parameters. The default postgres image includes a limited number of locales. These parameters ensure that the PostgreSQL instance is using the en_US.utf8 locale, which is important for data consistency and compatibility.

Additionally, in the volumes section, there is a configuration for mounting a volume. This volume is used to securely store OCS.io’s data.

OCS Cache Server

As the Cache Server, we utilize the Alpine distribution of the REDIS container.

First, we create ./redis/dockerfile for our custom REDIS container.

# Use the official Redis alpine base image
FROM redis:alpine

# Add your custom kernel parameter settings
RUN echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

# Take effect immediatelly
# RUN sysctl vm.overcommit_memory=1

The purpose of custom dockerfile is to enable REDIS to be run in-memory only.

Second, we create ./redis/redis.conf file with REDIS configuration. Please note, that listed bellow is only minimal configuration, real Production deployment will require more tuning.

# extract from default /opt/bitnami/redis/etc/redis.conf
bind 0.0.0.0

appendonly no
save ""

maxmemory 128mb
maxmemory-policy allkeys-lru

### not complete, needs more tunning

Service section for ocs-cache-server in docker-compose-infra.yml file looks like:

#  # *** Redis Cache Server ***
  ocs-cache-server:
    container_name: ${DNS_CACHE_SERVER}
    build:
      context: ./redis
      dockerfile: dockerfile
    image: 'ocs-redis'
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    restart: always
    ports:
      - "${REDIS_PORT_EXT}:${REDIS_PORT_INT}"
    volumes:
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
    networks:
      - ocs-app-network

An important configuration is line 8. command: ["redis-server", "/usr/local/etc/redis/redis.conf"]. This command setup ensures that REDIS will load redis.conf file and runs in-memory only without any data persistence, which is crucial for performance.

OCS Rabbit MQ incl. Management Console

OCS Rabbit MQ is created from a standard RabbitMQ container. This component is essential for managing messaging within the OCS.io solution. No specific parameters are set in this configuration.

Service section for ocs-rabbitmq in docker-compose-infra.yml file looks like:

  # *** Rabbit MQ incl. Management console ***
  ocs-rabbitmq:
    container_name: ${DNS_RABBITMQ}
    image: rabbitmq:3-management
    restart: always
    environment:
      RABBITMQ_DEFAULT_USER: "${RABBIT_USERNAME}"
      RABBITMQ_DEFAULT_PASS: "${RABBIT_PASSWORD}"
    ports:
      - "${RABBIT_PORT_EXT}:${RABBIT_PORT_INT}"
      - "${RABBIT_MGMT_PORT_EXT}:${RABBIT_MGMT_PORT_INT}"
    networks:
      - ocs-app-network