Skip to content

Commit

Permalink
adempiere-docker#12 Restructure the deployment of dockers containers #12
Browse files Browse the repository at this point in the history
  • Loading branch information
e-Evolution committed Sep 7, 2017
1 parent 2202953 commit 6fa13ad
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 127 deletions.
20 changes: 9 additions & 11 deletions .env
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# Copyright (C) 2010-2017, OpenUp S.A. , http://www.openup.com.uy
# Copyright (C) 2003-2017, e-Evolution Consultants S.A. , http://www.e-evolution.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Email: [email protected], http://openupsolutions.com , http://github.com/rcapecce
# Email: [email protected], http://www.e-evolution.com , http://github.com/e-Evolution
#

ADEMPIERE_VERSION=390LTS
ADEMPIERE_TENANT=tenant1
ADEMPIERE_DB_PORT=55432
COMPOSE_PROJECT_NAME=eevolution
ADEMPIERE_WEB_PORT=8277
ADEMPIERE_SSL_PORT=4445
ADEMPIERE_DB_SERVER=10.10.1.122
ADEMPIERE_APPS_SERVER=
ADEMPIERE_DB_USER=usertenant1
ADEMPIERE_SSL_PORT=4444
ADEMPIERE_DB_PORT=55432
ADEMPIERE_VERSION=3.9.0
ADEMPIERE_DB_PASSWORD=adempiere
ADEMPIERE_DB_ADMIN_PASSWORD=postgres

# ATENTION If is "Y" it will be replace de actual defined database with a empty ADempiere seed
ADEMPIERE_DB_INIT=Y
137 changes: 108 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,77 +76,156 @@ The adempiere-docker project follows the structure specified below

```
└─ adempiere-docker
├─ docker-compose.yml
├─ .env
├─ database.volume.yml
├─ database.yml
├─ adempiere.yml
├─ adempiere-last
├─ client1
├─ tenant1
| ├─ Adempiere_390LTS.tar.gz
| ├─ lib
| └─ packages
└─ client2
└─ tenant2
| ├─ Adempiere_390LTS.tar.gz
| ├─ lib
| └─ packages
...
└─ clientN
└─ tenantN
...
```
#### .env

#### client1
This file contains the setting variables to Tenant deployment

```
COMPOSE_PROJECT_NAME=eevolution
ADEMPIERE_WEB_PORT=8277
ADEMPIERE_SSL_PORT=4444
ADEMPIERE_DB_PORT=55432
ADEMPIERE_VERSION=3.9.0
ADEMPIERE_DB_PASSWORD=adempiere
ADEMPIERE_DB_ADMIN_PASSWORD=postgres
# ATENTION If is "Y" it will be replace de actual defined database with a empty ADempiere seed
ADEMPIERE_DB_INIT=Y
```

#### tenant1 dierectory

