Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set DHIS2_HOME env var to /DHIS2_home for images pre-Jib TECH-1433 #586

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

teleivo
Copy link
Contributor

@teleivo teleivo commented Dec 21, 2022

Docker images for releases starting from 2.39.0, 2.38.2, 2.37.9 do not create directory /DHIS2_home anymore. See dhis2/dhis2-core#11981 Instead /opt/dhis2 is created which is the default location used by DHIS2.

Set DHIS2_HOME to /DHIS2_home for images created before such releases and to /opt/dhis2 otherwise.

The changes make sure that the "effective" docker-compose.yml

for old Docker images (not using Jib) is

environment:
  DHIS2_HOME=/DHIS2_home
volumes:
  - ./config/DHIS2_home/dhis.conf:/DHIS2_home/dhis.conf

for new Docker images (using Jib) is

environment:
  DHIS2_HOME=/opt/dhis2
volumes:
  - ./config/DHIS2_home/dhis.conf:/opt/dhis2/dhis.conf

Mount other files into DHIS2_HOME

If you need to mount additional files. Find the docker-compose.yml in the d2 cache. And add one line. Make sure that the left side corresponds to a path on your host where the file exists! And make sure the right side points to the DHIS2_HOME for the version you deploy.

environment:
  DHIS2_HOME=/opt/dhis2
volumes:
  - ./config/DHIS2_home/dhis.conf:/opt/dhis2/dhis.conf
+  - ./config/DHIS2_home/dhis-google-auth.json:/opt/dhis2/dhis-google-auth.json

Tests

Automated

See unit and "integration" tests of the resulting config in this PR.

Manual

Created DHIS2 instances of the new image using d2. All started and let me log in.

NEW

d2 cluster up test-master --dhis2Version master --channel dev
d2 cluster up test-2.39.0 --dhis2Version 2.39.0
d2 cluster up test-2.38.2.1 --dhis2Version 2.38.2.1
d2 cluster up test-2.37.9 --dhis2Version 2.37.9

OLD
d2 cluster up test-2.38.1.1 --dhis2Version 2.38.1.1
d2 cluster up test-2.37.8.1 --dhis2Version 2.37.8.1
d2 cluster up test-2.36.13.1 --dhis2Version 2.36.13.1

I could stream the logs see dhis2/d2-cluster-docker-compose#26 (comment)

Details on issues with bind-mounting DHIS2_HOME

https://community.dhis2.org/t/d2-cluster-changes-feedback-needed-on-files-added-to-dhis2-home/51126

No matter where DHIS2_HOME is bind-mounted /DHIS2_home or /opt/dhis2 it has the following effect for rootless images:

Ownership of DHIS2_HOME with bind mount will be that of the host uid/guid. This will take write permission from DHIS2 to DHIS2_HOME.

This is why if you execute d2 cluster up 2.39.0.1, you will see

* INFO  2022-12-21T08:16:08,275 Environment variable DHIS2_HOME points to /DHIS2_home (LogOnceLogger.java [main])
* INFO  2022-12-21T08:16:08,276 Directory /DHIS2_home is not writeable (LogOnceLogger.java [main])
* INFO  2022-12-21T08:16:08,277 Home directory set to /opt/dhis2 (LogOnceLogger.java [main])
* INFO  2022-12-21T08:16:08,282 File /opt/dhis2/dhis.conf does not exist (LogOnceLogger.java [main])
21-Dec-2022 08:16:08.283 SEVERE [main] org.apache.catalina.core.ContainerBase.startInternal A child container failed during start

DHIS2_HOME exists in the images before using Jib /DHIS2_home and with using Jib /opt/dhis2. The DHIS2_HOME has the appropriate permission/ownership.

  • What do devs actually want to bind mount into DHIS2_HOME? Asked in various Slack channels and CoP.

@teleivo teleivo changed the title fix: set DHIS2_HOME env var to /DHIS2_home for images pre-Jib fix: set DHIS2_HOME env var to /DHIS2_home for images pre-Jib TECH-1433 Dec 21, 2022
teleivo added a commit to dhis2/d2-cluster-docker-compose that referenced this pull request Dec 21, 2022
Only mount the config, as the DHIS2_HOME directory is already created
using the correct ownership/permissions for DHIS2 to write to it. The
env var DHIS2_HOME is set to the appropriate location based on the DHIS2
version. For more details see dhis2/cli#586
teleivo added a commit to dhis2/d2-cluster-docker-compose that referenced this pull request Dec 21, 2022
The env var DHIS2_HOME is set to the appropriate location based on the
DHIS2 version. For more details see
dhis2/cli#586
@teleivo teleivo force-pushed the TECH-1433 branch 5 times, most recently from 2b8e486 to ba6d998 Compare December 21, 2022 14:34
@teleivo teleivo force-pushed the TECH-1433 branch 3 times, most recently from 685d6e4 to 81f0457 Compare December 22, 2022 06:46
@teleivo teleivo requested a review from radnov December 22, 2022 06:47
Docker images created for releases after 2.39.0, 2.38.2, 2.37.8.2 or
2.37.9 (not yet released) do not create directory /DHIS2_home anymore.
See dhis2/dhis2-core#11981 Instead /opt/dhis2
is created which is the default location used by DHIS2.

Set DHIS2_HOME to /DHIS2_home for images created before such releases
and to /opt/dhis2 otherwise.
@@ -1,4 +1,5 @@
module.exports = {
dhis2Home: '/opt/dhis2',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) As far as I can tell this will never be used because it is always overridden by the "computed" dhis2home (common.js::168), is that correct and if so should this default be removed...?

Copy link
Contributor Author

@teleivo teleivo Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right 👌🏻 Tests pass with or without it. I thought I add it here to be consistent since others like dhis2Version also have a "default" even though for dhis2Version the default is ''.

Keeping this default or removing is both fine for me. Which do you prefer @amcgee @radnov ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that dhis2Version is also in the defaults with an empty value, maybe we can either keep it as /opt/dhis2 (if we assume this is the default home location for images going forward) or also keep it with an empty value. I'm also fine either way. 🤷‍♂️ 😅

so we can simplify our logic that future proofed the next 2.37 release
@teleivo teleivo marked this pull request as ready for review January 10, 2023 08:02
@Philip-Larsen-Donnelly Philip-Larsen-Donnelly merged commit ed68ee2 into master Jan 13, 2023
@dhis2-bot
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants