Fly.io Rails Tutorial

It is great that Fly has a Rails Tutorial.

It would be really great to know, what are the rail parameters used in this tutorial. It would be great to see the github source code for the final result. It would be great to know, that anybody can follow the instructions for an Ubuntu rails application, and things just work in the deployment.

I noticed that in the Chapter 1: From zero to deploy | Ruby on Rails Tutorial | Learn Enough to Be Dangerous for their sample application a specific version of rails with a specific version of bundler is used.

Listing 1.2: Installing Rails with a specific version number.
$ gem install rails -v 7.0.4

Listing 1.3: Installing Bundler with a specific version number.
$ gem install bundler -v 2.3.14

When a new version of fly is released, what ruby application is used to verify that everything still works. It would be really nice if the new version of fly was tested against an existing documented ruby application.

It doesn’t make a lot of sense to send in error reports for others to debug, if the documented ruby applications don’t work.

You probably have a ruby application, that you test against, before deploying new versions of fly.

Please don’t ask me what went wrong, I just want to see what works on a Ubuntu system with rails.

If I sound a little bit upset, that is because I am upset. I had an existing rails application that worked fine for years, and 3 days ago, when I changed a date from 2023 to 2024. The application no longer deployed.

$ flyctl releases
VERSION	STATUS  	DESCRIPTION 	USER                    	DATE              
v7     	failed  	Release     	oserj@oserconsulting.com	19m26s ago       	
v6     	complete	Release     	admin-bot@fly.io        	May 26 2023 07:18	
v5     	pending 	Release     	admin-bot@fly.io        	May 26 2023 07:17	
v4     	complete	Deploy image	oserj@oserconsulting.com	Mar 31 2023 23:39	
v3     	complete	Deploy image	oserj@oserconsulting.com	Mar 27 2023 04:28	
v2     	complete	Deploy image	oserj@oserconsulting.com	Mar 27 2023 02:41	
v1     	complete	Deploy image	oserj@oserconsulting.com	Oct 24 2022 22:13	
v0     	complete	Deploy image	oserj@oserconsulting.com	Sep 18 2022 00:49

So probably many things have changed since Mar 31 2023, but my source rails code, version of gems, etc. has remained the same.

First, by way of introduction, I am a fly.io employee, and the author of Agile Web Development with Rails. I also run a fairly decent sized application here.

I actually would love to know more about what failure you are seeing. Fundamentally, if you are using a Dockerfile deploys should be 100% reproducible. What worked in 2022 should still work in 2024. If you are using a third party builder, things may change from time to time, and we recommend Dockerfiles.

The code that we use to produce Dockerfiles for you is open sourced: GitHub - fly-apps/dockerfile-rails: Provides a Rails generator to produce Dockerfiles and related files.; and has an extensive test suite.

~/src/oserconsulting-only-bootstrap (main) $ fly deploy
==> Verifying app config
Validating /home/oserj/src/oserconsulting-only-bootstrap/fly.toml
✓ Configuration is valid
→ Verified app config
==> Building image
Remote builder fly-builder-crimson-wind-7694 ready
Remote builder fly-builder-crimson-wind-7694 ready
==> Building image with Docker
→ docker host: 24.0.7 linux x86_64
[+] Building 1.2s (18/29)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 2.92kB 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 195B 0.0s
=> resolve image config for docker.io/docker/dockerfile:experimental 0.4s
=> CACHED docker-image://docker.io/docker/dockerfile:experimental@sha256:600e5c62eedff338b3f7a0850beb7c05866e0ef27b2d2e8c02aa468e7 0.0s
=> [internal] load .dockerignore 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load metadata for Quay 0.2s
=> [base 1/6] FROM quay.io/evl.ms/fullstaq-ruby:3.1.2-jemalloc-slim@sha256:6a18708ef1cbc3dfa8c14a1fa3942d8b13c2ed2eebf5caa30e7099b 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 2.46MB 0.2s
=> CACHED [base 2/6] RUN mkdir /app 0.0s
=> CACHED [base 3/6] WORKDIR /app 0.0s
=> CACHED [base 4/6] RUN mkdir -p tmp/pids 0.0s
=> CACHED [base 5/6] RUN curl https://get.volta.sh | bash 0.0s
=> CACHED [base 6/6] RUN volta install node@12.22.9 && volta install yarn 0.0s
=> CACHED [build_deps 1/1] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt --mount=type=cache,id= 0.0s
=> [node_modules 1/3] COPY packagejson ./ 0.0s
=> [node_modules 2/3] COPY yarn.
./ 0.0s
=> ERROR [node_modules 3/3] RUN if [ -f “yarn.lock” ]; then yarn install; elif [ -f “package-lock.json” ]; then npm in 0.3s

