For some projects, avoiding the JS ecosystem just isn't possible. If you ever find yourself needing to add
npm modules to your Phoenix app hosted on fly.io, here are the changes required to ensure your build step works.
- Note that this guide assumes you've already run
npm initin the
assetsdirectory of a Phoenix project.
- The guide also assumes that you have the associated
Dockerfileand supporting changes from running
fly launchto host your app on https://fly.io in your project.
curl is included as a dependency to be installed in the
RUN apt-get update -y && apt-get install -y build-essential git curl \ && apt-get clean && rm -f /var/lib/apt/lists/*_*
RUN apt-get update && apt-get install -y ca-certificates curl gnupg RUN mkdir -p /etc/apt/sources.list.d /etc/apt/keyrings RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list RUN apt-get update && apt-get install nodejs -y
Finally, node modules are installed from
npm to make sure they're available for the build step.
RUN npm install --prefix assets #... # The above needs to be run before this step RUN mix assets.deploy