Docker compose files for the deployment of the multi-container production and development environments of DengueChat. This tool is for DengueChat Developers and System Administrators who whish to install and run their local instances of DengueChat.
Before you start, you will need to have the following installed in your machine:
- PostgreSQL
- Docker
- Docker compose
- Git
- AWS account credentials (for testing or deployment in production mode)
- Get the code for DengueChat: get a copy of DengueChat's code from GitHub and step inside the directory where the code is cloned. We will refer to this directory as the code home from here on. Checkout the
develop
branch and branch out of it if you want to contribute to development.
git clone https://github.com/socialappslab/denguetorpedo.git
cd denguetorpedo
# For development or testing
git checkout develop
- Prepare a log directory: create a directory named
log
inside the Code Home. This is to avoid errors when the system tries to create the log file:
mkdir log
cd ..
- Get the docker compose files: get DengueChat's docker compose from this repository and step inside this directory to build and run the containers. We will refer to this directory as the Docker Compose Home from here on.
git clone https://github.com/socialappslab/denguechat-compose.git
cd denguechat-compose
- [IMPORTANT FOR DEVELOPERS]: create your docker compose file by renaming the proper base
.yml
file.
If you would like to run this on a local machine, for development purposes, use the docker-compose.localdev.yml
as the base file
cp docker-compose.localdev.yml docker-compose.yml
For deployment in a server for testing or production environments, you can work with the default docker-compose.server.yml
file.
cp docker-compose.server.yml docker-compose.yml
- Configure the docker-compose.yml (1): in the
docker-compose.yml
file, replace the text variable<local_folder_of_cloned_denguetorpedo_git_project>
with the path to the Code Home in thehost
. For example, suppose your Code Home is/home/user/projects/denguetorpedo
, you volume should be configured as follows:
volumes:
- /home/user/projects/denguetorpedo:/home/dengue/denguetorpedo
- Configure the docker-compose.yml (2): in the
docker-compose.yml
file, replace the variable<local_folder_for_redis>
with the path where you want to store redis data and configuration in thehost
. For example, suppose we created/opt/redis
in thehost
and want to use it to share with the redis container, the line should become the following:
volumes:
- /home/user/projects/denguechat-compose/redis/redisVolume:/bitnami
- Configure the docker-compose.yml (3): if you are using the
localdev
branch, you should configure the ENV variable${HOST_IP}
to point to the IP address of the PostgreSQL server. If you are running postgres locally, that would be yourhost
machine (i.e., your local development machine or server IP). For this to work, the postgres server will have to be properly configured. See the section Database below for more notes about configuring your database. You can use the scriptsetenv_compose.localdev.sh
to add theHOST_IP
variable to your environment, before building the containers. Make sure the command in this script is correct for your local environment. If it is not, you can create your own version with the proper command to set theHOST_IP
to the host machine IP.
chmod +x setenv_compose.sh
. ./setenv_compose.sh
- Prepare your environment variables (1): create a copy of the file
.env.sample
and name it.env
cp .env.sample .env
- Prepare your environment variables (2): in the new
.env
file, edit theDATABASE_URL
variable so that it includes the correct databaseuser
,password
andname
as you have them configured on your local host machine PostgreSQL installation:- Replace
postgres:postgres
with theusername:password
of your host database: - Replace
<ingresar_nombre_base_datos>
with the right database name. - The formatting of this variable is shown below:
- Replace
DATABASE_URL=protocol://username:password@postgreshost:port/database
-
Prepare your environment variables (3): in the new
.env
file, edit theREDIS_PASSWORD
variable with the password you would like to configure. If you have an AWS account, use your credentials to configure theAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. -
Build and run REDIS:
docker-compose build redis && docker-compose up -d redis
Notes:
- Remember you can run
docker-compose up
without the -d if you want to see the output of this process in foreground. If you run it with the -d flag, you can usedocker-compose logs
command to explore the logging output in search for potential issues or problems. - If you have a failure when the docker tries to run thesudo apt-get update
command, see the sectionDOCKERFILE
below for a potential fix.
- Build and run the container of DengueChat:
docker-compose build && docker-compose up -d
Notes:
- Remember that you can run
docker-compose up
without the -d if you want to see the output of this process in foreground. If you run it with the -d flag, you can usedocker-compose logs
command to explore the logging output in search for potential issues or problems.
- If all went well, you should now be able to access DengueChat's User Interface from your browser at
http://localhost:5000
. You can set up a user with admin rights for local testing by editing the tableadmin_users
and changing the encrypted passwords or adding a record. Passwords are encrypted withbcrypt-ruby
for reference.
- View denguetorpedo container logs:
docker logs -f denguetorpedo
- View redis container logs:
docker logs -f denguetorpedo-redis
- Accessing the denguetorpedo container:
docker exec -t -i denguetorpedo /bin/bash
- Accessing the redis container: use the same command only changing the name of the container.
- View sidekiq logs: access the container (3) en run
tail -f -n1 home/dengue/denguetorpedo/log/sidekiq.log
For local development, you can take a look at this article. You can also check out this other article to learn more
The version that works best for the current codebase is: rbenv local 2.3.0
Puma's GEM v2.11.2 gives sometimes an installation error, which can be fixed doing as follow in the host machine and the container:
- Install openssl:
brew install openssl
- Install puma using ssl:
gem install puma -v '2.11.2' --source 'http://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include
Note: the line above is also part of the Dockerfile now, but just in case you can install it in the host.
The file denguechat-compose/denguetorpedo/Dockerfile
now contains the following command before running apt commands:
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list
You can either use your host provided postgres (if you have one running) or create your own postgres container.
- Modify the
postgresql.conf
file, typically located at/usr/local/var/postgres/postgresql.conf
, and add the following, if not there:listen_addresses='*'
- Modify the
pg_hba.conf
file, typically located at/usr/local/var/postgres/pg_hba.conf
, and add the following:
host all all 0.0.0.0/0 md5
local all postgres md5
- If you have a backup, you can recover data as follows:
psql denguetorpedo < denguetorpedo.sql
- If you have an error with the role 'XXXX'. You need to create a role with the name 'XXXX' or comment the line where the role 'XXXX' appears in the sql file.