Skip to content

Commit c82ae81

Browse files
authored
Merge pull request #25 from mfhepp/micromamba2.0.4
Update to 2.0.4, add lock/pinning mechanism
2 parents 21f26a5 + bc7469d commit c82ae81

File tree

10 files changed

+901
-874
lines changed

10 files changed

+901
-874
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG MICROMAMBA_VERSION="2.0.2"
1+
ARG MICROMAMBA_VERSION="2.0.4"
22
ARG ENVIRONMENT_FILE="env.yaml"
33
ARG NOTEBOOK_MODE
44
# Stage 1

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Based on [`micromamba-docker`](https://github.com/mamba-org/micromamba-docker) a
2020
- Adding new kernel capabilities is blocked
2121
- **Development mode,** in which the local version of the Python code can be run inside the container
2222
- **Jupyter Notebook / JupyterLab**: You can also run Jupyter Notebook and JupyterLab inside the isolated container.
23+
- **Reproducible:** `build.sh` writes a YAML specification including versions for all `conda` and `pip` components, which can be used to reproduce a Python environment.
2324

2425
## Installation
2526

@@ -174,6 +175,15 @@ This can be done with the `-f` (for _force_) option:
174175
175176
Note that this may change the installed versions of Python packages. There is currently no mechanism for pinning the installed versions.
176177
178+
### Building from pinned versions
179+
180+
You can build a Docker image from the `*.yaml.lock` files, which contain the pinned versions of all `conda` and `pip` dependencies with the option `-l`, like so
181+
182+
```bash
183+
./build.sh -l
184+
./build.sh -nl dataviz
185+
```
186+
177187
## Running the Script with `run_script.sh`
178188
179189
This script starts the code in `main.py` inside a Docker container.

build.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ NOTEBOOK_ID="notebook"
1919
BUILD_NOTEBOOK=""
2020
DIGEST=""
2121
ENVIRONMENT_FILE="env.yaml"
22+
LOCK_SUFFIX=""
23+
# LOCK_SUFFIX=".lock"
24+
2225

2326
usage ()
2427
{
@@ -27,15 +30,16 @@ usage ()
2730
printf 'Option(s):\n'
2831
printf " -d: development mode (create $USER/$APPLICATION_ID:dev)\n"
2932
printf ' -f: force fresh build, ignoring cached build stages (will e.g. update Python packages)\n'
30-
printf " -n: Jupyter Notebook mode (create $USER/$NOTEBOOK_ID or $USER/$NOTEBOOK_ID:<env_name>)\n"
33+
printf " -n: Jupyter Notebook mode (create $USER/$NOTEBOOK_ID or $USER/$NOTEBOOK_ID:<env_name>)\n"
34+
printf " -l: build from <env.yaml.lock> file (pinned dependencies)\n"
3135
}
3236

3337
if [[ $1 = "--help" ]]; then
3438
usage
3539
exit 0
3640
fi
3741

38-
while getopts ":dfn" opt; do
42+
while getopts ":dfnl" opt; do
3943
case ${opt} in
4044
d)
4145
if [ "$APPLICATION_ID" = "$NOTEBOOK_ID" ]; then
@@ -50,6 +54,11 @@ while getopts ":dfn" opt; do
5054
echo "INFO: Force fresh build, ignoring cached build stages (will update Python packages and Debian packages)"
5155
PARAMETERS="--no-cache"
5256
;;
57+
l)
58+
echo "INFO: Build from LOCK file with pinned dependencies. Implies -f, ignoring cached build stages"
59+
PARAMETERS="--no-cache"
60+
LOCK_SUFFIX=".lock"
61+
;;
5362
n)
5463
if [ "$DIGEST" = "dev" ]; then
5564
echo "ERROR: Incompatible options -d and -n. Aborting."
@@ -69,10 +78,12 @@ done
6978
# Remove processed arguments
7079
shift $((OPTIND-1))
7180

81+
ENVIRONMENT_FILE="$ENVIRONMENT_FILE$LOCK_SUFFIX"
82+
7283
if [ $# -eq 0 ]; then
7384
echo "INFO: Environment file = $ENVIRONMENT_FILE"
7485
else
75-
ENVIRONMENT_FILE="$1.yaml"
86+
ENVIRONMENT_FILE="$1.yaml$LOCK_SUFFIX"
7687
# user:test_app:env-dev
7788
# user:test_app:env
7889
# user:notebook:env
@@ -92,14 +103,23 @@ docker build $PARAMETERS \
92103
--build-arg="ENVIRONMENT_FILE=$ENVIRONMENT_FILE" \
93104
$BUILD_NOTEBOOK \
94105
--progress=plain --tag $IMAGE_NAME .
95-
echo INFO: Writing lock file of installed packages for $ENVIRONMENT_FILE
96-
docker run \
106+
# Update lock file if we build from the unpinned environment specification
107+
if [ -z "$LOCK_SUFFIX" ]; then
108+
# Command to run if $LOCK_SUFFIX is empty
109+
echo INFO: Writing lock file of installed packages for $ENVIRONMENT_FILE
110+
docker run \
97111
--security-opt seccomp=seccomp-default.json \
98112
--security-opt=no-new-privileges \
99113
--read-only --tmpfs /tmp \
100114
--cap-drop all \
101115
--rm \
102116
$IMAGE_NAME \
103117
micromamba env export -n base > $ENVIRONMENT_FILE.lock
104-
# --explicit would give more details, but would be less portable
105-
echo INFO: Build completed.
118+
# --explicit would give more details, but would be less portable
119+
# Since 2.0.4, pip packages are included
120+
# See https://github.com/mamba-org/mamba/issues/2008#issuecomment-2500257976
121+
else
122+
echo "INFO: $ENVIRONMENT_FILE will not be updated"
123+
fi
124+
125+
echo INFO: Build completed.

dataviz.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ dependencies:
2727
# - jupyter_ai
2828
# PyPi modules
2929
# - pip:
30+
# - pyserial
3031
# - black[jupyter]

0 commit comments

Comments
 (0)