Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

- Operating System: GNU/Linux or Windows 10.
- Python >= 3.5 (with setuptools)
- Docker >= 18
- Docker compose >= 1.17
- Docker >= 20.10.13
- Docker compose >= 2.0
- RAM memory: At least 4Gb for instance, preferrably 8Gb.

On Ubuntu 22.04:
Expand Down Expand Up @@ -69,6 +69,8 @@ Create a dhis2-data image from a .sql.gz SQL file and the apps and documents (or
$ d2-docker create data docker.eyeseetea.com/eyeseetea/dhis2-data:2.37.9-sierra --sql=sierra-db.sql.gz [--apps-dir=path/to/apps] [--documents-dir=path/to/document] [--datavalues-dir=path/to/dataValue]
```

There are demo database files at [databases.dhis2.org](https://databases.dhis2.org/) that may be used for testing purposses. The database downloaded should correspond to the core version created; if there is no database file for the created core version, a prior version of the database should work.

### Start a DHIS2 instance

Start a new container from a _dhis2-data_ base image:
Expand All @@ -92,6 +94,9 @@ Some notes:
- 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"`)
- Use option `--postgis-version=13-3.1-alpine` to specify the PostGIS version to use. By default, 10-2.5-alpine is used.
- Use option `--debug-port=PORT` to specify the debug port of the Tomcat process.
- Use option `--glowroot-port=PORT` to specify the APM glowroot port of the Tomcat process.
- Use option `--glowroot` to use the latest version of glowroot in the Tomcat process.
- Use option `--glowroot-zip=FILE` to specify the zip file with a version of glowroot to run in the Tomcat process.

#### Custom DHIS2 dhis.conf

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setuptools.setup(
name="d2_docker",
version="1.15.0.b2",
version="1.16.0",
description="Dockers for DHIS2 instances",
long_description=open("README.md", encoding="utf-8").read(),
keywords=["python"],
Expand Down
6 changes: 6 additions & 0 deletions src/d2_docker/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def setup(parser):
parser.add_argument("--postgis-version", type=str, help="Set PostGIS database version")
parser.add_argument("--enable-postgres-queries-logging", action="store_true",
help="Enable Postgres queries logging")
parser.add_argument("--glowroot", action="store_true", help="Enables glowroot in tomcat in latest version")
parser.add_argument("--glowroot-zip", metavar="FILE", help="ZIP file with glowroot binaries")
parser.add_argument("--glowroot-port", metavar="PORT", help="Set glowroot port")


def run(args):
Expand Down Expand Up @@ -113,6 +116,9 @@ def start(args):
java_opts=args.java_opts,
postgis_version=args.postgis_version,
enable_postgres_queries_logging=args.enable_postgres_queries_logging,
glowroot=args.glowroot,
glowroot_zip=args.glowroot_zip,
glowroot_port=args.glowroot_port,
)

if args.detach:
Expand Down
15 changes: 15 additions & 0 deletions src/d2_docker/config/dhis2-core-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ WARFILE=/usr/local/tomcat/webapps/ROOT.war
TOMCATDIR=/usr/local/tomcat
DHIS2HOME=/DHIS2_home
DATA_DIR=/data
GLOWROOT_ZIP="/opt/glowroot.zip"
GLOWROOT_DIR="/opt/glowroot"


debug() {
echo "[dhis2-core-entrypoint] $*" >&2
Expand Down Expand Up @@ -49,6 +52,18 @@ if [ "$(id -u)" = "0" ]; then
rm -v $WARFILE # just to save space
fi

if [ -f $GLOWROOT_ZIP ] && [ ! -d $GLOWROOT_DIR ] ; then
unzip -q $GLOWROOT_ZIP -d /opt/ || [ $? -le 1 ]
if [ -d $GLOWROOT_DIR ] ; then
echo '{ "web": { "bindAddress": "0.0.0.0", "port": "4000" }}' > $GLOWROOT_DIR/admin.json
chown -R tomcat:tomcat $GLOWROOT_DIR
chmod -R u=rwX,g=rX,o-rwx $GLOWROOT_DIR
echo 'export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/glowroot/glowroot.jar"' > /usr/local/tomcat/bin/setenv.sh
chmod ugo+x /usr/local/tomcat/bin/setenv.sh
chown tomcat:tomcat /usr/local/tomcat/bin/setenv.sh
fi
fi

wait_for_data_container_to_finish_copy

mkdir -p $DATA_DIR/apps
Expand Down
2 changes: 2 additions & 0 deletions src/d2_docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
- "com.eyeseetea.image-name=${DHIS2_DATA_IMAGE}"
volumes:
- home:/DHIS2_home
- ${GLOWROOT_ZIP}:/opt/glowroot.zip
- ${DHIS_CONF}:/config/override/dhis2/dhis.conf
- ${ROOT_PATH}/config:/config
- data:/data
Expand All @@ -27,6 +28,7 @@ services:
- "data"
ports:
- "${DHIS2_CORE_DEBUG_PORT}"
- "${GLOWROOT_PORT}"
db:
image: "postgis/postgis:${POSTGIS_VERSION:-14-3.2-alpine}"
shm_size: 1gb
Expand Down
45 changes: 42 additions & 3 deletions src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import time
import yaml
import urllib.request
import json
import zipfile
from setuptools._distutils import dir_util
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -39,6 +41,16 @@ def get_dhis2_war_url(version):
)
return releases_base_url + "/" + path

