Skip to content

Add ability to connect to any mysql or redis database #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ PM_APP_URL=http://localhost
PM_APP_PORT=8080
PM_BROADCASTER_PORT=6004
PM_DOCKER_SOCK=/var/run/docker.sock
PM_DB_HOST=mysql
PM_DB_PORT=3306
PM_DB_NAME=processmaker
PM_DB_USERNAME=pm
PM_DB_PASSWORD=pass
PM_REDIS_HOST=redis
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This build has no enterprise packages.
- Docker Engine >= 3.2
- For Mac and Windows Users, we recommend [Docker Desktop](https://www.docker.com/products/docker-desktop)
- For other installation options: [Install Instructions](https://docs.docker.com/engine/install/)

- Docker Compose >= 1.2
- If using Docker Desktop, Compose is already included
- For all others: [Install Instructions](https://docs.docker.com/compose/install/)
Expand All @@ -27,6 +27,28 @@ This build has no enterprise packages.
| PM_BROADCASTER_PORT | Choose a different port for the Socket.io server if 6001 is in use on your host |
| PM_DOCKER_SOCK | Location of your docker socket file. See [note](#bind-mounting-the-docker-socket) |

If you are configuring the image to connect to a different mysql or redis database you can remove them from the docker compose file and then alter the following variables from their default values:

| Variable | Description |
| --- | --- |
| PM_DB_HOST | host for the mysql server |
| PM_DB_PORT | port for the mysql server |
| PM_DB_NAME | database name |
| PM_DB_USERNAME | mysql database username |
| PM_DB_PASSWORD | mysql database password |
| PM_REDIS_HOST | redis host |


1. Setup External DB *(optional)*

If you want to use a different mysql database other than the one in the compose file then you will need to change the custom env settings, remove mysql from the docker-compose file and setup the database and user in mysql. You can use the following commands to setup the datbase (Change the username and password to match what you put in the custom env file.)

```
create database processmaker CHARACTER SET utf8 COLLATE utf8_general_ci;
grant ALL on processmaker.* TO pm@'%' IDENTIFIED BY 'pass';
FLUSH PRIVILEGES;
```

1. Run `docker-compose up`

This will pull the image if it doesn't exist. It's >2 gigabytes so it could take some time.
Expand All @@ -49,7 +71,7 @@ This build has no enterprise packages.
## Building the application image locally
If you want to build your own version locally, run docker build with PM_VERSION set to a tag at https://github.com/ProcessMaker/processmaker/tags (without the leading 'v')
```
docker build --build-arg PM_VERSION=4.1.21-RC7 -t processmaker/pm4-core:local .
docker build --build-arg PM_VERSION=4.1.21 -t processmaker/pm4-core:local .
```
Then change PM_VERSION in .env to `local`

Expand Down Expand Up @@ -82,4 +104,4 @@ The goal is to have CircleCI do this automatically
### Use production build

Currently the image is built using development as the target (e.g. `npm run dev`). Building for production for Node and Composer packages
should greatly reduce the image size and might increase performance.
should greatly reduce the image size and might increase performance.
39 changes: 14 additions & 25 deletions build-files/init.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
set -ex

# # Wait for mysql to bec available
# while ! mysqladmin ping -u pm -ppass -h mysql --silent; do
# echo "Waiting for mysql"
# sleep 1
# done

# # Check if database has been initialized
# NUM_TABLES=$(mysql -u pm -p'pass' -h mysql -N -B -e 'show tables;' processmaker | wc -l)

# if [ $NUM_TABLES -eq 0 ]; then
# mysql -u pm -p'pass' -h mysql processmaker < mysqldump.sql
# fi
# This init file is run everytime the container instance starts

if [ ! -f ".env" ]; then

while ! mysqladmin ping -u pm -ppass -h mysql --silent; do
while ! mysqladmin ping -u pm -ppass -h ${PM_DB_HOST} -P ${PM_DB_PORT} --silent; do
echo "Waiting for mysql"
sleep 1
done
Expand All @@ -34,19 +23,19 @@ if [ ! -f ".env" ]; then
[email protected] \
--first-name=Admin \
--last-name=User \
--db-host=mysql \
--db-port=3306 \
--db-name=processmaker \
--db-username=pm \
--db-password=pass \
--db-host=${PM_DB_HOST} \
--db-port=${PM_DB_PORT} \
--db-name=${PM_DB_NAME} \
--db-username=${PM_DB_USERNAME} \
--db-password=${PM_DB_PASSWORD} \
--data-driver=mysql \
--data-host=mysql \
--data-port=3306 \
--data-name=processmaker \
--data-username=pm \
--data-password=pass \
--redis-host=redis
--data-host=${PM_DB_HOST} \
--data-port=${PM_DB_PORT} \
--data-name=${PM_DB_NAME} \
--data-username=${PM_DB_USERNAME} \
--data-password=${PM_DB_PASSWORD} \
--redis-host=${PM_REDIS_HOST}


echo "PROCESSMAKER_SCRIPTS_DOCKER=/usr/local/bin/docker" >> .env
echo "PROCESSMAKER_SCRIPTS_DOCKER_MODE=copying" >> .env
Expand Down
14 changes: 10 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@ services:
- PM_APP_URL
- PM_APP_PORT
- PM_BROADCASTER_PORT
- PM_DB_HOST
- PM_DB_PORT
- PM_DB_NAME
- PM_DB_USERNAME
- PM_DB_PASSWORD
- PM_REDIS_HOST
volumes:
- ${PM_DOCKER_SOCK}:/var/run/docker.sock
- storage:/code/pm4/storage
links:
- redis
- mysql
- mysql
depends_on:
- mysql
- redis
- redis
redis:
image: redis
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: processmaker
MYSQL_USER: pm
MYSQL_PASSWORD: pass
volumes:
- database:/var/lib/mysql
volumes:
database:
storage:
storage: