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

pavics compose.sh: overriding DATA_PERSIST_ROOT in env.local do not take effect and warn when a dir in EXTRA_CONF_DIRS does not exist #272

Merged
merged 15 commits into from
Dec 23, 2022

Conversation

tlvu
Copy link
Collaborator

@tlvu tlvu commented Dec 15, 2022

Fixes:

  • Overriding DATA_PERSIST_ROOT in env.local do not take effect for
    JUPYTERHUB_USER_DATA_DIR, MAGPIE_PERSIST_DIR, and GEOSERVER_DATA_DIR.

    These 3 vars will have to be delayed evaluated for override in env.local to
    take effect.

    For a variable to be delayed evaluated, it has to be defined using
    single-quote and be added to the list of DELAYED_EVAL in default.env.

    If those steps are forgotten in env.local, it will still work since
    env.local is the last file to be read. However those steps should not be
    forgotten in any default.env for all components.

    So the impact or burden is on the developpers to write their default.env
    file properly, not on the users that only modify the env.local file.

    All default.env files header have been updated with notice about this new
    delayed evaluation feature.

    Fixes 🐛 [BUG]: Regression handling DATA_PERSIST_ROOT setting #270

Changes:

@crim-jenkins-bot
Copy link
Collaborator

E2E Test Results

DACCS-iac Pipeline Results

Build URL : http://daccs-jenkins.crim.ca:80/job/DACCS-iac-birdhouse/1082/
Result : failure

BIRDHOUSE_DEPLOY_BRANCH : fix-bugs-in-pavics-compose.sh
DACCS_CONFIGS_BRANCH : master
PAVICS_E2E_WORKFLOW_TESTS_BRANCH : master
PAVICS_SDI_BRANCH : master

DESTROY_INFRA_ON_EXIT : true
PAVICS_HOST : https://

PAVICS-e2e-workflow-tests Pipeline Results

Tests URL :

NOTEBOOK TEST RESULTS
    
</code>

@tlvu
Copy link
Collaborator Author

tlvu commented Dec 15, 2022

@fmigneault I changed my mind and go ahead with single-quote and delayed evaluation instead.

The impact on users is actually minimum since forgetting to use single-quote in env.local has no problem. Basically the complexity burden is on the developer only. I've believe I've left enough documentation comments for the developers.

@crim-jenkins-bot
Copy link
Collaborator

E2E Test Results

DACCS-iac Pipeline Results

Build URL : http://daccs-jenkins.crim.ca:80/job/DACCS-iac-birdhouse/1083/
Result : failure

BIRDHOUSE_DEPLOY_BRANCH : fix-bugs-in-pavics-compose.sh
DACCS_CONFIGS_BRANCH : master
PAVICS_E2E_WORKFLOW_TESTS_BRANCH : master
PAVICS_SDI_BRANCH : master

DESTROY_INFRA_ON_EXIT : true
PAVICS_HOST : https://

PAVICS-e2e-workflow-tests Pipeline Results

Tests URL :

NOTEBOOK TEST RESULTS
    
</code>

@tlvu tlvu requested a review from matprov December 15, 2022 03:12
Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

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

AFAIU this looks nice and useful!

birdhouse/default.env Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
birdhouse/pavics-compose.sh Outdated Show resolved Hide resolved
Comment on lines +116 to +120
for i in ${DELAYED_EVAL}; do
v="`eval "echo \\$${i}"`"
eval 'export ${i}="`eval "echo ${v}"`"'
echo "delayed eval '`env |grep ${i}=`'"
done
Copy link
Collaborator

@fmigneault fmigneault Dec 15, 2022

Choose a reason for hiding this comment

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

I'm not sure if I understand the need for the separate DELAYED_EVAL definition.
Wouldn't developers forgetting to specify a new variable name in it be more prone to error?
Couldn't all variables in ${VARS} do the v="`eval "echo \\$${i}"`" step, and this way simply using the single quotes would be sufficient to achieve the same result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, if you think for simplicity, all vars in default.env should be delayed eval then VARS do not contain all of them. VARS currently do not contain the 3 broken vars in DELAYED_EVAL.

Then it looks like delayed eval is an exception rather than the norm. So I'd rather not forced the single quote on more vars than needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So they should be defined in OPTIONAL_VARS instead, and this loop should use OPTIONAL_VARS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not clear to me what is your reluctance to have a new var DELAYED_EVAL. Let's say we go with OPTIONAL_VARS, the person changing default.env still have to remember to add any new vars that need delayed eval to OPTIONAL_VARS again.

Basically, if the goal in simplicity, then having to remember to add to DELAYED_EVAL vs OPTIONAL_VARS is the same effort. With DELAYED_EVAL at least the feature is specific and the dev will have to remember to use single-quote.

I am not sure what is the gain to overload OPTIONAL_VARS with a new feature. Currently OPTIONAL_VARS is only used for template substitution. I'd rather have one duty per var for simplicity sake.

Copy link
Collaborator

@fmigneault fmigneault Dec 22, 2022

Choose a reason for hiding this comment

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

