External database connection (PostgreSQL)

Note

Make sure that the version of the external service matches the version specified in the docker-compose.yml file.

  1. Prepare an external database (PostgreSQL) for each service (databases' names: db, authdb, avatarsdb):

    yum install postgresql-contrib
    psql -U postgres
    create database testgeardb;
    create user tester with encrypted password 'tester';
    grant all privileges on database testgeardb to tester;
    \connect testgeardb;
    CREATE EXTENSION if not exists "uuid-ossp" SCHEMA public;
    
  2. For other databases (authdb, avatarsdb) run the script below by replacing testgeardb with the database name:

    • For authdb:
      create database authdb;
      grant all privileges on database authdb to tester;
      \connect authdb;
      CREATE EXTENSION if not exists "uuid-ossp" SCHEMA public;
      
    • For avatarsdb:
      create database avatarsdb;
      grant all privileges on database avatarsdb to tester;
      \connect avatarsdb;
      CREATE EXTENSION if not exists "uuid-ossp" SCHEMA public;
      
  3. Comment out the database service section (authdb, avatars.db, db) that would be replaced with an external database service, other container dependencies with the database service (the mentions of the database service in depends\_on blocks), and its volumes (authdb-volume, db-volume, avatars.db-volume) in the volumes list in the docker-compose.yml file.

  4. Add credentials (ip-external server/dns-name, port, login, password) for connecting to an external database to the .env file. You can specify either different DBMSs or the same DBMS for each database in the Host parameter.

    DB_CONNECTION_STRING=Host=external_server1;Port=5432;Database=testgeardb;Username=tester;Password=tester;Pooling=true;Maximum Pool Size=130
    #POSTGRES_DB=testgeardb
    #POSTGRES_USER=postgres
    #POSTGRES_PASSWORD=F1rstL0g0N!
    ...
    AUTH_CONNECTION_STRING=Host=external_server2;Port=5432;Database=authdb;Username=tester;Password=tester;Pooling=true;Maximum Pool Size=130
    #POSTGRES_AUTH_DB=authdb
    #POSTGRES_AUTH_USER=postgres
    #POSTGRES_AUTH_PASSWORD=F1rstL0g0N!
    ...
    AVATARS_CONNECTION_STRING=Host=external_server3;Port=5432;Database=avatarsdb;Username=tester;Password=tester
    #POSTGRES_AVATARS_DB=avatarsdb
    #POSTGRES_AVATARS_USER=postgres
    #POSTGRES_AVATARS_PASSWORD=F1rstL0g0N!
    
  5. By default, PostgreSQL is not configured for external connections. You must do it manually.

    Warning

    This step is not relevant if you use a database (DB) cluster or the database is a controlled solution (you are not the DB administrator). In these cases, you need to enable access to DB from TestGear containers depending on your configuration.

    To do that:

    1. In the postgresql.conf file, comment the following line:
      # listen_addresses = 'localhost'
      
    2. Add the following line to enable listen addresses for all interfaces:
      listen_addresses = '*'
      
    3. Add the following lines to the pg_hba.conf file:
      host    all             all              0.0.0.0/0                       md5
      host    all             all              ::/0                            md5
      
      The first line is for IPv4 addresses, and the second one is for IPv6 addresses. This configuration enables PostgreSQL to accept connections from any network.
    4. To enable connection with a certain subnet, specify the subnet address with with a CIDR mask. For example:
      host    all             all              192.168.101.20/24               md5
      
      Add addresses of subnets containing the servers with rabbitmq_consumer, webapi, auth, and avatars.api containers unless you use 0.0.0.0/0.
    5. Make sure that port listened by PostgreSQL (by default, port 5432) is open in your OS brandmauer.
  6. Install TestGear:

    docker-compose -f docker-compose.yml --project-name prod up --detach --timeout 120