Skip to content

Commit

Permalink
Merge pull request #96 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ifoche committed Oct 5, 2022
2 parents 9db5c78 + b3bd0c8 commit 1168138
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ $ d2-docker create core eyeseetea/dhis2-core:2.30 --war=dhis.war --dhis2-home=/t

### Create a base DHIS2 data image

Create a dhis2-data image from a .sql.gz SQL file and the apps and documents directory to include:
Create a dhis2-data image from a .sql.gz SQL file and the apps and documents (or datavalue fileresources) directory to include:

```
$ d2-docker create data eyeseetea/dhis2-data:2.30-sierra --sql=sierra-db.sql.gz [--apps-dir=path/to/apps] [--documents-dir=path/to/document]
$ d2-docker create data eyeseetea/dhis2-data:2.30-sierra --sql=sierra-db.sql.gz [--apps-dir=path/to/apps] [--documents-dir=path/to/document] [--datavalues-dir=path/to/dataValue]
```

### Start a DHIS2 instance
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.8.0",
version="1.9.0",
description="Dockers for DHIS2 instances",
long_description=open("README.md", encoding="utf-8").read(),
keywords=["python"],
Expand Down
7 changes: 7 additions & 0 deletions src/d2_docker/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setup(parser):
data_parser.add_argument("--sql", help="Supported sql / sql.gz / dump formats")
data_parser.add_argument("--apps-dir", help="Directory containing Dhis2 apps")
data_parser.add_argument("--documents-dir", help="Directory containing Dhis2 documents")
data_parser.add_argument("--datavalues-dir", help="Directory containing Dhis2 datavalues(file resources)")


def run(args):
Expand Down Expand Up @@ -60,6 +61,12 @@ def create_data(args):
"Copy documents: {} -> {}".format(args.documents_dir, dest_documents_dir)
)
utils.copytree(args.documents_dir, dest_documents_dir)
if args.datavalues_dir:
dest_datavalues_dir = os.path.join(build_dir, "dataValue")
utils.logger.debug(
"Copy datavalues: {} -> {}".format(args.datavalues_dir, dest_datavalues_dir)
)
utils.copytree(args.datavalues_dir, dest_datavalues_dir)
if args.sql:
utils.logger.debug("Copy DB file: {} -> {}".format(args.sql, db_path))
shutil.copy(args.sql, db_path)
Expand Down
5 changes: 3 additions & 2 deletions src/d2_docker/config/dhis2-core-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ if [ "$(id -u)" = "0" ]; then
rm -v $WARFILE # just to save space
fi

chown -R tomcat:tomcat $TOMCATDIR $DATA_DIR $DHIS2HOME
chmod -R u=rwX,g=rX,o-rwx $TOMCATDIR $DATA_DIR $DHIS2HOME
mkdir -p $DATA_DIR/apps
chown -R tomcat:tomcat $TOMCATDIR $DATA_DIR/apps $DHIS2HOME
chmod -R u=rwX,g=rX,o-rwx $TOMCATDIR $DATA_DIR/apps $DHIS2HOME

# Launch the given command as tomcat, in two ways for backwards compatibility:
if [ "$(grep '^ID=' /etc/os-release)" = "ID=alpine" ]; then
Expand Down
11 changes: 11 additions & 0 deletions src/d2_docker/config/dhis2-core-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ root_db_path="/data/db"
post_db_path="/data/db/post"
source_apps_path="/data/apps"
source_documents_path="/data/document"
source_datavalues_path="/data/dataValue"
files_path="/DHIS2_home/files/"
tomcat_conf_dir="/usr/local/tomcat/conf"

Expand Down Expand Up @@ -87,6 +88,15 @@ copy_documents() {
fi
}

copy_datavalues() {
debug "Copy Dhis2 dataValues: $source_datavalues_path -> $files_path"
mkdir -p "$files_path/dataValue"
if test -e "$source_datavalues_path"; then
cp -Rv "$source_datavalues_path" "$files_path"
fi
}


copy_non_empty_files() {
local from=$1 to=$2
find "$from" -maxdepth 1 -type f -size +0 -exec cp -v {} "$to" \;
Expand Down Expand Up @@ -138,6 +148,7 @@ run() {
setup_tomcat
copy_apps
copy_documents
copy_datavalues

if is_init_done; then
debug "Container: already configured. Skip DB load"
Expand Down
5 changes: 3 additions & 2 deletions src/d2_docker/images/dhis2-core/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ if [ "$(id -u)" = "0" ]; then
rm -v $WARFILE # just to save space
fi

chown -R tomcat:tomcat $TOMCATDIR $DATA_DIR $DHIS2HOME
chmod -R u=rwX,g=rX,o-rwx $TOMCATDIR $DATA_DIR $DHIS2HOME
mkdir -p $DATA_DIR/apps
chown -R tomcat:tomcat $TOMCATDIR $DATA_DIR/apps $DHIS2HOME
chmod -R u=rwX,g=rX,o-rwx $TOMCATDIR $DATA_DIR/apps $DHIS2HOME

# Launch the given command as tomcat, in two ways for backwards compatibility:
if [ "$(grep '^ID=' /etc/os-release)" = "ID=alpine" ]; then
Expand Down
1 change: 1 addition & 0 deletions src/d2_docker/images/dhis2-data/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ COPY run.sh /usr/local/bin/

COPY apps/ /data/apps
COPY document/ /data/document
COPY dataValue/ /data/dataValue

CMD ["sh", "/usr/local/bin/run.sh"]
Empty file.
13 changes: 10 additions & 3 deletions src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ def get_image_status(image_name):
if len(parts) != 3:
continue
image_name_part, container_name, ports = parts
indexed_service = container_name.split("_", 2)[-2:]
if image_name_part == final_image_name and indexed_service:
service = indexed_service[0]
# Depending on the docker version, the container name may be stringfromimage_service-1 OR
# stringfromimage_service_1. Split by all posible character separators.
parts = re.split(r"[-_]", container_name)
service = parts[-2] if len(parts) >= 2 else None

if image_name_part == final_image_name and service:
containers[service] = container_name
if service == "gateway":
port = get_port_from_docker_ports(ports)
Expand Down Expand Up @@ -379,6 +382,7 @@ def export_data_from_image(source_image, dest_path):
with possible_errors():
run(["docker", "cp", container_id + ":" + "/data/apps", dest_path])
run(["docker", "cp", container_id + ":" + "/data/document", dest_path])
run(["docker", "cp", container_id + ":" + "/data/dataValue", dest_path])
finally:
run(["docker", "rm", "-v", container_id])

Expand All @@ -394,6 +398,9 @@ def export_data_from_running_containers(image_name, containers, destination):
documents_source = "{}:/DHIS2_home/files/document/".format(containers["core"])
run(["docker", "cp", documents_source, destination])

datavalues_source = "{}:/DHIS2_home/files/dataValue/".format(containers["core"])
run(["docker", "cp", datavalues_source, destination])

db_path = os.path.join(destination, "db", "db.sql.gz")
export_database(image_name, db_path)

Expand Down

0 comments on commit 1168138

Please sign in to comment.