title: MeteorUp volumes and how Meteor can access to their contents
body: <p>First, thank you for reading my question. This is my first time on stackoverflow and I made a lot of research for answers that could help me.</p>
  <p><strong>CONTEXT</strong></p>
  <p>I'm developing a Meteor App that is used as a CMS, I create contents and store datas in mongoDb collections. The goal is to use these datas and a React project to build a static website, which is sent to an AWS S3 bucket for hosting purpose.</p>
  <p>I'm using meteorUp to deploy my Meteor App (on an AWS EC2 instance) and according to MeteorUp documentation (<a href="http://meteor-up.com/docs.html#volumes" rel="nofollow noreferrer">http://meteor-up.com/docs.html#volumes</a>), I added a docker volume in my mup.js:</p>
  <pre><code>module.exports = {
      ...
      meteor: {
        ...
        volumes: {
          '/opt/front': '/front'
        },
        ...
      },
      ...
  };
  </code></pre>
  <p>Once deployed, volume is well set in '/opt/myproject/config/start.sh':</p>
  <pre><code>sudo docker run \
    -d \
    --restart=always \
    $VOLUME \
     \
    --expose=3000 \
     \
    --hostname=&quot;$HOSTNAME-$APPNAME&quot; \
    --env-file=$ENV_FILE \
     \
    --log-opt max-size=100m --log-opt max-file=10  \
    -v /opt/front:/front  \
     --memory-reservation 600M  \
     \
    --name=$APPNAME \
    $IMAGE
  echo &quot;Ran abernix/meteord:node-8.4.0-base&quot;
  
  # When using a private docker registry, the cleanup run in 
  # Prepare Bundle is only done on one server, so we also
  # cleanup here so the other servers don't run out of disk space
  
  
  if [[ $VOLUME == &quot;&quot; ]]; then
    # The app starts much faster when prepare bundle is enabled,
    # so we do not need to wait as long
    sleep 3s
  else
    sleep 15s
  fi
  </code></pre>
  <p>On my EC2, '/opt/front' contains the React project used to generate a static website.
  This folder includes a package.json file, every modules are available in the 'node_modules' directory. 'react-scripts' is one of them, and package.json contains the following script line:</p>
  <pre><code>&quot;build&quot;: &quot;react-scripts build&quot;,
  </code></pre>
  <p><strong>React Project</strong></p>
  <p>React App is fed with a JSON file available in 'opt/front/src/assets/datas/publish.json'.</p>
  <p>This JSON file can be hand-written (so the project can be developed independently) or generated by my Meteor App.</p>
  <p><strong>Meteor App</strong></p>
  <p>Client-side, on the User Interface, we have a 'Publish' button that the Administrator can click when she/he wants to generate the static website (using CMS datas) and deploy it to the S3 bucket.</p>
  <p>It calls a Meteor method (server-side)</p>
  <p>Its action is separated in 3 steps:</p>
  <p><strong>1. Collect every useful datas and save them into a Publish collection</strong></p>
  <p><strong>2. JSON creation</strong></p>
  <p>a. Get Public collection first entry into a javascript object.</p>
  <p>b. Write a JSON file using that object in the React Project directory ('opt/front/src/assets/datas/publish.json').</p>
  <p><em>Here's the code:</em></p>
  <pre><code>import fs from 'fs';
      
  let publishDatas = Publish.find({}, {sort : { createdAt : -1}}).fetch();
  
  let jsonDatasString = JSON.stringify(publishDatas[0]);
  
  fs.writeFile('/front/src/assets/datas/publish.json', jsonDatasString, 'utf8', function (err) {
      if (err) {
          return console.log(err);
      }
  });
  </code></pre>
  <p><strong>2. Static Website build</strong></p>
  <p>a. Run a CD command to reach React Project's directory then run the 'build' script using this code:</p>
  <pre><code>process_exec_sync = function (command) {
      // Load future from fibers
      var Future = Npm.require(&quot;fibers/future&quot;);
      // Load exec
      var child = Npm.require(&quot;child_process&quot;);
      // Create new future
      var future = new Future();
      // Run command synchronous
      child.exec(command, {maxBuffer: 1024 * 10000}, function(error, stdout, stderr) {
          // return an onbject to identify error and success
          var result = {};
          // test for error
          if (error) {
              result.error = error;
          }
          // return stdout
          result.stdout = stdout;
          future.return(result);
      });
      // wait for future
      return future.wait();
  }   
  
  var build = process_exec_sync('(cd front &amp;&amp; npm run build)');
  </code></pre>
  <p>b. if 'build' is OK, then I send the 'front/build' content to my S3 bucket.</p>
  <p><strong>Behaviors:</strong></p>
  <p><em><strong>On local environment</strong></em> (Meteor running on development mode):</p>
  <p><em>FYI: React Project directory's name and location are slightly different.
  Its located in my meteor project directory, so instead of 'front', it's named '.#front' because I don't want Meteor to restart every time a file is modified, added or deleted.</em></p>
  <p>Everything works well, but I'm fully aware that I'm in development mode and I benefit from my local environment.</p>
  <p><em><strong>On production environment</strong></em> (Meteor running on production mode in a docker container):</p>
  <p>Step 2.b : It works well, I can see the new generated file in 'opt/front/src/assets/datas/'</p>
  <p>Step 3.a : I get the following error:</p>
  <blockquote>
  <p>&quot;Error running ls: Command failed: (cd /front &amp;&amp; npm run build)</p>
  <p>(node:39) ExperimentalWarning: The WHATWG Encoding Standard
  implementation is an experimental API. It should not yet be used in
  production applications.</p>
  <p>npm ERR! code ELIFECYCLE npm ERR! errno 1 npm
  ERR! front@0.1.0 build: <code>react-scripts build</code> npm ERR! Exit status 1
  npm ERR!  npm ERR! Failed at the front@0.1.0 build script. npm ERR!</p>
  <p>This is probably not a problem with npm. There is likely additional
  logging output above.</p>
  <p>npm ERR! A complete log of this run can be found in: npm ERR!<br />
  /root/.npm/_logs/2021-09-16T13_55_24_043Z-debug.log  [exec-fail]&quot;</p>
  </blockquote>
  <p>So here's my question:
  On production mode, is it possible to use Meteor to reach another directory and run a script from a package.json?</p>
  <p>I've been searching for an answer for months, and can't find a similar or nearby case.</p>
  <p>Am I doing something wrong?</p>
  <p>Am I using a wrong approach?</p>
  <p>Am I crazy? :D</p>
  <p>Thank you so much to have read until the end.</p>
  <p>Thank you for your answers!</p>
  <hr />
  <p><strong>!!!!! UPDATE !!!!!</strong></p>
  <p>I found the solution!</p>
  <p>In fact I had to check few things on my EC2 with ssh:</p>
  <ul>
  <li>once connected, I had to go to '/opt/front/' and try to build the React-app with 'npm run build'</li>
  <li>I had a first error because of CHMOD not set to 777 on that directory (noob!)</li>
  <li>then, I had an error because of node-sass.</li>
  </ul>
  <p>The reason is that my docker is using Node v8, and my EC2 is using Node v16.</p>
  <p>I had to install NVM and use a Node v8, then delete my React-App node_modules (and package-lock.json) then reinstall it.</p>
  <p>Once it was done, everything worked perfectly!</p>
  <p>I now have a Meteor App acting as a CMS / Preview website hosted on an EC2 instance that can publish a static website on a S3 bucket.</p>
  <p>Thank you for reading me!</p>