From 96b637a09e6d87d25713136f8677b34ce04bb15b Mon Sep 17 00:00:00 2001 From: Austin McGee <947888+amcgee@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:42:58 +0000 Subject: [PATCH 1/2] feat: add simple example docker-compose --- simple/config/dhis.conf | 7 +++++ simple/config/log4j2.xml | 40 ++++++++++++++++++++++++ simple/config/nginx.conf | 50 ++++++++++++++++++++++++++++++ simple/config/server.xml | 56 +++++++++++++++++++++++++++++++++ simple/docker-compose.yml | 65 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 simple/config/dhis.conf create mode 100644 simple/config/log4j2.xml create mode 100644 simple/config/nginx.conf create mode 100644 simple/config/server.xml create mode 100644 simple/docker-compose.yml diff --git a/simple/config/dhis.conf b/simple/config/dhis.conf new file mode 100644 index 0000000..4f4a4bf --- /dev/null +++ b/simple/config/dhis.conf @@ -0,0 +1,7 @@ +connection.dialect = org.hibernate.dialect.PostgreSQLDialect +connection.driver_class = org.postgresql.Driver +connection.url = jdbc:postgresql://db/dhis +connection.username = dhis +connection.password = dhis + +tracker.import.preheat.cache.enabled=off \ No newline at end of file diff --git a/simple/config/log4j2.xml b/simple/config/log4j2.xml new file mode 100644 index 0000000..e332f21 --- /dev/null +++ b/simple/config/log4j2.xml @@ -0,0 +1,40 @@ + + + + + %-5level %c [%t] %msg%n + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/simple/config/nginx.conf b/simple/config/nginx.conf new file mode 100644 index 0000000..231d5f2 --- /dev/null +++ b/simple/config/nginx.conf @@ -0,0 +1,50 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + upstream web { + server web:8080 max_fails=3 fail_timeout=60s; + } + + gzip on; # Enables compression, incl Web API content-types + gzip_types + "application/json;charset=utf-8" application/json + "application/javascript;charset=utf-8" application/javascript text/javascript + "application/xml;charset=utf-8" application/xml text/xml + "text/css;charset=utf-8" text/css + "text/plain;charset=utf-8" text/plain; + + server { + listen 80; + port_in_redirect off; + + root /data/apps; + + client_max_body_size 25m; + + # Redirect required to prevent 403 error on / access + rewrite ^/$ $scheme://$http_host/dhis-web-dashboard redirect; + + location / { + include mime.types; + try_files $uri $uri/ $uri/index.html @web; + } + + # location /screenshot { + # proxy_set_header Host $http_host; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_pass http://screenshot:9000; + # } + + location @web { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://web; + } + } +} diff --git a/simple/config/server.xml b/simple/config/server.xml new file mode 100644 index 0000000..86e2951 --- /dev/null +++ b/simple/config/server.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/simple/docker-compose.yml b/simple/docker-compose.yml new file mode 100644 index 0000000..485fe81 --- /dev/null +++ b/simple/docker-compose.yml @@ -0,0 +1,65 @@ +version: "3.8" + +services: + web: + image: "${DHIS2_IMAGE:-dhis2/core:2.40.1}" + restart: unless-stopped + volumes: + - files:/opt/dhis2 + - ./config/dhis.conf:/opt/dhis2/dhis.conf:ro + - ./config/log4j2.xml:/opt/dhis2/log4j2.xml:ro + - ./config/server.xml:/usr/local/tomcat/conf/server.xml + environment: + JAVA_OPTS: "-Dcontext.path='${DHIS2_CORE_CONTEXT_PATH:-}' \ + -Dlog4j2.configurationFile=/opt/dhis2/log4j2.xml" + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "wget -q -S -O /dev/null http://127.0.0.1:8080/dhis-web-commons/security/login.action 2>&1| grep -q 'HTTP.*200'"] + start_period: 120s + interval: 10s + timeout: 5s + retries: 5 + security_opt: + - no-new-privileges:true + + db: + image: postgis/postgis + restart: unless-stopped + ports: + - 127.0.0.1:5432:5432 + volumes: + - postgresql:/var/lib/postgresql + environment: + POSTGRES_USER: dhis + POSTGRES_DB: dhis + POSTGRES_PASSWORD: &postgres_password dhis + PGPASSWORD: *postgres_password # needed by psql in healthcheck + healthcheck: + test: ["CMD-SHELL", "psql --no-password --quiet --username $$POSTGRES_USER postgres://127.0.0.1/$$POSTGRES_DB -p 5432 --command \"SELECT 'ok'\" > /dev/null"] + start_period: 120s + interval: 10s + timeout: 3s + retries: 5 + security_opt: + - no-new-privileges:true + + gateway: + image: nginx + restart: always + depends_on: + web: + condition: service_healthy + ports: + - "${DHIS2_PORT:-8080}:80" + volumes: + - ./config/nginx.conf:/etc/nginx/nginx.conf:ro + security_opt: + - no-new-privileges:true + +volumes: + files: + driver: local + postgresql: + driver: local From 9c069d5f7fe58151fcd9e7b8042f3843b91e65ec Mon Sep 17 00:00:00 2001 From: Austin McGee <947888+amcgee@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:30:56 +0100 Subject: [PATCH 2/2] chore: move to examples directory --- examples/simple/config/dhis.conf | 7 ++++ examples/simple/config/log4j2.xml | 40 +++++++++++++++++++ examples/simple/config/nginx.conf | 50 ++++++++++++++++++++++++ examples/simple/config/server.xml | 56 ++++++++++++++++++++++++++ examples/simple/docker-compose.yml | 63 ++++++++++++++++++++++++++++++ 5 files changed, 216 insertions(+) create mode 100644 examples/simple/config/dhis.conf create mode 100644 examples/simple/config/log4j2.xml create mode 100644 examples/simple/config/nginx.conf create mode 100644 examples/simple/config/server.xml create mode 100644 examples/simple/docker-compose.yml diff --git a/examples/simple/config/dhis.conf b/examples/simple/config/dhis.conf new file mode 100644 index 0000000..4f4a4bf --- /dev/null +++ b/examples/simple/config/dhis.conf @@ -0,0 +1,7 @@ +connection.dialect = org.hibernate.dialect.PostgreSQLDialect +connection.driver_class = org.postgresql.Driver +connection.url = jdbc:postgresql://db/dhis +connection.username = dhis +connection.password = dhis + +tracker.import.preheat.cache.enabled=off \ No newline at end of file diff --git a/examples/simple/config/log4j2.xml b/examples/simple/config/log4j2.xml new file mode 100644 index 0000000..e332f21 --- /dev/null +++ b/examples/simple/config/log4j2.xml @@ -0,0 +1,40 @@ + + + + + %-5level %c [%t] %msg%n + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/simple/config/nginx.conf b/examples/simple/config/nginx.conf new file mode 100644 index 0000000..231d5f2 --- /dev/null +++ b/examples/simple/config/nginx.conf @@ -0,0 +1,50 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + upstream web { + server web:8080 max_fails=3 fail_timeout=60s; + } + + gzip on; # Enables compression, incl Web API content-types + gzip_types + "application/json;charset=utf-8" application/json + "application/javascript;charset=utf-8" application/javascript text/javascript + "application/xml;charset=utf-8" application/xml text/xml + "text/css;charset=utf-8" text/css + "text/plain;charset=utf-8" text/plain; + + server { + listen 80; + port_in_redirect off; + + root /data/apps; + + client_max_body_size 25m; + + # Redirect required to prevent 403 error on / access + rewrite ^/$ $scheme://$http_host/dhis-web-dashboard redirect; + + location / { + include mime.types; + try_files $uri $uri/ $uri/index.html @web; + } + + # location /screenshot { + # proxy_set_header Host $http_host; + # proxy_set_header X-Real-IP $remote_addr; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_pass http://screenshot:9000; + # } + + location @web { + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://web; + } + } +} diff --git a/examples/simple/config/server.xml b/examples/simple/config/server.xml new file mode 100644 index 0000000..86e2951 --- /dev/null +++ b/examples/simple/config/server.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/simple/docker-compose.yml b/examples/simple/docker-compose.yml new file mode 100644 index 0000000..424488b --- /dev/null +++ b/examples/simple/docker-compose.yml @@ -0,0 +1,63 @@ +version: "3.8" + +services: + web: + image: "${DHIS2_IMAGE:-dhis2/core:2.40.1}" + restart: unless-stopped + volumes: + - files:/opt/dhis2 + - ./config/dhis.conf:/opt/dhis2/dhis.conf:ro + - ./config/log4j2.xml:/opt/dhis2/log4j2.xml:ro + - ./config/server.xml:/usr/local/tomcat/conf/server.xml + environment: + JAVA_OPTS: "-Dcontext.path='${DHIS2_CORE_CONTEXT_PATH:-}' \ + -Dlog4j2.configurationFile=/opt/dhis2/log4j2.xml" + depends_on: + db: + condition: service_healthy + healthcheck: + test: ["CMD-SHELL", "wget -q -S -O /dev/null http://127.0.0.1:8080/dhis-web-commons/security/login.action 2>&1| grep -q 'HTTP.*200'"] + start_period: 120s + interval: 10s + timeout: 5s + retries: 5 + security_opt: + - no-new-privileges:true + + db: + image: postgis/postgis + restart: unless-stopped + volumes: + - postgresql:/var/lib/postgresql + environment: + POSTGRES_USER: dhis + POSTGRES_DB: dhis + POSTGRES_PASSWORD: &postgres_password dhis + PGPASSWORD: *postgres_password # needed by psql in healthcheck + healthcheck: + test: ["CMD-SHELL", "psql --no-password --quiet --username $$POSTGRES_USER postgres://127.0.0.1/$$POSTGRES_DB -p 5432 --command \"SELECT 'ok'\" > /dev/null"] + start_period: 120s + interval: 10s + timeout: 3s + retries: 5 + security_opt: + - no-new-privileges:true + + gateway: + image: nginx + restart: always + depends_on: + web: + condition: service_healthy + ports: + - "${DHIS2_PORT:-8080}:80" + volumes: + - ./config/nginx.conf:/etc/nginx/nginx.conf:ro + security_opt: + - no-new-privileges:true + +volumes: + files: + driver: local + postgresql: + driver: local