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

Containerize: accommodate nested or pre-existing spack-env paths #41558

Merged
merged 4 commits into from
Jan 11, 2024

Conversation

odoublewen
Copy link
Contributor

@odoublewen odoublewen commented Dec 11, 2023

fixes #41656

The current mkdir {{ paths.environment }} will generate an error if:

  • {{ paths.environment }} already exists, or
  • {{ paths.environment }} is nested in non-existing dirs.

Adding -p to the command will make this robust to both possibilities.

Why would {{ paths.environment }} pre-exist? Sometimes I need to copy a custom spack package repo into my spack environment, to provide spack packages for proprietary software. I like the custom repo to stay relative to the spack.yaml file for portability (i.e. so that the spack.yaml file can work both inside and outside of the containerize command.)

cc: @hartzell

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.
@spackbot-app spackbot-app bot added core PR affects Spack core functionality docker labels Dec 11, 2023
@wdconinc
Copy link
Contributor

Isn't a pre-existing directory more likely an indication of unexpected behavior? I'd be worried that this will silently overwrite a spack.yaml file already in /opt/spack-environments since containerize uses a shell redirect.

@odoublewen
Copy link
Contributor Author

Thank you @wdconinc for your comment. A valid concern. I've proposed an alternative change (#41746) that would be a different (and better) way to address the issue I'm facing.

@alalazo alalazo self-assigned this Jan 9, 2024
@alalazo
Copy link
Member

alalazo commented Jan 9, 2024

On the other hand, how likely it is that a spack.yaml file is in the build.image in the /opt/spack-environment directory "accidentally" ? @wdconinc Which use case do you see as potentially problematic with this PR ?

@wdconinc
Copy link
Contributor

One use case that I can imagine is that someone uses a base image that is itself the outcome of a spack containerize run. This could fit in a strategy of layering containers: env1 installs core dependencies, env2 uses env1 image as base and installs dependent packages (reusing what's in /opt/software), env3 uses env1 as well to install other dependent packages (also reusing /opt/software), etc. This would cause the env1 spack.yaml to be overwritten by the env2 and env3 spack.yamls.

Yes, maybe this is a bit contrived, and maybe the 'damage' is minimal in this case.

@alalazo
Copy link
Member

alalazo commented Jan 10, 2024

Yes, maybe this is a bit contrived, and maybe the 'damage' is minimal in this case.

Yeah, if you don't strong oppose to this solution, I would be for merging this PR.

@odoublewen
Copy link
Contributor Author

This would cause the env1 spack.yaml to be overwritten by the env2 and env3 spack.yamls

@wdconinc Just out of curiosity, in this scenario, which spack.yaml would be the right one to keep?

In any case, if we believe it is important to protect against silently overwriting an existing spack.yaml file, we could do something like:

RUN mkdir -p {{ paths.environment }} \
{{ manifest }} > /tmp/spack.yaml && \
mv -n /tmp/spack.yaml {{ paths.environment }}/spack.yaml

At least that would preserve the behavior of throwing an error during build, if the environment dir pre-exists and contains a spack.yaml file.

@wdconinc
Copy link
Contributor

which spack.yaml would be the right one to keep?

I would just want spack to error out instead of picking one over the other in that case :-)

Maybe set -o noclobber is sufficient too, rather than doing the tmp and mv.

@odoublewen
Copy link
Contributor Author

odoublewen commented Jan 10, 2024

Maybe set -o noclobber is sufficient too, rather than doing the tmp and mv.

Oh, nice. I didn't know about that bash option.

So then how about (edited to correct path):

RUN mkdir -p {{ paths.environment }} && \
set -o noclobber \
{{ manifest }} > {{ paths.environment }}/spack.yaml

(btw I think it's odd that the {{ manifest }} string includes the && but maybe there's a subtle reasons for this that I don't see... anyway we don't need to go down that path right now...)

If you both agre with the above, I will update my PR and rebase with develop.

@wdconinc
Copy link
Contributor

Sounds good to me.

@odoublewen
Copy link
Contributor Author

I don't have the ability to add a reviewer to the PR. Could one of you maybe add yourself (and approve it if you think it's ready?)

@alalazo alalazo merged commit 4022f08 into spack:develop Jan 11, 2024
46 checks passed
@alalazo
Copy link
Member

alalazo commented Jan 11, 2024

Thanks @odoublewen !

@odoublewen odoublewen deleted the patch-1 branch January 11, 2024 17:49
alalazo pushed a commit that referenced this pull request Jan 15, 2024
)

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.

Set noclobber bash option when writing manifest.
@alalazo alalazo mentioned this pull request Jan 15, 2024
13 tasks
RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jan 25, 2024
…ck#41558)

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.

Set noclobber bash option when writing manifest.
RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jan 31, 2024
…ck#41558)

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.

Set noclobber bash option when writing manifest.
alalazo pushed a commit that referenced this pull request Feb 29, 2024
)

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.

Set noclobber bash option when writing manifest.
greenc-FNAL pushed a commit to FNALssi/spack that referenced this pull request Mar 21, 2024
…ck#41558)

The current `mkdir {{ paths.environment }}` will generate an error if:
* `{{ paths.environment }}` already exists, or
* `{{ paths.environment }}` is nested in non-existing dirs.

Adding `-p` to the command will make this robust to both possibilities.

Set noclobber bash option when writing manifest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core PR affects Spack core functionality docker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

containerize: issues with custom repos in the environment directory
3 participants