I'm not reluctant to it if there's no way around it.
I'm rather trying to see if there's a way we could drop all these manual steps altogether.
Technically, we could generate the contents of OPTIONAL_VARS using only a grep -E 'export [A-Z]=', and then we would not have to worry about those steps ever again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ouch, the grep trick might too magic for me. How do you get the name of each var after?

Copy link
Collaborator

@fmigneault fmigneault Dec 22, 2022

Choose a reason for hiding this comment

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

Using this:
cat birdhouse/default.env | grep -E "export [A-Z0-9_]+=" | cut -d ' ' -f 2 | cut -d '=' -f 1

Copy link
Collaborator

Choose a reason for hiding this comment

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

And an extra | sed -r -e 's/(.*)/\$\1/g' at the end for adding the $.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh wow, think I'll pass on this magic for now. We have to handle all the default.env from components from any other external repos as well. I don't have time to think of all the corner cases with this magic for now.

Do you see anything blocking with the current approach?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. Good to go with the current alternative.

@tlvu tlvu changed the title pavics compose.sh: overriding DATA_PERSIST_ROOT in env.local do not take effect and warn when a dir in EXTRA_CONF_DIRS do not exist pavics compose.sh: overriding DATA_PERSIST_ROOT in env.local do not take effect and warn when a dir in EXTRA_CONF_DIRS does not exist Dec 22, 2022
birdhouse/default.env Outdated Show resolved Hide resolved
Copy link
Collaborator

@fmigneault fmigneault left a comment

Choose a reason for hiding this comment

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

Current method sufficient for now.
Alternative to avoid DELAYED_EVAL to be considered as some other time as per #272 (comment).

For reference: #274

@github-actions github-actions bot added ci/operations Continuous Integration components documentation Improvements or additions to documentation labels Dec 23, 2022
@tlvu tlvu merged commit 2337a16 into master Dec 23, 2022
@tlvu tlvu deleted the fix-bugs-in-pavics-compose.sh branch December 23, 2022 22:52
tlvu added a commit that referenced this pull request Feb 13, 2023
## Fixes

There are other scripts sourcing `default.env` and `env.local` and all
those scripts have to expand the vars in `DELAYED_EVAL` list to have
their actual values.

Only scripts using the 3 variables in `DELAYED_EVAL` list are broken.

`DELAYED_EVAL` was previously introduced in PR
#272.

### Sample errors

`fix-geoserver-data-dir-perm` (called at the end of
`pavics-compose.sh`):
```
fix GeoServer data dir permission on first run only, when data dir do not exist yet.
+ DATA_DIR='${DATA_PERSIST_ROOT}/geoserver'
+ '[' -n  ]
+ docker run --rm --name fix-geoserver-data-dir-perm --volume '${DATA_PERSIST_ROOT}/geoserver:/datadir' --env FIRST_RUN_ONLY bash:5.1.4 bash -xc 'if [ -z "$FIRST_RUN_ONLY" -o ! -f /datadir/global.xml ]; \
    then chown -R 1000:10001 /datadir; else echo "No execute."; fi'
docker: Error response from daemon: create ${DATA_PERSIST_ROOT}/geoserver: "${DATA_PERSIST_ROOT}/geoserver" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
```
`trigger-deploy-notebook` (broke notebook deploy job):
```
+ TMP_SCRIPT=/tmp/notebookdeploy/notebookdeploy.XXXXXXIfafFK/deploy-notebook
+ cat
+ chmod a+x /tmp/notebookdeploy/notebookdeploy.XXXXXXIfafFK/deploy-notebook
+ docker run --rm --name deploy_tutorial_notebooks -u root -v /tmp/notebookdeploy/notebookdeploy.XXXXXXIfafFK/deploy-notebook:/deploy-notebook:ro -v /tmp/notebookdeploy/notebookdeploy.XXXXXXIfafFK/tutorial-notebooks:/tutorial-notebooks:ro -v '${DATA_PERSIST_ROOT}/jupyterhub_user_data:/notebook_dir:rw' --entrypoint /deploy-notebook bash:5.1.4
docker: Error response from daemon: create ${DATA_PERSIST_ROOT}/jupyterhub_user_data: "${DATA_PERSIST_ROOT}/jupyterhub_user_data" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
```
### Explanation of the fix

All scripts have to remember to call function `process_delayed_eval` in
order to obtain the real value of each vars in `DELAYED_EVAL` list.

Centralized all logic about reading configs (config files reading order,
remember to call `process_delayed_eval`) to avoid mistake and to ease
updating logic in the future. Too many scripts were reading the configs
themselves and some are not doing it properly, ex: forgot to hide
password when reading `env.local`.

### All scripts should do this going forward

```sh
# Set variable COMPOSE_DIR to the dir containing pavics-compose.sh and docker-compose.yml.

# Source the script providing function read_configs.
# read_configs uses COMPOSE_DIR to find default.env and env.local.
. $COMPOSE_DIR/read-configs.include.sh

# Call function read_configs to read the various config files in the appropriate order and process delayed eval vars properly.
read_configs
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/operations Continuous Integration components documentation Improvements or additions to documentation
Projects
None yet
4 participants