Skip to content

Commit

Permalink
Conditionally install findutils, sed
Browse files Browse the repository at this point in the history
Exclude create-env's own strip, find, xargs, sed binaries from strip.
(The files are in use and their replacement gets into a race condition.)

Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Oct 17, 2023
1 parent fb14ffa commit a8f1636
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
2 changes: 2 additions & 0 deletions images/create-env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

- Rebuilt on the latest base image with Debian 12.2 / BusyBox 1.36.1.

- Do not install findutils, sed if provided by the base image (as is currently).


## bioconda/create-env 2.2.1 (2022-10-14)

Expand Down
21 changes: 19 additions & 2 deletions images/create-env/create-env
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,33 @@ if [ -n "${strip_files_globs}" ] ; then
# Strip binaries. (Run strip on all files; ignore errors for non-ELF files.)
# Limit open fds (ulimit -n) for strip (small number chosen arbitrarily).
# (To avoid "could not create temporary file to hold stripped copy: Too many open files")

# Filter out the binaries currently in use by the pipeline via sed below.
skip_inode_expressions="$(
command -v -- find xargs sed strip \
| xargs -- stat -L -c '-e /^%d,%i:/d' --
)"
find "${prefix}" \
-type f \
\( "${@}" \) \
-print0 \
| xargs \
--null \
-0 \
-n 64 \
-- \
stat -L -c '%d,%i:%n' -- \
| sed \
${skip_inode_expressions} \
-e 's/^[^:]*://' \
| tr \\n \\0 \
|
xargs \
-0 \
-n 64 \
-- \
strip -- \
2>&1 \
| grep -v ': file format not recognized' \
| sed '/: file format not recognized/d' \
|| true
)
fi
Expand Down
30 changes: 19 additions & 11 deletions images/create-env/install-conda
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -eu
#! /bin/bash -eux

requirements_file="${1}"
conda_install_prefix="${2}"
Expand All @@ -7,6 +7,14 @@ conda_install_prefix="${2}"
miniconda_boostrap_prefix="$( pwd )/miniconda"
# Run the following in a subshell to avoid environment changes from bootstrap.
(

# Use the base image-provided tools if they work for us:
tools=''
find -print0 -maxdepth 0 && xargs -0 true < /dev/null \
|| tools="${tools} findutils"
sed -e '' < /dev/null \
|| tools="${tools} sed"

sh ./miniconda.sh \
-b \
-p "${miniconda_boostrap_prefix}"
Expand All @@ -25,10 +33,8 @@ miniconda_boostrap_prefix="$( pwd )/miniconda"
--prefix="${conda_install_prefix}" \
--channel=conda-forge \
binutils
tmp_dir="${miniconda_boostrap_prefix}/tmp-strip"
mkdir "${tmp_dir}"
cp -a "${conda_install_prefix}/bin/"*strip "${tmp_dir}/"
conda run --prefix="${conda_install_prefix}" strip -- "${tmp_dir}/"*strip
cp -aL "${conda_install_prefix}/bin/strip" ./strip
conda run --prefix="${conda_install_prefix}" strip -- ./strip
mamba remove --yes --all \
--prefix="${conda_install_prefix}"

Expand All @@ -41,15 +47,14 @@ miniconda_boostrap_prefix="$( pwd )/miniconda"
tini \
\
libgcc-ng \
findutils \
${tools} \
;

mv \
./print-env-activate \
./create-env \
"${tmp_dir}/"* \
./strip \
"${conda_install_prefix}/bin/"
rmdir "${tmp_dir}"
)

# Activate the new base environment.
Expand All @@ -61,9 +66,12 @@ eval "${activate_script}"
set -u
unset activate_script

# Run strip on find/xargs/grep beforehand as they are run in the strip pipeline.
for prog in find xargs grep ; do
strip -- "$( command -v "${prog}" )"
# Strip find/xargs/sed beforehand as they are excluded in the strip pipeline.
for prog in find xargs sed ; do
case "$( command -v "${prog}" )" in
"${conda_install_prefix%%/}"/* )
strip -- "$( command -v "${prog}" )"
esac
done

# Use --conda=: to turn the `conda create` into a no-op, but do continue to
Expand Down

0 comments on commit a8f1636

Please sign in to comment.