def get_latest_glowroot_url():
glowroot_releases_url = "https://api.github.com/repos/glowroot/glowroot/releases/latest"
glowroot_download_url = "https://github.com/glowroot/glowroot/releases/download"
with urllib.request.urlopen(glowroot_releases_url) as response:
data = response.read().decode()
release_info = json.loads(data)

tag_name = release_info["tag_name"]
return "{}/{}/glowroot-{}-dist.zip".format(glowroot_download_url, tag_name, tag_name.lstrip("v"))


def docker_build(directory, tag):
return run(["docker", "build", "--platform", "linux/amd64", "--tag", tag, directory])
Expand Down Expand Up @@ -261,6 +273,9 @@ def run_docker_compose(
tomcat_server=None,
postgis_version=None,
enable_postgres_queries_logging=False,
glowroot=None,
glowroot_zip=None,
glowroot_port=None,
**kwargs,
):
"""
Expand All @@ -270,11 +285,30 @@ def run_docker_compose(

The DHIS2_CORE_IMAGE is inferred from the data repo, if not specified.
"""

final_image_name = data_image or get_running_image_name()
project_name = get_project_name(final_image_name)
core_image_name = core_image or get_core_image_name(data_image)
post_sql_dir_abs = get_absdir_for_docker_volume(post_sql_dir)
scripts_dir_abs = get_absdir_for_docker_volume(scripts_dir)
glowroot_path=None

if args[0] == "up":
glowroot_file = tempfile.NamedTemporaryFile(delete=False, prefix="glowroot_", suffix=".zip", dir="/tmp")
glowroot_path = glowroot_file.name

atexit.register(lambda: os.remove(glowroot_path) if os.path.exists(glowroot_path) else None)
if glowroot_zip:
logger.debug("Copy zip file: {} -> {}".format(glowroot_zip, glowroot_path))
shutil.copy(glowroot_zip, glowroot_path)
elif glowroot:
glowroot_url = get_latest_glowroot_url()
logger.info("Download file: {}".format(glowroot_url))
urllib.request.urlretrieve(glowroot_url, glowroot_path)
else:
# empty zipfile
with zipfile.ZipFile(glowroot_path, mode="w") as zf:
pass

env_pairs = [
("DHIS2_DATA_IMAGE", final_image_name),
Expand All @@ -296,13 +330,18 @@ def run_docker_compose(
# Add ROOT_PATH from environment (required when run inside a docker)
("ROOT_PATH", ROOT_PATH),
("PSQL_ENABLE_QUERY_LOGS", "") if not enable_postgres_queries_logging else None,
("GLOWROOT_PORT", "{}:4000".format(glowroot_port) if glowroot_port else "4000:4000") if (glowroot or glowroot_zip) else ("GLOWROOT_PORT", None),
("GLOWROOT_ZIP", get_absfile_for_docker_volume(glowroot_path)),
]
env = dict((k, v) for (k, v) in [pair for pair in env_pairs if pair] if v is not None)

def process_yaml(data):
if "DHIS2_CORE_DEBUG_PORT" not in env:
core = data["services"]["core"]
core["ports"] = [port for port in core["ports"] if "DHIS2_CORE_DEBUG_PORT" not in port]
# Removes ports for "core" service in docker-compose if the environmental variables are not established
core = data["services"]["core"]
env_ports = ["DHIS2_CORE_DEBUG_PORT", "GLOWROOT_PORT"]
for env_port in env_ports:
if env_port not in env:
core["ports"] = [port for port in core["ports"] if env_port not in port]

return data

Expand Down