Skip to content
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
22 changes: 2 additions & 20 deletions src/d2_docker/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,8 @@ def create_core(args):

def get_core_build_dir(args):
base_dir = utils.get_docker_directory("core", args)
major_version = get_major_version(args.version or args.war)
utils.logger.info("DHIS2 major version: {}".format(major_version or "-"))

if not major_version:
raise utils.D2DockerError("Cannot get version from --version or --war")
else:
if major_version >= 42:
return os.path.join(base_dir, "java-17-tomcat-10")
elif major_version >= 41:
return os.path.join(base_dir, "java-17")
else:
return os.path.join(base_dir, "java-11")


def get_major_version(s):
"""Return major DHIS2 version. Ex: "2.38.4" -> "38". "40.1.2" -> 40."""
match = re.search(r"(\d+\.\d+)", s)
if not match: return None
parts = [int(s) for s in match.groups()[0].split(".")]
return parts[1] if parts[0] == 2 else parts[0]
major_version = utils.get_major_version(args.version or args.war)
return utils.get_core_java_dir(base_dir, major_version)


def create_data(args):
Expand Down
2 changes: 1 addition & 1 deletion src/d2_docker/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def upgrade_to_version(
)
war_exists = dhis_war_path and os.path.exists(dhis_war_path)
create_core_kwargs = dict(war=dhis_war_path) if war_exists else dict(version=version)
core_docker_dir = utils.get_docker_directory("core")
core_docker_dir = utils.get_core_java_dir(utils.get_docker_directory("core"), utils.get_major_version(version))
utils.create_core(
docker_dir=core_docker_dir,
image=core_image,
Expand Down
26 changes: 25 additions & 1 deletion src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ def copytree(source, dest):
dir_util.copy_tree(source, dest)


def get_core_java_dir(base_dir, major_version):
logger.info("DHIS2 major version: {}".format(major_version or "-"))

if not major_version:
raise D2DockerError("Cannot get version from --version or --war")
else:
if major_version >= 42:
return os.path.join(base_dir, "java-17-tomcat-10")
elif major_version >= 41:
return os.path.join(base_dir, "java-17")
else:
return os.path.join(base_dir, "java-11")


def get_major_version(s):
"""Return major DHIS2 version. Ex: "2.38.4" -> "38". "40.1.2" -> 40."""
match = re.search(r"(\d+\.\d+)", s)
if not match: return None
parts = [int(s) for s in match.groups()[0].split(".")]
return parts[1] if parts[0] == 2 else parts[0]


def run(
command_parts,
raise_on_error=True,
Expand Down Expand Up @@ -606,6 +628,9 @@ def wait_for_server(port):
url = "http://localhost:{}".format(port)

while True:
# This functions is called right after a "docker up", which takes a little to be able to start the nginx (and way longer for the tomcat to be ready),
# so to avoid calling before nginx can accept connections (and raising an exception) just move the sleep to be the first step
time.sleep(5)
try:
logger.debug("wait_for_server:url={}".format(url))
urllib.request.urlopen(url) # nosec
Expand All @@ -619,7 +644,6 @@ def wait_for_server(port):
except urllib.request.URLError as exc:
logger.debug("wait_for_server:url-error: {}".format(exc.reason))

time.sleep(5)


def create_core(
Expand Down
Loading