Web Server Setup

Compose is a tool for defining and running multi-container Docker applications.

Install compose https://docs.docker.com/compose/install/

Note: Install docker CE or EE version. Docker CS is not supported and permission errors may be experienced if using Docker CS version.
Docker CS (Commercially Supported) is kind of the old bundle version of Docker EE for versions <= 1.13.

Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

ServiceCurrentNew
mysqllocalhost:3306mysql:3306
couchdblocalhost:5984couchdb:5984
couchdb-lucenelocalhost:5985couchdb-lucene:5985
activemqlocalhost:61616activemq:61616

Steps for setting up OpenSRP docker container

  1. Checkout opensrp docker builds and navigate to the composed directory.
    Below is the list of build time args

    #Build arguments
    ARG opensrp_server_tag
    
    #openmrs settings
    ARG openmrs_url="http:\/\/localhost:8080\/openmrs\/"
    ARG openmrs_username=admin
    ARG openmrs_password=Admin123
    
    #couchdb settings
    ARG couchdb_username
    ARG couchdb_password
    ARG couchdb_opensrp_db=opensrp
    ARG couchdb_form_db=opensrp-form
    ARG couchdb_atomfeed_db=atomfeed
    ARG couchdb_mcts_db=opensrp-mcts
    ARG couchdb_motech_db=motech-scheduletracking-api
    ARG couchdb_error_db=opensrp-errortrace
    #mysql settings
    ARG mysql_opensrp_user
    ARG mysql_opensrp_password
    ARG mysql_opensrp_database
    ARG mysql_openmrs_user
    ARG mysql_openmrs_password
    ARG mysql_openmrs_database
    ARG mysql_motech_database
    ARG mysql_reporting_database
    ARG mysql_anm_database
    ARG mysql_opensrp_jdbc="jdbc:mysql:\/\/mysql:3306\/${mysql_opensrp_database}?createDatabaseIfNotExist=true"
    ARG mysql_opensrp_jdbc_wo="jdbc:mysql:\/\/mysql:3306"
    ARG mysql_motech_jdbc="jdbc:mysql:\/\/mysql:3306\/${mysql_motech_database}"
    
    #redis settings
    ARG redis_password
    
    #postgres settings
    ARG postgres_opensrp_user
    ARG postgres_opensrp_password
    ARG postgres_opensrp_database
    ARG postgres_opensrp_jdbc="jdbc:postgresql:\/\/postgres:5432\/${postgres_opensrp_database}"
    
    ARG demo_data_tag
  2. Create .env file to store variables and credentials. For example, create a file with the following details..

    #!/bin/sh
    POSTGRES_OPENSRP_TABLESPACE_DIR=/opt/postgresql
    POSTGRES_OPENSRP_DATABASE=opensrp
    POSTGRES_OPENSRP_USER=opensrp_admin
    POSTGRES_OPENSRP_PASSWORD=admin
    MYSQL_ROOT_PASSWORD=mypassword
    MYSQL_MOTECH_DATABASE=motechquartz
    MYSQL_REPORTING_DATABASE=report
    MYSQL_ANM_DATABASE=anm
    MYSQL_OPENMRS_USER=openmrs
    MYSQL_OPENMRS_PASSWORD=openmrs
    MYSQL_OPENMRS_DATABASE=openmrs
    MYSQL_OPENSRP_USER=opensrp
    MYSQL_OPENSRP_PASSWORD=opensrp
    MYSQL_OPENSRP_DATABASE=opensrp
    COUCHDB_USER=rootuser
    COUCHDB_PASSWORD=adminpass
    REDIS_PASSWORD=reallylongreallylongpassword
    OPENSRP_SERVER_TAG=opensrp_server_tag                                             

    These environment variables are used at runtime and also as build time arguments when building docker images for opensrp-composed and migrations containers.

    Note: You can add an optional DEMO_DATA_TAG environment variable so that the launched  containers contains demo(seed) data for a particular project. The value should be either zeir, tbreach or uganda-hpv. If the environment variable is set  openmrs database, opensrp database and images will be downloaded from S3 bucket. 


    Note: If you want to override a build argument with a default constant expose it in the args section of a service in the docker compose file. To expose a build argument called custom_build_arg that is populated from MY_ARG environment variable, see the below example

    migrations:
          build:
            context: .
            dockerfile: ./Dockerfile
            args:
              - custom_build_arg=${MY_ARG}
  3. Run compose up

    docker-compose up -d 

    Alternatively if you want to rebuild the containers use

    docker-compose up --force-recreate --remove-orphans --build -d
  4. Link couchdb with lucene.
     Go to couchdb container

    docker exec -it composed_couchdb_1 bash

    update /usr/local/etc/couchdb/local.ini i.e. append the following lines

    [couchdb]
    os_process_timeout=60000 ; increase the timeout from 5 seconds.
    
    [external]
    fti=/usr/bin/python /opt/couchdb-lucene/tools/couchdb-external-hook.py
    
    [httpd_db_handlers]
    _fti = {couch_httpd_external, handle_external_req, <<"fti">>}
    
    [httpd_global_handlers]
    _fti = {couch_httpd_proxy, handle_proxy_req, <<"http:\\couchdb-lucene:5985">>}

    NB: Checkout Cloudant Sync Security Configuration to configure couchdb security.

  5. Test the services

    ServiceLinkCredentials
    OpenSRP http://localhost:9090/opensrp
    OpenMRS http://localhost:9091/openmrsadmin/Admin123

Some useful commands

CommandDescription

docker-compose down

stop containers
docker-compose rm -fremove containers
docker-compose up --force-recreate --remove-orphans --buildrecreate containers when building
docker volume ls | grep volume_namelist mounted volumes
docker volume rm volume_namedelete volume

docker-compose down -v

Stop container and delete volumes

References

https://docs.docker.com/compose/

https://docs.docker.com/compose/networking/

https://hub.docker.com/_/mysql/

https://hub.docker.com/_/couchdb/

https://github.com/klaemo/docker-couchdb-lucene

https://hub.docker.com/r/rmohr/activemq/

OpenSRP Server Build

Server for your App in 15 mins