Skip to content

Commit

Permalink
Merge pull request #68 from EyeSeeTea/feature/override-dhis-conf-kt7ntm
Browse files Browse the repository at this point in the history
  • Loading branch information
SferaDev authored Jun 7, 2021
2 parents fc92d84 + ff50fa8 commit e2d4250
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ Some notes:
- Use option `--run-scripts=DIRECTORY` to run shell scripts (.sh) from a directory within the `dhis2-core` container. By default, a script is run **after** postgres starts (`host=db`, `port=5432`) but **before** Tomcat starts; if its filename starts with prefix "post", it will be run **after** Tomcat is available. `curl` and typical shell tools are available on that Alpine Linux environment. Note that the Dhis2 endpoint is always `http://localhost:8080/${deployPath}`, regardless of the public port that the instance is exposed to.
- Use option `--java-opts="JAVA_OPTS"` to override the default JAVA_OPTS for the Tomcat process. That's tipically used to set the maximum/initial Heap Memory size (for example: `--java-opts="-Xmx3500m -Xms2500m"`)

#### Custom DHIS2 dhis.conf

Copy the default [dhis.conf](https://github.com/EyeSeeTea/d2-docker/blob/master/src/d2_docker/config/DHIS2_home/dhis.conf) and use it as a template to create your own configuration. Then pass it to the `start` command:

```
$ d2-docker start --dhis-conf=dhis.conf ...
```

#### Custom Tomcat server.xml

Copy the default [server.xml](https://github.com/EyeSeeTea/d2-docker/blob/master/src/d2_docker/config/server.xml) and use it as a template to create your own configuration. Then pass it to the `start` command:
Expand Down
6 changes: 5 additions & 1 deletion src/d2_docker/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

def setup(parser):
d2_docker_path = os.path.abspath(d2_docker.__path__[0])
server_xml_path = os.path.join(d2_docker_path, "config", "server.xml")
server_xml_path = utils.get_config_file("server.xml")
server_xml_help = "Use a custom Tomcat server.xml file. Template: {0}".format(server_xml_path)
dhis_conf_path = utils.get_config_file("DHIS2_home/dhis.conf")
dhis_conf_help = "Use a custom dhis.conf file. Template: {0}".format(dhis_conf_path)

parser.add_argument(
"image_or_file", metavar="IMAGE_OR_EXPORT_FILE", help="Docker image or exported file"
Expand All @@ -24,6 +26,7 @@ def setup(parser):
"-k", "--keep-containers", action="store_true", help="Keep existing containers"
)
parser.add_argument("--tomcat-server-xml", metavar="FILE", help=server_xml_help)
parser.add_argument("--dhis-conf", metavar="FILE", help=dhis_conf_help)
parser.add_argument("--run-sql", metavar="DIRECTORY", help="Run .sql[.gz] files in directory")
parser.add_argument(
"--run-scripts",
Expand Down Expand Up @@ -96,6 +99,7 @@ def start(args, image_name):
deploy_path=deploy_path,
dhis2_auth=args.auth,
tomcat_server=args.tomcat_server_xml,
dhis_conf=args.dhis_conf,
java_opts=args.java_opts,
)

Expand Down
1 change: 1 addition & 0 deletions src/d2_docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
- "com.eyeseetea.image-name=${DHIS2_DATA_IMAGE}"
volumes:
- home:/DHIS2_home
- ${DHIS_CONF}:/config/DHIS2_home/dhis.conf
- ./config:/config
- data:/data
- "${TOMCAT_SERVER}:/config/override/tomcat/server.xml"
Expand Down
23 changes: 20 additions & 3 deletions src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from distutils import dir_util
from pathlib import Path

import d2_docker
from .image_name import ImageName

PROJECT_NAME_PREFIX = "d2-docker"
Expand Down Expand Up @@ -210,6 +211,7 @@ def run_docker_compose(
post_sql_dir=None,
scripts_dir=None,
deploy_path=None,
dhis_conf=None,
java_opts=None,
dhis2_auth=None,
tomcat_server=None,
Expand Down Expand Up @@ -239,14 +241,19 @@ def run_docker_compose(
("DEPLOY_PATH", deploy_path or ""),
("JAVA_OPTS", java_opts or ""),
("DHIS2_AUTH", dhis2_auth or ""),
("TOMCAT_SERVER", get_abs_file_for_docker_volume(tomcat_server)),
("TOMCAT_SERVER", get_absfile_for_docker_volume(tomcat_server)),
("DHIS_CONF", get_config_path("DHIS2_home/dhis.conf", dhis_conf)),
]
env = dict((k, v) for (k, v) in [pair for pair in env_pairs if pair] if v is not None)

yaml_path = os.path.join(os.path.dirname(__file__), "docker-compose.yml")
return run(["docker-compose", "-f", yaml_path, "-p", project_name, *args], env=env, **kwargs)


def get_config_path(default_filename, path):
return os.path.abspath(path) if path else get_config_file(default_filename)


def get_absdir_for_docker_volume(directory):
"""Return absolute path for given directory, with fallback to empty directory."""
if not directory:
Expand All @@ -258,7 +265,7 @@ def get_absdir_for_docker_volume(directory):
return os.path.abspath(directory)


def get_abs_file_for_docker_volume(file_path):
def get_absfile_for_docker_volume(file_path):
"""Return absolute path for given file, with fallback to empty file."""
if not file_path:
return os.path.join(os.path.dirname(__file__), ".empty", "placeholder")
Expand Down Expand Up @@ -469,7 +476,12 @@ def wait_for_server(port):


def create_core(
*, docker_dir, image, version=None, war=None, dhis2_home_paths=None,
*,
docker_dir,
image,
version=None,
war=None,
dhis2_home_paths=None,
):
logger.info("Create core image: {}".format(image))

Expand All @@ -495,4 +507,9 @@ def create_core(
run(["docker", "build", build_dir, "--tag", image])


def get_config_file(filename):
d2_docker_path = os.path.abspath(d2_docker.__path__[0])
return os.path.join(d2_docker_path, "config", filename)


logger = get_logger()

0 comments on commit e2d4250

Please sign in to comment.