Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into efh
Browse files Browse the repository at this point in the history
  • Loading branch information
tokland committed Oct 26, 2022
2 parents 783f535 + 691033d commit bfb99c2
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,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.7.0",
version="1.10.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
10 changes: 10 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,14 @@ 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 +147,7 @@ run() {
setup_tomcat
copy_apps
copy_documents
copy_datavalues

if is_init_done; then
debug "Container: already configured. Skip DB load"
Expand Down
7 changes: 7 additions & 0 deletions src/d2_docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
- "${TOMCAT_SERVER}:/config/override/tomcat/server.xml"
- "${SCRIPTS_DIR}:/data/scripts"
- "${POST_SQL_DIR}:/data/db/post"
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
environment:
CATALINA_OPTS: "-Dcontext.path=${DEPLOY_PATH}"
JAVA_OPTS: "-Xmx7500m -Xms4000m ${JAVA_OPTS}"
Expand All @@ -25,10 +27,13 @@ services:
- "db"
db:
image: "postgis/postgis:${POSTGIS_VERSION:-14-3.2-alpine}"
shm_size: 1gb
labels:
- "com.eyeseetea.image-name=${DHIS2_DATA_IMAGE}"
volumes:
- pgdata:/var/lib/postgresql/data
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
environment:
POSTGRES_DB: dhis2
POSTGRES_USER: dhis
Expand All @@ -48,6 +53,8 @@ services:
- ${ROOT_PATH}/config/nginx.conf:/etc/nginx/nginx.conf:ro
- ${ROOT_PATH}/config/50x.html:/usr/share/nginx/html/50x.html:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
restart: unless-stopped
depends_on:
- "core"
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.
7 changes: 6 additions & 1 deletion src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def get_image_status(image_name):
image_name_part, container_name, ports = parts
# Depending on the docker version, the container name may be stringfromimage_service-1 OR
# stringfromimage_service_1. Split by all posible character separators.
service = re.split(r"[-_]", container_name)[-2]
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
Expand Down Expand Up @@ -384,6 +385,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 @@ -399,6 +401,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 bfb99c2

Please sign in to comment.