Tech notes/yarn run in docker
<p>I wanted to build the assets for a website as part of the startup process of a django container. To speed it up, I wanted to install the dependencies during the image creation in the same way I was already doing it for the Python dependencies. </p>
<p>The first think I did was moving the files into the container while building the image:</p>
<pre class="codehilite"><code>COPY ./yarn.lock /yarn.lock
COPY ./package.json /package.json
RUN yarn install
</code></pre>
<p>And I created a start script that would run:</p>
<pre class="codehilite"><code>yarn webpack
</code></pre>
<p>The problem is that the <strong>node_modules</strong> folder ended up being a folder above where the project's <code>package.json</code> file was (in the <code>/app</code> directory in the container). I couldn't find a way of telling yarn where to look for the modules, so I had to force the proper webpack to run, by updated the start script to:</p>
<pre class="codehilite"><code>/node_modules/.bin/webpack --mode=production
</code></pre>
<p>The full example code is in this <a href="https://github.com/Klimaat-Helpdesk/website/pull/52/files">pull request</a>. </p>
<p>Tags: <a href="/tags/docker">#docker</a> <a href="/tags/yarn">#yarn</a> <a href="/tags/building-assets">#building-assets</a> <a href="/tags/build-automation">#build-automation</a></p>
Backlinks
These are the other notes that link to this one.
Nothing links here, how did you reach this page then?
Comment
Share your thoughts on this note. Comments are not public, they are
messages sent directly to my inbox.