[node_modules 3/3] RUN if [ -f “yarn.lock” ]; then yarn install; elif [ -f “package-lock.json” ]; then npm install; else mkdir node_modules; fi:

0.291
0.291 SyntaxError: Unexpected token ‘.’
0.291 at wrapSafe (internal/modules/cjs/loader.js:915:16)
0.291 at Module._compile (internal/modules/cjs/loader.js:963:27)
0.291 at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
0.291 at Module.load (internal/modules/cjs/loader.js:863:32)
0.291 at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0.291 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
0.291 at internal/main/run_main_module.js:17:47

$ cat Dockerfile

syntax = docker/dockerfile:experimental

ARG RUBY_VERSION=2.7.3
ARG VARIANT=jemalloc-slim
FROM Quay as base

ARG NODE_VERSION=16
ARG BUNDLER_VERSION=2.3.9

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 update --system --no-document &&
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 packagejson ./
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”
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
COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
COPY --from=gems /usr/local/bundle /usr/local/bundle

The following enable assets to precompile on the build server. Adjust

as necessary. If no combination works for you, see:

Existing Rails Apps · Fly Docs

ENV SECRET_KEY_BASE 1

ENV AWS_ACCESS_KEY_ID=1

ENV AWS_SECRET_ACCESS_KEY=1

COPY . .

