Can't deploy after upgrading to v2 - ERROR [stage-3 7/7] RUN bin/rails fly:build

Hi all

It’s been quite a while since I deployed, and after updating to v2, I can’t deploy. Everything goes fine until it’s time for fly:build

 => ERROR [stage-3 7/7] RUN bin/rails fly:build                            2.0s
------
 > [stage-3 7/7] RUN bin/rails fly:build:
#0 1.941 rails aborted!
#0 1.941 Don't know how to build task 'fly:build' (See the list of available tasks with `rails --tasks`)
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task_manager.rb:59:in `[]'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:159:in `invoke_task'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
rake/rake_command.rb:24:in `block (2 levels) in perform'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands/rake/rake_command.rb:18:in `perform'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/command.rb:51:in `invoke'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/railties-7.0.2.3/lib/rails/commands.rb:18:in `<main>'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
#0 1.941 /app/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
#0 1.941 (See full trace by running task with --trace)
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/bash -o pipefail -c ${BUILD_COMMAND}]: exit code: 1

Fly.toml:

# fly.toml app configuration file generated for <app> on 2023-08-20T10:50:34-05:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "app"
primary_region = "ewr"
kill_signal = "SIGINT"
kill_timeout = "5s"

[experimental]
  auto_rollback = true

[build]
  [build.args]
    BUILD_COMMAND = "bin/rails fly:build"
    SERVER_COMMAND = "bin/rails fly:server"

[deploy]
  release_command = "bin/rails fly:release"

[env]
  PORT = "8080"

[[services]]
  protocol = "tcp"
  internal_port = 8080
  processes = ["app"]

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

  [[services.ports]]
    port = 443
    handlers = ["tls", "http"]
  [services.concurrency]
    type = "connections"
    hard_limit = 25
    soft_limit = 20

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

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

Dockerfile:

# syntax = docker/dockerfile:experimental

# Dockerfile used to build a deployable image for a Rails application.
# Adjust as required.
#
# Common adjustments you may need to make over time:
#  * Modify version numbers for Ruby, Bundler, and other products.
#  * Add library packages needed at build time for your gems, node modules.
#  * Add deployment packages needed by your application
#  * Add (often fake) secrets needed to compile your assets

#######################################################################

# Learn more about the chosen Ruby stack, Fullstaq Ruby, here:
#   https://github.com/evilmartians/fullstaq-ruby-docker.
#
# We recommend using the highest patch level for better security and
# performance.

ARG RUBY_VERSION=3.0.2
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

LABEL fly_launch_runtime="rails"

ARG BUNDLER_VERSION=2.2.31

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

#######################################################################

# install packages only needed at build time

FROM base as build_deps

ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV BUILD_PACKAGES ${BUILD_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 ${BUILD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

#######################################################################

# install gems

FROM build_deps as gems

RUN gem update --system --no-document && \
    gem install -N bundler -v ${BUNDLER_VERSION}

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

#######################################################################

# install deployment packages

FROM base

ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0 nodejs"
ENV DEPLOY_PACKAGES=${DEPLOY_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 \
    ${DEPLOY_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

# copy installed gems
COPY --from=gems /app /app
COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
COPY --from=gems /usr/local/bundle /usr/local/bundle

#######################################################################

# Deploy your application
COPY . .

# Adjust binstubs to run on Linux and set current working directory
RUN chmod +x /app/bin/* && \
    sed -i 's/ruby.exe/ruby/' /app/bin/* && \
    sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*

# The following enable assets to precompile on the build server.  Adjust
# as necessary.  If no combination works for you, see:
# https://fly.io/docs/rails/getting-started/existing/#access-to-environment-variables-at-build-time
ENV SECRET_KEY_BASE 1
# ENV AWS_ACCESS_KEY_ID=1
# ENV AWS_SECRET_ACCESS_KEY=1

# Run build task defined in lib/tasks/fly.rake
ARG BUILD_COMMAND="bin/rails fly:build"
RUN ${BUILD_COMMAND}

# Default server start instructions.  Generally Overridden by fly.toml.
ENV PORT 8080
ARG SERVER_COMMAND="bin/rails fly:server"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

I’ve tried:

  • adding nodejs to the build args in the Dockerfile
  • changing bin/rails to bin/rake in the Dockerfile & fl.toml file

At this point I couldn’t find any solutions online that actually helped. I’m not above destroying everything and starting over, but as this is just a hobby project I’d like to figure out what to do.

Do you have a lib/tasks/fly.rake? Its contents should look like this:

I moved the rake file from lib/fly.rake to lib/tasks/fly.rake and i got further! Will update this thread if I still get stuck.

I got this error next:

release_command: bin/rails fly:release
Error: release command failed - aborting deployment. error running release_command machine: error creating a release_command machine: failed to launch VM: To create more than 1 machine per app please add a payment method. 

Solved by adding a credit card to my account, I thought i did this already last year.

Then ran into this error

Running <app> release_command: bin/rails fly:release
  Waiting for 7328721ad65385 to get exit event
Error release_command failed running on machine 7328721ad65385 with exit code 1.
Check its logs: here's the last 100 lines below, or run 'fly logs -i 7328721ad65385':
  To create your database, run:
          bin/rails db:create

My db has the status of suspended and i’m not sure how to start it again, or if it’s decoupled from my app how to fix that.

See postgres-db suspended - #4 by shaun for information on how to restart postgres.

You can check to see if your app is connected to your database by running:

fly ssh console -C 'printenv DATABASE_URL'

That exact line didn’t work, but running
fly console then printenv DATABASE_URL gave me postgres://<app>:<id>@top2.nearest.of.<app>-db.internal:5432/<app>

Found the problem! It was some problem with my migrations. In between the 150 or so lines of rails error messages, there was this:

PG::UndefinedColumn: ERROR:  column "<col>" of relation "<model>" does not exist

I removed that migration and i got a successful deploy. Thank you for your help!

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