-
Notifications
You must be signed in to change notification settings - Fork 104
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
Support conda/mamba install --copy
#267
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ In order to use conda-lock in a docker-style context you want to add the lockfil | |||||||||
docker container. This avoids the case where the `conda install xyz` statement is cached. | ||||||||||
|
||||||||||
Given a file tree like | ||||||||||
|
||||||||||
``` | ||||||||||
Dockerfile | ||||||||||
environment.yaml | ||||||||||
|
@@ -15,24 +16,74 @@ You want a dockerfile that is structured something similar to this | |||||||||
```Dockerfile | ||||||||||
# Dockerfile | ||||||||||
|
||||||||||
# Build container | ||||||||||
FROM continuumio/miniconda:latest as conda | ||||||||||
# ----------------- | ||||||||||
# Builder container | ||||||||||
# ----------------- | ||||||||||
FROM continuumio/miniconda:latest as builder | ||||||||||
|
||||||||||
ADD conda-linux-64.lock /locks/conda-linux-64.lock | ||||||||||
COPY conda-linux-64.lock /locks/conda-linux-64.lock | ||||||||||
RUN conda create -p /opt/env --copy --file /locks/conda-linux-64.lock | ||||||||||
|
||||||||||
# ----------------- | ||||||||||
# Primary container | ||||||||||
# ----------------- | ||||||||||
FROM gcr.io/distroless/base-debian10 | ||||||||||
# copy over the generated environment | ||||||||||
COPY --from=conda /opt/env /opt/env | ||||||||||
COPY --from=builder /opt/env /opt/env | ||||||||||
ENV PATH="/opt/env/bin:${PATH}" | ||||||||||
``` | ||||||||||
|
||||||||||
To get this to work nicely generate the platform specific lock run | ||||||||||
To get this to work nicely generate the platform specific lock run something | ||||||||||
like this in your shell | ||||||||||
|
||||||||||
```shell | ||||||||||
```bash | ||||||||||
# Update the lockfile | ||||||||||
conda lock --format explicit --platform linux-64 | ||||||||||
docker build . | ||||||||||
# build the image | ||||||||||
docker build -t myimagename:mytag . | ||||||||||
``` | ||||||||||
|
||||||||||
This will ensure that your conda dependencies used in this docker container are | ||||||||||
always exactly reproducible. | ||||||||||
|
||||||||||
## conda-lock inside a build container | ||||||||||
|
||||||||||
You can also use conda-lock with a build-container style system if you make use of | ||||||||||
the `--copy` flag from `conda-lock install` | ||||||||||
|
||||||||||
```Dockerfile | ||||||||||
# ----------------- | ||||||||||
# Builder container | ||||||||||
# ----------------- | ||||||||||
FROM condaforge/mambaforge:4.14.0-0 as builder | ||||||||||
|
||||||||||
COPY environment.yml /docker/environment.yml | ||||||||||
|
||||||||||
RUN . /opt/conda/etc/profile.d/conda.sh && \ | ||||||||||
mamba create --name lock && \ | ||||||||||
conda activate lock && \ | ||||||||||
mamba env list && \ | ||||||||||
mamba install --yes pip conda-lock>=1.2.2 setuptools wheel && \ | ||||||||||
conda-lock lock \ | ||||||||||
--platform linux-64 \ | ||||||||||
--file /docker/environment.yml \ | ||||||||||
--kind lock \ | ||||||||||
--lockfile /docker/conda-lock.yml | ||||||||||
|
||||||||||
RUN . /opt/conda/etc/profile.d/conda.sh && \ | ||||||||||
conda activate lock && \ | ||||||||||
conda-lock install \ | ||||||||||
--mamba \ | ||||||||||
--copy \ | ||||||||||
--prefix /opt/env \ | ||||||||||
/docker/conda-lock.yml | ||||||||||
# optionally you can perfom some more cleanup on your conda install after this | ||||||||||
# to get a leaner conda environment | ||||||||||
Comment on lines
+80
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just be explicit here?
Suggested change
|
||||||||||
|
||||||||||
# ----------------- | ||||||||||
# Primary container | ||||||||||
# ----------------- | ||||||||||
FROM gcr.io/distroless/base-debian10 | ||||||||||
COPY --from=builder /opt/env /opt/env | ||||||||||
ENV PATH="/opt/env/bin:${PATH}" | ||||||||||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm following correctly, then
conda-lock.yml
only lives in the Docker cache where it can't be tracked with version control. Do we really want to recommend this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hence the two approaches in this document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I'm missing something obvious here... I think I don't know what is a "build-container style system".
Two reasons I can think of off the top of my head for locking:
It seems like neither of these applies in this case. (For 2. at least there's a file in the container, but if you have to go into the container to see it, you might as well run
conda env export
.)What's the benefit to this approach over installing directly from
environment.yml
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the main benefit is more when you are using something like
earthly
and have a single earthfile specify multiple docker outputs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't know about Earthly. So if I understand correctly, one benefit is that the lockfile can be reused in multiple Dockerfile stages (or similar) to avoid multiple solves.