diff --git a/Dockerfile b/Dockerfile index 48b24cc..c1f44b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,23 @@ -FROM opendronemap/odm:latest -MAINTAINER Piero Toffanin - -EXPOSE 3000 - -USER root -RUN apt-get update && apt-get install -y curl gpg-agent -RUN curl --silent --location https://deb.nodesource.com/setup_14.x | bash - -RUN apt-get install -y nodejs unzip p7zip-full && npm install -g nodemon && \ - ln -s /code/SuperBuild/install/bin/untwine /usr/bin/untwine && \ - ln -s /code/SuperBuild/install/bin/entwine /usr/bin/entwine && \ - ln -s /code/SuperBuild/install/bin/pdal /usr/bin/pdal - - -RUN mkdir /var/www - -WORKDIR "/var/www" -COPY . /var/www - -RUN npm install --production && mkdir -p tmp - -ENTRYPOINT ["/usr/bin/node", "/var/www/index.js"] +FROM opendronemap/odm:latest +MAINTAINER Piero Toffanin + +EXPOSE 3000 + +USER root + +RUN mkdir /var/www + +WORKDIR "/var/www" +COPY . /var/www + +ENV NVM_DIR /usr/local/nvm +ENV NODE_VERSION 14 + +RUN bash install_deps.sh && \ + ln -s /code/SuperBuild/install/bin/untwine /usr/bin/untwine && \ + ln -s /code/SuperBuild/install/bin/entwine /usr/bin/entwine && \ + ln -s /code/SuperBuild/install/bin/pdal /usr/bin/pdal && \ + ln -s /var/www/node.sh /usr/bin/node && \ + mkdir -p tmp && node index.js --powercycle + +ENTRYPOINT ["/usr/bin/node", "/var/www/index.js"] diff --git a/Dockerfile.gpu b/Dockerfile.gpu index 738bd04..434b4cb 100644 --- a/Dockerfile.gpu +++ b/Dockerfile.gpu @@ -4,12 +4,15 @@ MAINTAINER Piero Toffanin EXPOSE 3000 USER root -RUN apt-get update && apt-get install -y curl gpg-agent ca-certificates -RUN curl --silent --location https://deb.nodesource.com/setup_14.x | bash - -RUN apt-get install -y nodejs unzip p7zip-full && npm install -g nodemon && \ + +ENV NVM_DIR /usr/local/nvm +ENV NODE_VERSION 14 + +RUN bash install_deps.sh && \ ln -s /code/SuperBuild/install/bin/untwine /usr/bin/untwine && \ ln -s /code/SuperBuild/install/bin/entwine /usr/bin/entwine && \ - ln -s /code/SuperBuild/install/bin/pdal /usr/bin/pdal + ln -s /code/SuperBuild/install/bin/pdal /usr/bin/pdal && \ + ln -s /var/www/node.sh /usr/bin/node RUN echo /usr/local/cuda-11.2/compat >> /etc/ld.so.conf.d/989_cuda-11.conf && ldconfig @@ -19,7 +22,7 @@ WORKDIR "/var/www" RUN useradd -m -d "/home/odm" -s /bin/bash odm COPY --chown=odm:odm . /var/www -RUN npm install --production && mkdir -p tmp +RUN npm install --production && mkdir -p tmp && node index.js --powercycle RUN chown -R odm:odm /var/www RUN chown -R odm:odm /code diff --git a/helpers/odmOptionsToJson.py b/helpers/odmOptionsToJson.py index 9a4e0ce..be66f0f 100644 --- a/helpers/odmOptionsToJson.py +++ b/helpers/odmOptionsToJson.py @@ -18,24 +18,33 @@ ''' import sys -import imp +import importlib.util +import importlib.machinery +import types import argparse import json import os +def load_source(module_name, filename): + loader = importlib.machinery.SourceFileLoader(module_name, filename) + module = types.ModuleType(loader.name) + module.__file__ = filename + loader.exec_module(module) + return module + dest_file = os.environ.get("ODM_OPTIONS_TMP_FILE") sys.path.append(sys.argv[2]) try: - imp.load_source('opendm', sys.argv[2] + '/opendm/__init__.py') + load_source('opendm', sys.argv[2] + '/opendm/__init__.py') except: pass try: - imp.load_source('context', sys.argv[2] + '/opendm/context.py') + load_source('context', sys.argv[2] + '/opendm/context.py') except: pass -odm = imp.load_source('config', sys.argv[2] + '/opendm/config.py') +odm = load_source('config', sys.argv[2] + '/opendm/config.py') options = {} class ArgumentParserStub(argparse.ArgumentParser): diff --git a/install_deps.sh b/install_deps.sh new file mode 100644 index 0000000..54d6395 --- /dev/null +++ b/install_deps.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ -z "$NVM_DIR" ]; then + echo "Error: NVM_DIR environment variable is not set" >&2 + exit 1 +fi +if [ -z "$NODE_VERSION" ]; then + echo "Error: NODE_VERSION environment variable is not set" >&2 + exit 1 +fi + +for i in {1..20}; do + apt-get update && apt-get install -y curl gpg-agent && break + echo "apt-get failed, retrying... ($i/20)" + sleep 30 +done + +mkdir -p $NVM_DIR +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash +source $NVM_DIR/nvm.sh +nvm install $NODE_VERSION +nvm alias default $NODE_VERSION + +for i in {1..20}; do + apt-get install -y unzip p7zip-full && npm install -g nodemon && break + echo "apt-get failed, retrying... ($i/20)" + sleep 30 +done + +npm install --production \ No newline at end of file diff --git a/libs/odmRunner.js b/libs/odmRunner.js index 334bcea..2e54bd6 100644 --- a/libs/odmRunner.js +++ b/libs/odmRunner.js @@ -133,7 +133,7 @@ module.exports = { } let childProcess = spawn(pythonExe, [shQuote(path.join(__dirname, "..", "helpers", "odmOptionsToJson.py")), - "--project-path", shQuote(config.odm_path), "bogusname"], { env, stdio: 'inherit', shell: true }); + "--project-path", shQuote(config.odm_path), "bogusname"], { env, shell: true }); // Cleanup on done let handleResult = (err, result) => { diff --git a/node.sh b/node.sh new file mode 100755 index 0000000..30c59a5 --- /dev/null +++ b/node.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -z "$NVM_DIR" ]; then + echo "Error: NVM_DIR environment variable is not set" >&2 + exit 1 +fi + +source $NVM_DIR/nvm.sh +nvm use $NODE_VERSION +exec node "$@" \ No newline at end of file