RUN chmod +x /app/bin/* &&
sed -i ‘s/ruby.exe/ruby/’ /app/bin/* &&
sed -i ‘/^#!/aDir.chdir File.expand_path(“…”, dir)’ /app/bin/*

RUN bin/rails fly:build

ENV PORT 8080

ARG SERVER_COMMAND=“bin/rails fly:server”
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

$ cat fly.toml

fly.toml file generated for oserconsulting-only-bootstrap on 2022-09-18T00:46:48Z

app = “oserconsulting-only-bootstrap”
kill_signal = “SIGINT”
kill_timeout = 5
processes =

[build]
[build.args]
BUNDLER_VERSION = “2.3.7”
NODE_VERSION = “12.22.9”
RUBY_VERSION = “3.1.2”

[deploy]
release_command = “bin/rails fly:release”

[env]
PORT = “8080”
SERVER_COMMAND = “bin/rails fly:server”

[experimental]
allowed_public_ports =
auto_rollback = true

[[services]]
http_checks =
internal_port = 8080
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 = “/app/public”
url_prefix = “/”

What’s likely going on here is that Node 16 reached end of life on 2022-04-30, and current versions of yarn now depend on you running a more recent version of node. We had another user with the same error: New error popping up when I to deploy my rails app after making some minor text changes - #7 by mchilson

The fix that worked for them was to update the Node version used. It may also be possible to specify that you want an older version of yarn.

Hi Sam Ruby @rubys

Thank you very much for your help.

Yes. It is the identical situation
New error popping up when I to deploy my rails app after making some minor text changes - #7 by mchilson

I looked at his post but I don’t understand what to do.

I am suppose to
fly apps destroy
then what’s next.
What do I
fly launch (with something changed)
Do I
fly deploy (with something changed)

Do I modify
Dockerfile
fly.toml

Everything is working fine when I do
rails server -b 0.0.0.0

I am a refugee from Heroku.
I did the original black magic to get everything working in September 2023.
I don’t know how to use Dockerfiles.

In parallel to doing my own website, I am going through your rails tutorial.

I didn’t notice this line before:

Start by verifying that you have Rails version 7 installed.

It doesn’t say what version of rails 7 or what version of ruby.

You seemed surprised in other posts that people were having trouble with the tutorial.

I finally got a basic rails program up and running with:

rails 7.1.3.4
ruby 3.2.2

I think this forum system should leave posts open for more than 1 week.

There really needs to one place to always discuss the rails tutorial.

I also see that several people have asked why they can’t use twice their application name.

The rails tutorial says to use the name “list”, however if things don’t work, the command line tool asks me to go to a web interface to continue, which other people have complained about it.

It is unclear when one needs to run:
fly apps destroy

So many questions. Maybe you can hire some college students to do a FAQ about the rails tutorial, so all the answers are in the same place.

Also I see there are some posts of the internet that say that rake has changed, and therefore the ruby version needs to change.

If you haven’t yet, don’t destroy your app.

What result to you get when you run node -v on your machine?

Can you modify the line in fly.toml to match?

NODE_VERSION = “12.22.9”

Then run fly deploy?

Now it looks like a completely different problem.

2024-06-18T00:35:32.997 proxy[148e2d12c07018] dfw [error] [PM05] failed to connect to machine: gave up after 15 attempts (in 22.345607309s)

2024-06-18T00:35:35.093 proxy[148e2d12c07018] dfw [info] Starting machine

2024-06-18T00:35:35.167 app[148e2d12c07018] dfw [info] 2024-06-18T00:35:35.166793848 [01J0MC2XX82ACX2WCS4GKSJ6EE:main] Running Firecracker v1.7.0

2024-06-18T00:35:35.269 app[148e2d12c07018] dfw [info] [ 0.045586] PCI: Fatal: No config space access function found

2024-06-18T00:35:35.532 app[148e2d12c07018] dfw [info] INFO Starting init (commit: f7402432)…

2024-06-18T00:35:35.548 app[148e2d12c07018] dfw [info] INFO Mounting /dev/vdb at /data w/ uid: 1000, gid: 1000 and chmod 0755

2024-06-18T00:35:35.550 app[148e2d12c07018] dfw [info] INFO Resized /data to 1056964608 bytes

2024-06-18T00:35:35.550 app[148e2d12c07018] dfw [info] INFO Preparing to run: /rails/bin/docker-entrypoint ./bin/rails server as 1000

2024-06-18T00:35:35.556 app[148e2d12c07018] dfw [info] INFO [fly api proxy] listening at /.fly/api

2024-06-18T00:35:35.562 app[148e2d12c07018] dfw [info] 2024/06/18 00:35:35 INFO SSH listening listen_address=[fdaa:0:9bc1:a7b:6b:d33b:aad8:2]:22 dns_server=[fdaa::3]:53

2024-06-18T00:35:35.581 runner[148e2d12c07018] dfw [info] Machine started in 485ms

2024-06-18T00:35:35.582 proxy[148e2d12c07018] dfw [info] machine started in 488.643933ms

2024-06-18T00:35:36.618 app[148e2d12c07018] dfw [info] rails aborted!

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] LoadError: cannot load such file – /rails/lib/tasks/fly.rake (LoadError)

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/engine.rb:661:in `load’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/engine.rb:661:in `block in run_tasks_blocks’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/engine.rb:661:in `each’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/engine.rb:661:in `run_tasks_blocks’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/application.rb:501:in `run_tasks_blocks’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/engine.rb:464:in `load_tasks’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /rails/Rakefile:6:in `’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/commands/rake/rake_command.rb:20:in `block in perform’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/commands/rake/rake_command.rb:18:in `perform’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/command.rb:51:in `invoke’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/railties-7.0.8.4/lib/rails/commands.rb:18:in `’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:37:in `require’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] internal:/usr/local/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb:37:in `require’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] /usr/local/bundle/ruby/3.2.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] ./bin/rails:4:in `’

2024-06-18T00:35:36.635 app[148e2d12c07018] dfw [info] (See full trace by running task with --trace)

2024-06-18T00:35:37.560 app[148e2d12c07018] dfw [info] INFO Main child exited normally with code: 1

2024-06-18T00:35:37.572 app[148e2d12c07018] dfw [info] INFO Starting clean up.

2024-06-18T00:35:37.588 app[148e2d12c07018] dfw [info] INFO Umounting /dev/vdb from /data

2024-06-18T00:35:37.588 app[148e2d12c07018] dfw [info] [ 2.362470] reboot: Restarting system

@rubys

Ok. I am up and running, even with SSL
https://www.oserconsulting.com
https://oserconsulting.com
https://jholist.fly.dev

However, there are some gotchas:
I originally was trying to get running
rails 7.0.4 with ruby 3.1.2

https://jimoser.fly.dev

This or something very close to this, was running for months without problems on fly until I tried to make a text change, and things blew up.

I am now running

https://jholist.fly.dev](https://jholist.fly.dev/
with ruby 3.2.2

with a big gotcha to get bootstrap 5 working with dropdown menus.
This is the big gotcha.

Huge kludge to get dropdowns to work in bootstrap.
 <body>
<!--
  https://stackoverflow.com/questions/70907799/bootstrap-5-javascript-functions-not-working-in-rails-7-app
-->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  <%= render 'layouts/navbar' %>

In other news, I did find on my computer, your 2013 book, Agile Web Development with Rails 4.

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