diff --git a/Dockerfile b/Dockerfile index efac0ef..64e3ce2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,7 +74,7 @@ RUN mkdir -p /opt/app/tmp \ && ln -s /opt/app/artifacts/screenshots /opt/app/tmp/screenshots # Add binstubs to the path. -ENV PATH="/usr/bin:/opt/app/bin:$PATH" +ENV PATH="/usr/bin:/opt/app/bin:/usr/local/yarn/node_modules/bin:$PATH" # If run with no other arguments, the image will start the rails server by # default. Note that we must bind to all interfaces (0.0.0.0) because when @@ -108,8 +108,12 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \ gcc \ && rm -rf /var/lib/apt/lists/* +RUN mkdir -p /usr/local/yarn \ + && chown -R $APP_USER:$APP_USER /usr/local/yarn +COPY ./webpack.config.js ./package.json /usr/local/yarn + # ------------------------------------------------------------ -# Install Ruby gems +# Install Ruby gems and Yarn packages # Drop back to $APP_USER. USER $APP_USER @@ -127,6 +131,8 @@ RUN bundle install # re-install. COPY --chown=$APP_USER:$APP_USER . . +RUN yarn install --cwd /usr/local/yarn + # ============================================================================= # Target: production # @@ -149,6 +155,7 @@ ENV RAILS_SERVE_STATIC_FILES=true # Copy the built codebase from the dev stage COPY --from=development --chown=$APP_USER /opt/app /opt/app COPY --from=development --chown=$APP_USER /usr/local/bundle /usr/local/bundle +COPY --from=development --chown=$APP_USER /usr/local/yarn /usr/local/yarn # Ensure the bundle is installed and the Gemfile.lock is synced. RUN bundle config set frozen 'true' @@ -159,17 +166,13 @@ RUN bundle install --local # TODO: Figure out why jsbundling-rails doesn't invoke `yarn build` # *before* Sprockets reads app/assets/config/manifest.js -RUN yarn install && yarn build +RUN yarn install --cwd /usr/local/yarn # Pre-compile assets so we don't have to do it after deployment. # NOTE: dummy SECRET_KEY_BASE to prevent spurious initializer issues # -- see https://github.com/rails/rails/issues/32947 RUN SECRET_KEY_BASE=1 rails assets:precompile --trace -# Remove cached YARN packages -# TODO: change this to .yarn/cache once we're on Yarn 3.x -RUN rm -r .cache/yarn - # ------------------------------------------------------------ # Preserve build arguments diff --git a/docker-compose.yml b/docker-compose.yml index 899c773..5e508c8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: aliases: - app.test volumes: - - ./:/opt/app + - .:/opt/app - ./app/assets/builds:/opt/app/app/assets/builds ports: - 3000:3000