# Rails App build error

**URL:** <https://community.fly.io/t/rails-app-build-error/12611>\
**Category:** General\
**Tags:** login-only\
**Created:** [May 1, 2023, 8:54am UTC](https://community.fly.io/t/rails-app-build-error/12611 "2023-05-01T08:54:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejandrouda](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/alejandrouda/32/13384_2.png) [@alejandrouda](https://community.fly.io/u/alejandrouda)\
**Post date:** [May 1, 2023, 8:54am UTC](https://community.fly.io/t/rails-app-build-error/12611/1 "2023-05-01T08:54:59Z")

</div>

Hi there,

I’m encountering with the following error when trying to deploy my App:

`Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile]: exit code: 1`

I removed my dockerfile and fly.toml and delete the App in [fly.io](http://fly.io). Then I re-launched, but couldn’t solve this problem.

Here’s my Dockerfile:

```auto
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.1.2
FROM ruby:$RUBY_VERSION-slim as base

LABEL fly_launch_runtime="rails"

# Rails app lives here
WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_WITHOUT="development:test" \
    BUNDLE_DEPLOYMENT="1"

# Update gems and bundler
RUN gem update --system --no-document && \
    gem install -N bundler

# Install packages needed to install nodejs
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install Node.js
ARG NODE_VERSION=16.15.1
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    rm -rf /tmp/node-build-master

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential git libpq-dev libvips node-gyp pkg-config python-is-python3

# Install yarn
ARG YARN_VERSION=1.22.19
RUN npm install -g yarn@$YARN_VERSION

# Build options
ENV PATH="/usr/local/node/bin:$PATH"

# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
    bundle exec bootsnap precompile --gemfile && \
    rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git

# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Copy application code
COPY --link . .

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

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile

# Final stage for app image
FROM base

# Install packages needed for deployment
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y imagemagick libvips postgresql-client && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Run and own the application files as a non-root user for security
RUN useradd rails --home /rails --shell /bin/bash
USER rails:rails

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=rails:rails /rails /rails

# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
    RAILS_SERVE_STATIC_FILES="true"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

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

```

Here’s my fly.toml file:

```auto
# fly.toml file generated for restaurant-website on 2023-05-01T10:43:09+02:00

app = "restaurant-website"
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "mad"
processes = []

[env]

[experimental]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 3000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/rails/public"
  url_prefix = "/"

```

Do you know what should I check to solve this issue?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![alejandrouda](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/alejandrouda/32/13384_2.png) [@alejandrouda](https://community.fly.io/u/alejandrouda)\
**Post date:** [May 1, 2023, 11:46am UTC](https://community.fly.io/t/rails-app-build-error/12611/4 "2023-05-01T11:46:11Z")

</div>

Hi PabloC, thanks for your help! Tried that command and got the same error:

```auto
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY bundle exec rails assets:precompile]: exit code: 1

```

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [May 1, 2023, 2:19pm UTC](https://community.fly.io/t/rails-app-build-error/12611/5 "2023-05-01T14:19:03Z")

</div>

There is likely more information available in the [logs](https://fly.io/docs/rails/getting-started/existing/#view-log-files).

The most common reason why assets:precompile may fail on a build machine is that one of your config files accesses a secret, something that often can be easily avoided by the [addition of an if statement](https://community.fly.io/t/error-build-9-9-run-secret-key-base-dummy-bin-rails-assets-precompile-when-running-fly-deploy/11657/4).

---

<div class="post-metadata">

**Author:** ![alejandrouda](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/alejandrouda/32/13384_2.png) [@alejandrouda](https://community.fly.io/u/alejandrouda)\
**Post date:** [May 1, 2023, 4:31pm UTC](https://community.fly.io/t/rails-app-build-error/12611/6 "2023-05-01T16:31:13Z")

</div>

Hi Rubys, thanks for looking at this!

I tried checking the logs but it seems that the App hasn’t been deployed yet, and logs remains empty

 ![Screenshot 2023-05-01 181346](https://global.discourse-cdn.com/fly1/original/3X/5/b/5be100a87bbfaf426ecd042dbcc65b71b03331da.png)

I checked my config files and the only thing I found accessing secrets is this block:

```auto
local:
  service: Disk
  public: true
  root: <%= ENV.fetch('RAILS_STORAGE', Rails.root.join("storage")) %>

```

I commented this out and still got the same error. Do you know what else could I check?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![rubys](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/rubys/32/16907_2.png) [@rubys](https://community.fly.io/u/rubys)\
**Post date:** [May 1, 2023, 4:38pm UTC](https://community.fly.io/t/rails-app-build-error/12611/7 "2023-05-01T16:38:19Z")

</div>

> [@alejandrouda](#):
>
> `Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c SECRET_KEY_BASE=DUMMY bundle exec rails assets:precompile]: exit code: 1`

Is there a stack traceback before this line? If you scroll back, you should see something like the following, and immediately following it will be the error that you need to address:

```auto
 => ERROR [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precom 1.4s
------                                                                          
 > [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:         
#18 1.355 rails aborted!

```

---

<div class="post-metadata">

**Author:** ![alejandrouda](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/alejandrouda/32/13384_2.png) [@alejandrouda](https://community.fly.io/u/alejandrouda)\
**Post date:** [May 2, 2023, 2:01pm UTC](https://community.fly.io/t/rails-app-build-error/12611/8 "2023-05-02T14:01:47Z")

</div>

Thanks for helping me to go on the right direction Rubys! I could find the error which is the same as described here: [Function rgb is missing argument $green. · tailwindlabs/tailwindcss · Discussion #6738 · GitHub](https://github.com/tailwindlabs/tailwindcss/discussions/6738)

The solution posted there worked for me. Thanks again! 🙏

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [May 9, 2023, 2:02pm UTC](https://community.fly.io/t/rails-app-build-error/12611/9 "2023-05-09T14:02:18Z")

</div>

Closed on May 9, 2023, 2:02pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
