All threads / Docker rails assets:precompile
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Docker rails assets:precompile

Islam Bahnas asked in Rails

Hello I'm learning docker and faced this error while testing it locally

banstein@DESKTOP-I54N512:~/Projects/icb$ docker-compose build
[+] Building 4.2s (12/12) FINISHED                                                    
 => [internal] load build definition from Dockerfile                             0.0s
 => => transferring dockerfile: 32B                                              0.0s
 => [internal] load .dockerignore                                                0.0s
 => => transferring context: 35B                                                 0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.0                    1.0s
 => [internal] load build context                                                0.0s
 => => transferring context: 7.59kB                                              0.0s
 => [1/8] FROM docker.io/library/ruby:3.2.0@sha256:f2ec40227806aaab47e928f2e0ea  0.0s
 => CACHED [2/8] RUN apt-get update -qq &&     apt-get install -y build-essenti  0.0s
 => CACHED [3/8] WORKDIR /rails                                                  0.0s
 => CACHED [4/8] COPY Gemfile Gemfile.lock ./                                    0.0s
 => CACHED [5/8] RUN bundle install                                              0.0s
 => CACHED [6/8] COPY . .                                                        0.0s
 => CACHED [7/8] RUN bundle exec bootsnap precompile --gemfile app/ lib/         0.0s
 => ERROR [8/8] RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile  3.1s
------
 > [8/8] RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile:
#0 3.016 Parsing scenario file install
#0 3.017 ERROR: [Errno 2] No such file or directory: 'install'
#0 3.027 rails aborted!
#0 3.027 jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors
#0 3.027 
#0 3.027 Tasks: TOP => assets:precompile => javascript:build
#0 3.027 (See full trace by running task with --trace)
------
failed to solve: executor failed running [/bin/sh -c SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile]: exit code: 1

Hey Islam,

Looks like rails can't find the install directory. After [6/8] COPY . ., insert a bash shell and poke around to verify that the directories you copied actually exist. Also, can you post the Dockerfile and docker-compose file?

here is the Dockerfile
i setup the project with rails g new --main --database=postgresql --css=bootstrap

# Make sure it matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.0
FROM ruby:$RUBY_VERSION

# Install libvips for Active Storage preview support
RUN apt-get update -qq && \
    apt-get install -y build-essential libvips bash bash-completion libffi-dev tzdata postgresql nodejs npm yarn && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_LOG_TO_STDOUT="1" \
    RAILS_SERVE_STATIC_FILES="true" \
    RAILS_ENV="production" \
    BUNDLE_WITHOUT="development"

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# ENTRYPOINT ["rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]

docker-compose file:

version: '3.4'
services:
  yarn:
    image: node:14.5
    command: yarn install
  db:
    image: postgres:14.2-alpine
    container_name: demo-postgres-14.2
    volumes:
      - postgres_data:/var/lib/postgresql/data
    command: 
      "postgres -c 'max_connections=500'"
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    ports:
      - "5432:5432"
  demo-web:
    build: .
    command: "./bin/rails server"
    environment:
      - RAILS_ENV=${RAILS_ENV}
      - POSTGRES_HOST=${POSTGRES_HOST}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - RAILS_MASTER_KEY=${RAILS_MASTER_KEY}
    volumes:
      - app-storage:/rails/storage
    depends_on:
      - db
    ports:
      - "3000:3000"

volumes:
  postgres_data: {}
  app-storage: {}
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.