Skip to content

Commit 2f0ec8e

Browse files
Merge pull request #139 from EyeSeeTea/development
Release 1.15.0
2 parents 29e38c7 + 9ee0d7a commit 2f0ec8e

File tree

15 files changed

+257
-36
lines changed

15 files changed

+257
-36
lines changed

.github/workflows/codeql.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "development", "master" ]
17+
pull_request:
18+
branches: [ "development", "master" ]
19+
20+
jobs:
21+
analyze:
22+
name: Analyze (${{ matrix.language }})
23+
# Runner size impacts CodeQL analysis time. To learn more, please see:
24+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
25+
# - https://gh.io/supported-runners-and-hardware-resources
26+
# - https://gh.io/using-larger-runners (GitHub.com only)
27+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
28+
runs-on: self-hosted
29+
permissions:
30+
# required for all workflows
31+
security-events: write
32+
33+
# required to fetch internal or private CodeQL packs
34+
packages: read
35+
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
include:
40+
- language: python
41+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
42+
# Use `c-cpp` to analyze code written in C, C++ or both
43+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
44+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
45+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
46+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
47+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
48+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
53+
# Initializes the CodeQL tools for scanning.
54+
- name: Initialize CodeQL
55+
uses: github/codeql-action/init@v3
56+
with:
57+
languages: ${{ matrix.language }}
58+
build-mode: ${{ matrix.build-mode }}
59+
# If you wish to specify custom queries, you can do so here or in a config file.
60+
# By default, queries listed here will override any specified in a config file.
61+
# Prefix the list here with "+" to use these queries and those in the config file.
62+
63+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
64+
# queries: security-extended,security-and-quality
65+
66+
- name: Perform CodeQL Analysis
67+
uses: github/codeql-action/analyze@v3
68+
with:
69+
category: "/language:${{matrix.language}}"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
On Ubuntu 22.04:
1010

1111
```
12-
$ sudo apt install docker.io docker-compose python3 python3-setuptools
12+
$ sudo apt install docker.io docker-compose-v2 python3 python3-setuptools
1313
```
1414

1515
On Windows 10:
@@ -87,7 +87,7 @@ Some notes:
8787
- Use option `--deploy-path` to run the container with a deploy path namespace (i.e: `--deploy-path=dhis2` serves `http://localhost:8080/dhis2`)
8888
- Use option `-k`/`--keep-containers` to re-use existing docker containers, so data from the previous run will be kept.
8989
- Use option `-auth` to pass the instance authentication (`USER:PASS`). It will be used to call post-tomcat scripts.
90-
- Use option `--run-sql=DIRECTORY` to run SQL files (.sql, .sql.gz or .dump files) after the DB has been initialized.
90+
- Use option `--run-sql=DIRECTORY` to run SQL files (.sql, .sql.gz or .dump files) after the DB has been initialized. SQL files containing "strict" in their name will cause `d2-docker start` to stop if an error occurs.
9191
- 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.
9292
- 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"`)
9393
- Use option `--postgis-version=13-3.1-alpine` to specify the PostGIS version to use. By default, 10-2.5-alpine is used.

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Flask==2.0.3
1+
Flask==3.1.0
22
python-dotenv
3-
Flask_Cors==3.0.10
4-
Werkzeug==2.3.7
5-
requests==2.31.0
3+
Flask_Cors==6.0.0
4+
requests==2.32.3
65
PyYAML
6+
setuptools

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setuptools.setup(
66
name="d2_docker",
7-
version="1.14.0",
7+
version="1.15.0.b2",
88
description="Dockers for DHIS2 instances",
99
long_description=open("README.md", encoding="utf-8").read(),
1010
keywords=["python"],

src/d2_docker/commands/commit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ def setup(parser):
1010
nargs="?",
1111
help="Destination Docker image (same if empty)",
1212
)
13-
13+
parser.add_argument(
14+
"--folders",
15+
nargs="+",
16+
choices=utils.default_folders,
17+
help="Folders to include in the image",
18+
)
1419

1520
def run(args):
1621
image_name = args.image or utils.get_running_image_name()
1722
docker_dir = utils.get_docker_directory("data", args)
1823
temp_dir = utils.get_temp_base_directory(args)
1924
utils.logger.info("Commit image: {}".format(image_name))
20-
utils.build_image_from_source(docker_dir, image_name, image_name, temp_dir)
25+
utils.build_image_from_source(docker_dir, image_name, image_name, temp_dir, args.folders)

src/d2_docker/commands/create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def get_core_build_dir(args):
5252
if not major_version:
5353
raise utils.D2DockerError("Cannot get version from --version or --war")
5454
else:
55-
if major_version >= 41:
55+
if major_version >= 42:
56+
return os.path.join(base_dir, "java-17-tomcat-10")
57+
elif major_version >= 41:
5658
return os.path.join(base_dir, "java-17")
5759
else:
5860
return os.path.join(base_dir, "java-11")

