Skip to content

Commit f8a3425

Browse files
authored
Refactor Dockerfile to use printf for py-init function
1 parent abf3165 commit f8a3425

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

.devcontainer/docker/Dockerfile

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ RUN echo 'eval "$(/root/.local/bin/mise activate bash)"' > /etc/profile.d/mise.s
2121
# the function so child bash processes see it, and set BASH_ENV so
2222
# non-interactive bash shells source it too. Also source it from
2323
# /root/.bashrc to ensure interactive non-login shells get it.
24-
RUN cat > /etc/profile.d/py-init.sh <<'PYINIT'
25-
py-init() {
26-
if [ -z "$1" ]; then
27-
echo "Error: Please provide a Python version."
28-
echo "Example: py-init 3.11"
29-
return 1
30-
fi
31-
32-
echo "Initializing mise Python environment for version $1..."
33-
34-
touch ./mise.toml
35-
mise use python@$1
36-
mise config set env._.python.venv.path .venv
37-
mise config set env._.python.venv.create true
38-
39-
echo "Setup complete."
40-
}
41-
export -f py-init
42-
PYINIT
24+
RUN printf '%s\n' \
25+
'py-init() {' \
26+
' if [ -z "$1" ]; then' \
27+
' echo "Error: Please provide a Python version."' \
28+
' echo "Example: py-init 3.11"' \
29+
' return 1' \
30+
' fi' \
31+
' ' \
32+
' echo "Initializing mise Python environment for version $1..."' \
33+
' ' \
34+
' touch ./mise.toml' \
35+
' mise use python@$1' \
36+
' mise config set env._.python.venv.path .venv' \
37+
' mise config set env._.python.venv.create true' \
38+
' ' \
39+
' echo "Setup complete."' \
40+
'}' \
41+
'export -f py-init' \
42+
> /etc/profile.d/py-init.sh
4343

4444
RUN chmod 0755 /etc/profile.d/py-init.sh \
4545
&& echo 'source /etc/profile.d/py-init.sh' >> /root/.bashrc || true
@@ -51,4 +51,4 @@ RUN /root/.local/bin/mise use --global python@3.13
5151

5252
WORKDIR /workspace
5353

54-
CMD ["bash"]
54+
CMD ["bash"]

0 commit comments

Comments
 (0)