Rails deployment fails at bundle exec rails assets:precomile

I recently upgraded my project to Rails 7. Locally I can run bundle exec rails assets:precompile however when I try to deploy with fly the deployment fails:

#23 16.19 Compiling...
#23 18.46 Compilation failed:
#23 18.46 Internal Error: project@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile
#23 18.46     at pQ.getCandidates (/root/.volta/tools/image/yarn/3.3.0/bin/yarn.js:435:5146)
#23 18.46     at Wf.getCandidates (/root/.volta/tools/image/yarn/3.3.0/bin/yarn.js:391:1264)
#23 18.46     at /root/.volta/tools/image/yarn/3.3.0/bin/yarn.js:439:7695
#23 18.46     at Rf (/root/.volta/tools/image/yarn/3.3.0/bin/yarn.js:390:8965)
#23 18.46     at ge (/root/.volta/tools/image/yarn/3.3.0/bin/yarn.js:439:7675)
#23 18.46
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/bash -c bundle exec rails assets:precompile]: exit code: 1

I was using a pretty old version of yarn so I upgraded with yarn set version stable.

Now I’m seeing this error message:

 => ERROR [stage-4 3/5] COPY --from=node_modules /app/node_modules /app/node_modules                                      0.0s
------
 > [stage-4 3/5] COPY --from=node_modules /app/node_modules /app/node_modules:
------
Error failed to fetch an image or build from source: error building: failed to compute cache key: "/app/node_modules" not found: not found

I’m not particular about the version of Yarn I use, I’d be willing to revert to the old version if I could get it working.

For additional context I’m including these lines of my dockerfile:

# syntax = docker/dockerfile:experimental
ARG RUBY_VERSION=3.0.1
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

ARG NODE_VERSION=16
ARG BUNDLER_VERSION=2.2.15

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

SHELL ["/bin/bash", "-c"]

RUN curl https://get.volta.sh | bash

ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:/usr/local/bin:$PATH

RUN volta install node@${NODE_VERSION} && volta install yarn

FROM base as build_deps

ARG DEV_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV DEV_PACKAGES ${DEV_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${DEV_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

FROM build_deps as gems

RUN gem install -N bundler -v ${BUNDLER_VERSION}

COPY Gemfile* ./
RUN bundle install &&  rm -rf vendor/bundle/ruby/*/cache

FROM build_deps as node_modules

COPY package*json ./
COPY yarn.* ./

RUN if [ -f "yarn.lock" ]; then \
    yarn install; \
    elif [ -f "package-lock.json" ]; then \
    npm install; \
    else \
    mkdir node_modules; \
    fi

FROM base

ARG PROD_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0 imagemagick"
ENV PROD_PACKAGES=${PROD_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${PROD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

COPY --from=gems /app /app
#COPY --from=node_modules /app/node_modules /app/node_modules

ENV SECRET_KEY_BASE 1

COPY . .
RUN yarn instll
RUN bundle exec rails assets:precompile

ENV PORT 8080

ARG SERVER_COMMAND="bundle exec puma"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

In order to help, I’d need to see more of the Dockerfile. The Dockerfiles we currently generate look a bit different, though I can’t think of any changes we made that would help here.

Thanks, I’ve included the full Dockerfile… I’m not entirely sure where this came from, I assumed it was fly launch back in June.

Looks like it. Currently produced Dockerfiles tend to look like this:

ARG YARN_VERSION=1.22.19
. . .
RUN volta install node@${NODE_VERSION} yarn@${YARN_VERSION} 

In other words, it will install the version of Yarn that you specify, not whatever is latest.

But even with that Dockerfile, I can’t explain why node_modules would be missing.

Our story on upgrades after you make a significant change to your application isn’t the best right now (but we’re working on it, see: Dockerfile-less-deploys · Fly ). If you are willing, I would suggest a clean start: in a separate directory run 'rails new foo -j webpack; cd foo; fly launch. Let it pick a name. Don't allocate postgres or redis. Copy the Dockerfileandlib/tasks/fly.rakefiles over to your application. Compare thefly.tomlfiles and copy over any relevant changes. Delete the fly application you just created either usingflyctl apps destroy` or the dashboard.