This directory contains the files needed to deploy and start a particular ADempiere instance of a client.
Here we will find:
* The Adempiere tar.gz installer.
* lib: The files to copy to the lib directory on ADempiere (this directory will contain the customization and zkcustomization of ADempiere.
* packages: The files to copy to the packages directory on ADempiere (this directory will contain the localization of an ADempiere).

### docker-compose.yml

### database.volume.yml

this file will contain the an external database volume

```
version: '3'
services:
database:
volumes:
- database:/var/lib/postgresql/data/
volumes:
database:
driver: local
```

### database.yml

this file will contain the PostgreSQL deployment

```
version: '3'
services:
database:
image: postgres:9.6
restart: always
ports:
- "${ADEMPIERE_DB_PORT}:5432"
networks:
- custom
environment:
- POSTGRES_USER:postgres
- POSTGRES_PASSWORD:postgres
- PGDATA:/var/lib/postgresql/data/pgdata
- POSTGRES_INITDB_ARGS:''
- POSTGRES_INITDB_XLOGDIR:''
networks:
custom:
external : true
```



### adempiere.yml

This file will contain the definition of our ADempiere clients.
For a client we will need to complete the next parametrization.

```
adempiere-client1: # Name of the ADempiere client for docker
depends_on:
- db
image: adempiere-client1 # Name of the ADempiere client image
container_name: adempierec-client1 # Name of the ADempiere client container
version: '3'
services:
adempiere-tenant:
networks:
- custom
external_links:
- database:database
image: "${COMPOSE_PROJECT_NAME}" # Name of the instance for docker create based on project name
container_name: "${COMPOSE_PROJECT_NAME}" # Name of the ADempiere client container
ports:
- <<port>>:8888 # Port where the web client will be exposed
- ${ADEMPIERE_WEB_PORT}:8888 # http port where the web client will be exposed
- ${ADEMPIERE_SSL_PORT}:444 # https port where the web client will be exposed
environment:
ADEMPIERE_DB_INIT: N # ATENTION If is "Y" it will be replace de actual defined database with a empty ADempiere Seed
ADEMPIERE_DB_INIT: ${ADEMPIERE_DB_INIT} # ATENTION If is "Y" it will be replace de actual defined database with a empty ADempiere seed
build:
context: .
dockerfile: ./adempiere-last/Dockerfile
args:
ADEMPIERE_REL: 390LTS
ADEMPIERE_SRC_DIR: ./client1 # Directory that contain the ADempiere installer, customization and localization
ADEMPIERE_DB_HOST: <<ip adress>> # Address of the database host
ADEMPIERE_DB_PORT: <<port>> # Port of the database host
ADEMPIERE_DB_NAME: <<database name>>
ADEMPIERE_DB_USER: <<database user>>
ADEMPIERE_DB_PASSWORD: <<password database user>>
ADEMPIERE_DB_ADMIN_PASSWORD: <<admin password>>
ADEMPIERE_BINARY : ${ADEMPIERE_BINARY}
ADEMPIERE_SRC_DIR: "./${COMPOSE_PROJECT_NAME}" # Directory that contain the ADempiere installer, customization and localization
ADEMPIERE_DB_HOST: "database"
ADEMPIERE_DB_PORT: 5432
ADEMPIERE_DB_NAME: "${COMPOSE_PROJECT_NAME}"
ADEMPIERE_DB_USER: "${COMPOSE_PROJECT_NAME}"
ADEMPIERE_DB_PASSWORD: ${ADEMPIERE_DB_PASSWORD}
ADEMPIERE_DB_ADMIN_PASSWORD: ${ADEMPIERE_DB_ADMIN_PASSWORD}
networks:
custom:
external: true
```

### Postgres Container
If you don't have an external database server, You can use the postgres server container defined in this composer. As you will not have a database defined in the container, you can first start the database container to mount it, or you can pass the ADEMPIERE_DB_INIT argument with "Y" to load an ADempiere seed, then you only need to parametrice your ADempiere instances with this database configuration.

### Usage
If you already have configured the docker-compose.yml, you only need to start the dockers container, to do this in terminal we will run the next line:

Edit and define the parameters of your instance

.env

to do this in terminal we will run the next line:

```
cd <<directory_of_docker-compose.yml>>
docker-compose up -d
./application up -d
```
This command will build the images defined in the docker-compose.yml, create the containers and start them. The "-d" parameter will launch the process in background.


This command will build the images defined in the .env, create the containers and start them. The "-d" parameter will launch the process in background.
To stop the containers you will run the next command.
```
docker-compose stop
./application stop
```
Note that in the above command we use the instruction ```stop``` insted of ```down```, this is because the ```down``` instruction delete the containers to, ```stop``` only shutdown them.

If you have a new client, you only need to add this client definition to the docker-compose.yml and start up only this image and container.
If you have a new tenant, you only need to edit and setting the tenant definition to env. and start up only this image and container.

```
docker-compose up -d client3
./application up -d
```


Expand All @@ -156,4 +235,4 @@ look at the [docker compose documentation](https://docs.docker.com/compose)
### Contribution

Contributions are more than welcome. Please log any issue or new feature request in
adempiere-docker project's repositor
adempiere-docker project's repository
11 changes: 5 additions & 6 deletions adempiere-last/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM openjdk:8-jdk
MAINTAINER [email protected]
MAINTAINER [email protected] , [email protected]


ARG ADEMPIERE_REL
ARG ADEMPIERE_BINARY
ARG ADEMPIERE_SRC_DIR
ARG ADEMPIERE_DB_HOST
ARG ADEMPIERE_DB_PORT
Expand All @@ -12,7 +11,7 @@ ARG ADEMPIERE_DB_PASSWORD
ARG ADEMPIERE_DB_ADMIN_PASSWORD
ARG ADEMPIERE_WEB_PORT

ENV ADEMPIERE_REL $ADEMPIERE_REL
ENV ADEMPIERE_BINARY $ADEMPIERE_BINARY
ENV ADEMPIERE_SRC_DIR $ADEMPIERE_SRC_DIR
ENV ADEMPIERE_DB_HOST $ADEMPIERE_DB_HOST
ENV ADEMPIERE_DB_PORT $ADEMPIERE_DB_PORT
Expand All @@ -25,14 +24,14 @@ ENV ADEMPIERE_WEB_PORT $ADEMPIERE_WEB_PORT
ENV ADEMPIERE_HOME /opt/Adempiere
ENV AD_DB_Init $AD_DB_Init

COPY $ADEMPIERE_SRC_DIR/Adempiere_$ADEMPIERE_REL.tar.gz /tmp
COPY $ADEMPIERE_SRC_DIR/$ADEMPIERE_BINARY /tmp
COPY $ADEMPIERE_SRC_DIR/lib /tmp/lib
COPY $ADEMPIERE_SRC_DIR/packages /tmp/packages
COPY ./adempiere-last/start-adempiere.sh /root
COPY ./adempiere-last/define-ad-ctl.sh /root

RUN cd /tmp && \
tar zxvf /tmp/Adempiere_$ADEMPIERE_REL.tar.gz && \
tar zxvf /tmp/$ADEMPIERE_BINARY && \
mv Adempiere /opt/Adempiere && \
mv lib /opt/Adempiere/lib && \
mv packages /opt/Adempiere/packages && \
Expand Down
45 changes: 45 additions & 0 deletions adempiere.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2010-2017, OpenUp S.A. , http://www.openup.com.uy
# Copyright (C) 2003-2017, e-Evolution Consultants S.A. , http://www.e-evolution.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Email: [email protected], http://openupsolutions.com , http://github.com/rcapecce
# Email: [email protected], http://www.e-evolution.com , http://github.com/e-Evolution
#

version: '3'
services:
adempiere-tenant:
networks:
- custom
external_links:
- database:database
image: "${COMPOSE_PROJECT_NAME}" # Name of the instance for docker create based on project name
container_name: "${COMPOSE_PROJECT_NAME}" # Name of the ADempiere client container
ports:
- ${ADEMPIERE_WEB_PORT}:8888 # http port where the web client will be exposed
- ${ADEMPIERE_SSL_PORT}:444 # https port where the web client will be exposed
environment:
ADEMPIERE_DB_INIT: ${ADEMPIERE_DB_INIT} # ATENTION If is "Y" it will be replace de actual defined database with a empty ADempiere seed
build:
context: .
dockerfile: ./adempiere-last/Dockerfile
args:
ADEMPIERE_BINARY : ${ADEMPIERE_BINARY}
ADEMPIERE_SRC_DIR: "./${COMPOSE_PROJECT_NAME}" # Directory that contain the ADempiere installer, customization and localization
ADEMPIERE_DB_HOST: "database"
ADEMPIERE_DB_PORT: 5432
ADEMPIERE_DB_NAME: "${COMPOSE_PROJECT_NAME}"
ADEMPIERE_DB_USER: "${COMPOSE_PROJECT_NAME}"
ADEMPIERE_DB_PASSWORD: ${ADEMPIERE_DB_PASSWORD}
ADEMPIERE_DB_ADMIN_PASSWORD: ${ADEMPIERE_DB_ADMIN_PASSWORD}
networks:
custom:
external: true
70 changes: 70 additions & 0 deletions application.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (C) 2003-2017, e-Evolution Consultants S.A. , http://www.e-evolution.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Email: [email protected], http://www.e-evolution.com , http://github.com/e-Evolution

#!/usr/bin/env bash
BASE_DIR=$(cd "$(dirname "$0")"; pwd)
# load environment variables
. .env

if [ $(docker network inspect -f '{{.Name}}' custom) != "custom" ];
then
echo "Create custom network"
docker network create -d bridge custom
fi

if [ $(docker inspect -f '{{.State.Running}}' postgres96_database_1) = "true" ];
then
echo "Database container is running"
else
echo "Create Database container"
docker-compose \
-f "$BASE_DIR/database.yml" \
-f "$BASE_DIR/database.volume.yml" \
"$@" \
-p postgres96_database_1
fi

# Define Adempiere path and binary
ADEMPIERE_PATH="./$COMPOSE_PROJECT_NAME"
ADEMPIERE_BINARY=Adempiere_${ADEMPIERE_VERSION//.}"LTS.tar.gz"
export ADEMPIERE_BINARY;
URL="https://github.com/adempiere/adempiere/releases/download/"$ADEMPIERE_VERSION"/"$ADEMPIERE_BINARY

echo "Adempiere Path $ADEMPIERE_PATH"
echo "Adempiere Version $ADEMPIERE_VERSION"
echo "Adempiere Binary $ADEMPIERE_PATH/$ADEMPIERE_BINARY"
echo "Download from $URL"


if [ -d "$ADEMPIERE_PATH" ]
then
if [ -f "$ADEMPIERE_PATH/$ADEMPIERE_BINARY" ]
then
echo "Installed based on $ADEMPIERE_PATH/$ADEMPIERE_BINARY"
else
curl -L $URL > "$ADEMPIERE_PATH/$ADEMPIERE_BINARY"
if [ -f "$ADEMPIERE_PATH/$ADEMPIERE_BINARY" ]
then
echo "Adempiere Binary download successful"
else
"Adempiere Binary not download"
exit
fi
fi
# Execute docker-compose
docker-compose \
-f "$BASE_DIR/adempiere.yml" \
"$@"
else
echo "Project directory not found for : $COMPOSE_PROJECT_NAME "
fi
Loading

0 comments on commit 6fa13ad

Please sign in to comment.