rr- / szurubooru

Image board engine, Danbooru-style.
GNU General Public License v3.0
704 stars 178 forks source link

ERROR: Service 'frontend' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 139 #212

Closed wychwitch closed 5 years ago

wychwitch commented 5 years ago

Hello, I'm currently running into this problem when building the front end on my raspberry pi 1.

docker-compose up -d
Building frontend
Step 1/16 : FROM node:9 as builder
 ---> 97f504c74032
Step 2/16 : WORKDIR /opt/app
 ---> Using cache
 ---> 5c12eb572e46
Step 3/16 : COPY package.json ./
 ---> Using cache
 ---> 36dc557a8900
Step 4/16 : RUN npm install
 ---> Running in 5cdec928bbfb
ERROR: Service 'frontend' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 139

Here is my docker file

FROM scratch as approot
WORKDIR /opt/app
COPY alembic.ini wait-for-es generate-thumb ./                                      COPY szurubooru/ ./szurubooru/
COPY config.yaml.dist ./

FROM python:3.6-slim
WORKDIR /opt/app

ARG PUID=1000
ARG PGID=1000
ARG PORT=6666
RUN \
    # Set users
    mkdir -p /opt/app /data && \
    groupadd -g ${PGID} app && \
    useradd -d /opt/app -M -c '' -g app -r -u ${PUID} app && \
    chown -R app:app /opt/app /data && \
    # Create init file
    echo "#!/bin/sh" >> /init && \
    echo "set -e" >> /init && \
    echo "cd /opt/app" >> /init && \
    echo "./wait-for-es" >> /init && \
    echo "alembic upgrade head" >> /init && \
    echo "exec waitress-serve --port ${PORT} szurubooru.facade:app" \
        >> /init && \
    chmod a+x /init && \
    # Install ffmpeg
    apt-get -yqq update && \
    apt-get -yq install --no-install-recommends ffmpeg && \
    apt-get -yqq install libpq-dev make gcc libffi-dev zlib1g-dev libjpeg-dev libtiff-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl-dev wget && \
    wget  https://nodejs.org/dist/v11.5.0/node-v4.3.2-linux-$(uname -m).tar.gz && \
    tar -xvf node-v11.5.0-linux-$(uname -m).tar.gz && \
    cd node-v11.5.0-linux-$(uname -m) && \
    cp -R * /usr/local/ && \
    rm -rf /var/lib/apt/lists/* && \
    # Install waitress
    pip3 install --no-cache-dir waitress

COPY --chown=app:app requirements.txt ./requirements.txt
RUN pip3 install --no-cache-dir -r ./requirements.txt

# done to minimize number of layers in final image
COPY --chown=app:app --from=approot / /

VOLUME ["/data/"]
EXPOSE ${PORT}
USER app
CMD ["/init"]

My os information is as follows:

OS: HypriotOS (v2.0.1) [Raspbian Stretch]
Hardware: Raspberry Pi 1 

As you can see I've editedthis socket file a bit. I ran into some dependency problems (mostly pillow, but also make before that) I fixed by including them in an apt-get. I also wget'd nodejs to make sure I had it installed in case that was the cause of the issue. Please let me know if there's anything I can fix or if you'd like more logs, I'm out of ideas.

Also because this is on a raspberry pi, numpy takes nearly 3 hours to compile so it might take a little while to try out a fix.

Thanks in advance to anyone who might help!

wychwitch commented 5 years ago

I now suspect that this is due to a wonky npm installation. I tried the installation method outside of the dockerfile and I got an error, and installing via adding the nodejs repo to my package manager (apt-get) game be an illegal instruction (nodejs -v). Npm simply can't be found.

I'm going to try and install a few different ways. Once I have it verified and working correctly I'll punch those same commands into my socket file and rebuild the image

sgsunder commented 5 years ago

This entire project is split into two parts. client/ is just a web interface that runs in the user's web browser, written in your usual HTML/JS/CSS. node/npm is only used for the build.js script that bundles all the client-side Javascript and CSS together. It's not used during runtime.

server/ is a REST API written in Python that is the core of the application. It doesn't need node to run. It's only dependencies are ffmpeg, the python packages in requirements.txt, and a connection to a PostgreSQL database plus an ElasticSearch database. You don't need to install node here.

So there's no need to modify server/Dockerfile to include node. Your error seems to be originating from the first build stage of client/Dockerfile. Here, you may need to change FROM node:9 to a base image compatible with ARM architecture.

And for server/Dockerfile, if you can find a way to get ARM-compatable wheel (binary) distributions for all the Python packages, you wouldn't need to install gcc and all the build tools. I'm not familiar with running Python on ARM systems, so I'm not sure how easy this is.

Hope this helps!

wychwitch commented 5 years ago

oh wow, I had no idea there was even a client dockerfile! I should've looked there whoops.

Thank you so much! While searching I found this https://hub.docker.com/r/hypriot/rpi-node/ which looks like it's exactly what I need. I just have to replace FROM node:9 to FROM hypriot/rpi-node:9 right? This whole experience has been my first time messing around with docker so forgive me if this is an obvious question.

EDIT: I ran it and it seems to have worked! its on step 8/16 of building the client so I'm going to let it finish running before I close this issue. Thank you so much @sgsunder !

wychwitch commented 5 years ago

Yep it worked! I'm having another error (szuru_elasticsearch_1 exited with code 1) but I'm pretty sure it's unrelated and probably my fault.

To Summarize for anyone who's running into this exact same problem, here is my client/Dockerfile:

FROM hypriot/rpi-node:8 as builder
WORKDIR /opt/app

COPY package.json ./
RUN npm install

COPY . ./

ARG BUILD_INFO="docker-latest"
ARG CLIENT_BUILD_ARGS=""
RUN BASE_URL="__BASEURL__" node build.js ${CLIENT_BUILD_ARGS}

RUN find public/ -name public/index.html -prune -o -type f -size +5k \
        -print0 | xargs -0 -- gzip -6 -k

FROM nginx:alpine
WORKDIR /var/www

RUN \
    # Create init file
    echo "#!/bin/sh" >> /init && \
    echo 'sed -i "s|__BACKEND__|${BACKEND_HOST}|" /etc/nginx/nginx.conf' \
        >> /init && \
    echo 'sed -i "s|__BASEURL__|${BASE_URL:-/}|" /var/www/index.htm' >> /init &&
 \
    echo 'exec nginx -g "daemon off;"' >> /init && \
    chmod a+x /init

CMD ["/init"]
VOLUME ["/data"]

COPY nginx.conf.docker /etc/nginx/nginx.conf
COPY --from=builder /opt/app/public/ .

Like was said earlier, change the FROM node:9 as builder to FROM hypriot/rpi-node:8 as builder. 8 because as far as I can tell, rpi-node:9 doesn't exist.

Thanks again @sgsunder for the help! I couldn't have done it without you. If I can't fix my new error I'll open up a separate issue for it. Edit: a issue was already opened for this problem! Here is my comment on it. if anyone is going down this same rabbithole as me in the future.