What Am I Doing Wrong?
from sabreW4K3@lazysoci.al to python@programming.dev on 10 Jun 2024 13:21
https://lazysoci.al/post/14507693

If I run this

#!/bin/bash

ARCH=$(python fetch_architecture.py)
if [ $ARCH == "aarch64" -o $ARCH == "armv71" ] ; then
    export PATH=/opt/local/llvm/bin:${PATH}
    cd /app
    RUSTFLAGS="-C linker=lld" wasm-pack build --target web --release plume-front
else
    wasm-pack build --target web --release plume-front
fi

via the terminal, it works just fine. But when I run it via the Dockerfile,

COPY . . 
RUN cargo install wasm-pack 
RUN chmod a+x ./script/plume-front.sh 
RUN sleep 1 
RUN ./script/plume-front.sh

It says python: command not found and then [: too many arguments

#python

threaded - newest

rglullis@communick.news on 10 Jun 2024 13:38 next collapse

What is your base image? It has no python installed.

sabreW4K3@lazysoci.al on 10 Jun 2024 18:13 collapse

Rust:1.78-bookworm.

Thank you, manually included it.

thenextguy@lemmy.world on 10 Jun 2024 13:39 next collapse

Python is not on the Path for docker. The error message “python: command not found” is then passed to the [ command (also called test) which says too many arguments.

Add the path /use/bin/ to your python command. Or figure out why it isn’t on the docker path.

sabreW4K3@lazysoci.al on 10 Jun 2024 18:14 collapse

Thank you so much.

wasabi@discuss.tchncs.de on 10 Jun 2024 13:40 next collapse

This is a docker/bash question, not a python question. Also reading the error message explains the problem.

sabreW4K3@lazysoci.al on 10 Jun 2024 18:04 collapse

Apologies, I thought it was Python because I was trying to execute a Python script. And double sorry for not knowing how to interpret the error message.

friend_of_satan@lemmy.world on 10 Jun 2024 13:40 next collapse

Python is not found, so $ARCH gets assigned to “”, and you didn’t double quote your variables in the comparison, so the code parses as [ == “aarch64” which is a syntax error.

Also, maybe uname -m could work instead of that Python script.

sabreW4K3@lazysoci.al on 10 Jun 2024 18:16 collapse

This was super insightful. Thank you so much.

onlinepersona@programming.dev on 10 Jun 2024 21:11 next collapse

In addition to what everybody said:

Those will help catch many problems before they happen or exactly when they happen.

P.S I would recommend against

set -o pipefail

It can introduce some very weird behaviour when it doesn’t work.

Anti Commercial-AI license

sabreW4K3@lazysoci.al on 11 Jun 2024 05:23 next collapse

Thank you so much. Especially for the Shell Check. That’s an invaluable resource.

wasabi@discuss.tchncs.de on 11 Jun 2024 09:09 collapse

Could you elaborate on the weird behaviour introduced by pipefail?

onlinepersona@programming.dev on 11 Jun 2024 10:20 collapse

This wiki explains one pitfall of nonstandard return codes in pipes. The other one that bit me is pipes that just stop existing (error 141).

Anti Commercial-AI license

wasabi@discuss.tchncs.de on 11 Jun 2024 11:14 collapse

Thanks. Bash should just be avoided except trivial uses. It has an impressive collection of footguns. I’ve written a lot of bash, even used it for CGI scripts to create web tools, but honestly it is time to move on. Ansible and Python cover most of the bash use cases.

onlinepersona@programming.dev on 11 Jun 2024 13:19 collapse

I fully agree with you. Hopefully newer shells will be used for distros (nushell, xonsh, osh, …). Backwards compatibility with bash is a huge pitfall that should be a disqualification criterion.

Anti Commercial-AI license

FizzyOrange@programming.dev on 10 Jun 2024 21:25 next collapse

You should use python3 anyway not python. The latter is sometimes Python 3, sometimes Python 2 and sometimes doesn’t exist. python3 works reliably, assuming you have it installed.

(And assuming you aren’t using the official Windows Python installer, but that doesn’t seem like the case here!)

sabreW4K3@lazysoci.al on 11 Jun 2024 05:22 collapse

I ended up adding Python3 as it moaned when I just added Python. Thank you so much for your advice though. I’m grateful.

[deleted] on 11 Jun 2024 12:15 collapse
.