src/d2_docker/commands/run_sql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
22
from d2_docker import utils
3+
from d2_docker.utils import get_pg_dump_command
34

45
DESCRIPTION = "Run SQL or open interactive session in a d2-docker container"
56
NAME = "run-sql"
@@ -29,7 +30,7 @@ def run(args):
2930
utils.logger.debug("DB container: {}".format(db_container))
3031

3132
if args.dump:
32-
cmd = ["docker", "exec", db_container, "pg_dump", "-U", "dhis", "dhis2"]
33+
cmd = ["docker", "exec", db_container, *get_pg_dump_command(compress=False)]
3334
utils.logger.info("Dump SQL for image {}".format(image_name))
3435
utils.run(cmd, raise_on_error=False)
3536
else:
@@ -54,7 +55,7 @@ def get_stream_db(image):
5455
raise utils.D2DockerError("Container must be running to dump database")
5556

5657
db_container = status["containers"]["db"]
57-
cmd_parts = ["docker", "exec", db_container, "pg_dump", "-U", "dhis", "dhis2", "|", "gzip"]
58+
cmd_parts = ["docker", "exec", db_container, *get_pg_dump_command()]
5859
cmd = subprocess.list2cmdline(cmd_parts)
5960
utils.logger.info("Dump SQL for image: {}".format(cmd))
6061

src/d2_docker/commands/version.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pkg_resources # part of setuptools
1+
from importlib.metadata import distribution
22
import re
33
from d2_docker import utils
44

@@ -11,7 +11,7 @@ def setup(_parser):
1111

1212
def run(_args):
1313
utils.run(["docker", "-v"])
14-
utils.run(["docker-compose", "-v"])
14+
utils.run(["docker", "compose", "version"])
1515
d2_docker = get_d2_docker_version()
1616
if d2_docker:
1717
print("d2-docker version {}".format(d2_docker))
@@ -32,11 +32,11 @@ def get_field(command, field_index):
3232

3333
def get_versions():
3434
docker = get_field(["docker", "-v"], 2)
35-
docker_compose = get_field(["docker-compose", "-v"], 3)
35+
docker_compose = get_field(["docker", "compose", "version"], 3)
3636
d2_docker = get_d2_docker_version()
3737
return dict({"docker": docker, "docker-compose": docker_compose, "d2-docker": d2_docker})
3838

3939

4040
def get_d2_docker_version():
41-
resources = pkg_resources.require("d2-docker")
42-
return resources[0].version if resources else None
41+
dist = distribution("d2-docker")
42+
return dist.version

src/d2_docker/config/dhis2-core-start.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export PGPASSWORD="dhis"
1717

1818
dhis2_url="http://localhost:8080/$DEPLOY_PATH"
1919
dhis2_url_with_auth="http://$DHIS2_AUTH@localhost:8080/$DEPLOY_PATH"
20-
psql_cmd="psql -v ON_ERROR_STOP=0 --quiet -h db -U dhis dhis2"
20+
psql_base_cmd="psql --quiet -h db -U dhis dhis2"
21+
psql_cmd="$psql_base_cmd -v ON_ERROR_STOP=0"
22+
psql_strict_cmd="$psql_base_cmd -v ON_ERROR_STOP=1"
2123
pgrestore_cmd="pg_restore -h db -U dhis -d dhis2"
2224
configdir="/config"
2325
homedir="/dhis2-home-files"
@@ -54,10 +56,26 @@ run_sql_files() {
5456
find "$base_db_path" -type f \( -name '*.sql' \) |
5557
sort | while read -r path; do
5658
echo "Load SQL: $path"
57-
$psql_cmd <"$path" || true
59+
exit_code=0
60+
run_psql_cmd "$path" || exit_code=$?
61+
if [ "$exit_code" -gt 0 ]; then
62+
echo "Exit code: $exit_code"
63+
exit "$exit_code"
64+
fi
5865
done
5966
}
6067

68+
run_psql_cmd() {
69+
local path=$1
70+
if [[ "$path" == *strict* ]]; then
71+
echo "Strict mode: $path"
72+
$psql_strict_cmd < "$path"
73+
else
74+
echo "Normal mode: $path"
75+
$psql_cmd < "$path"
76+
fi
77+
}
78+
6179
run_pre_scripts() {
6280
find "$scripts_dir" -type f -name '*.sh' ! \( -name 'post*' \) | sort | while read -r path; do
6381
debug "Run pre-tomcat script: $path"
@@ -154,7 +172,7 @@ run() {
154172
else
155173
debug "Container: clean. Load DB"
156174
wait_for_postgres
157-
run_sql_files || true
175+
run_sql_files
158176
run_pre_scripts || true
159177
init_done
160178
fi

src/d2_docker/config/server.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
connectionTimeout="20000"
2626
URIEncoding="UTF-8"
2727
relaxedQueryChars='\ { } | [ ]'
28+
maxHttpHeaderSize="32768"
2829
/>
2930

3031
<Connector

0 commit comments

Comments
 (0)