Rails app is running but page not loading

As per title, deployment runs successfully and dashboard shows that everything is ok, but when trying to load the page nothing shows up.

Here’s the link to the deployed app.

This is the result of fly doctor:

Testing authentication token... PASSED
Testing flyctl agent... PASSED
Testing local Docker instance... Nope
Pinging WireGuard gateway (give us a sec)... PASSED
Testing WireGuard DNS... PASSED
Testing WireGuard Flaps... PASSED

App specific checks for metrak:
Checking that app has ip addresses allocated... PASSED
Checking A record for metrak.fly.dev... PASSED
Checking AAAA record for metrak.fly.dev... PASSED

Build checks for metrak:
Checking docker context size (this may take little bit)... PASSED (47 kB)
Checking for .dockerignore... PASSED

While you can find the fly logs at this link.

Cannot find module ‘flowbite/plugin’

Can you post your package.json?

I’m assuming it should be in root, but apparently it isn’t.
Should I run npm init?

Apologies, but I’m new to Rails, and this is the first time ever trying to deploy a Rails app.
I should’ve mentioned in the original post probably.

No, don’t run npm init.

Do you perhaps have a tailwind.config.js? Or other file that references flowbite/plugin?

Here’s the theory: what appears to be going on here is that there are two types of Rails applications: those that make use of node, and those that don’t. Your app started out as one of the latter, but now depends on node, but that’s OK on your machine because you have node installed.

If that theory is correct, we may need to modify your Dockerfile to install node just for the duration of the build step, then install the necessary plugins, then run assets:precompile. I can talk you through that process.

Yep, I think your theory is correct.
I have Tailwind and Flowbite installed. And tailwind.config.js in the config directory and flowbite referenced a couple of times and some JS here and there.

So, I guess your solution sounds like the right way to go, and it would be great if you could guide me through that. Thank you very much.

This may not work right the first time, but it should be close.

First, run node -v on your machine. That will tell you the version of node you are running.

Next, look at your Dockerfile, and try to find lines that look like the following:

It is OK if these lines don’t exactly match, for example, they may not have --link.

Immediately before those lines (in other words, before the ‘COPY’ line), add the following:

Replace xxx with your node version you identified above, but WITHOUT the leading v.

Finally, add the following line after the ones you just inserted but before the copy:

RUN npm install -g flowbite

If you have multiple plugins, you may need to repeat that line.

Give that a try.

If, perchance, your Dockerfile doesn’t look anything like this, I may ask you to generate a new one and try again using these instructions: GitHub - fly-apps/dockerfile-rails: Provides a Rails generator to produce Dockerfiles and related files.

Currently, those lines in the Dockerfile looks like this:

# Copy application code
COPY --link . .

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

It might be due to the fact that I’ve already run bin/rails generate dockerfile --precompile=defer ?

Before that (I haven’t pushed local changes yet) they looked like this:

# Copy application code
COPY . .

# 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=1 ./bin/rails assets:precompile

Wondering if I should proceed as you suggested anyway?

Moreover,

Flowbite needs Tailwind to work as well. Does it mean I should npm i that first?

Yes, before that COPY statement would be where you insert your changes.

Add as many npm i statements as you need. It won’t hurt if you install too much. If you miss something, you will see what you need to install next in your logs.

I tried with both my current node versione (22.0.0) and the one recommended on the official website (20.14.0).
Either way, fly deploy exits with this error:

Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c 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" did not complete successfully: exit code: 2

Full log here.

Try creating a file named Docker.test with the following contents:

# syntax = docker/dockerfile:1

ARG RUBY_VERSION=3.3.1
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim

RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl

# Install Node.js
ARG NODE_VERSION=22.0.0
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

And then run the following command:

fly console --dockerfile Dockerfile.test -C bash

You should be able to get that to work, iterate quickly to add what you need, and once done you can transplant the necessary lines to your Dockerfile.

I’m not sure what you’re asking me to do here and what that command does.
Can you elaborate on that?

However, you made me realise that I was missing curl from my Dockerfile, which I added, and that let deployment complete.
However, as per original post, even though the app is saying it’s deployed, it still doesn’t load and in the logs I can see the same errors.

Just to verify, your current Dockerfile only has one FROM line?

If you have installed node and from there installed flowbite you should, at the very least, get a different error message. If you haven’t tried it yet, make sure you try specifying -gor --global on the install.

Both fly ssh console and fly console are handy commands to get to know. The first will create a secure shell into your running instance. The second will create an ephemeral machine that lasts until you exit the shell. You can override the Dockerfile and command to be run on each.

Both are great for exploring… you can run commands interactively and see the results. Once you find a sequence of commands that do what you need, modify your Dockerfile and redeploy.

Yes, there is only one FROM and I’m using the -g flag.

One thing I remembered is that, to complete the Flowbite installation, there is loads of stuff that needs to be input manually, as you can see here.

Could that be the problem?
If so, is it fixable?

UPDATE: Could this be the solution for me as well?

At this point, we are past the edge of my expertise. I know a lot about Rails, Docker, and Fly.io; but literally nothing about Flowbite.

But I will say that the following Dockerfile works for me (create it as Dockerfile.test and follow the instructions above:

# syntax = docker/dockerfile:1

ARG RUBY_VERSION=3.3.1
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim

RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl

# Install Node.js
ARG NODE_VERSION=22.0.0
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

WORKDIR /rails

RUN npm install tailwindcss flowbite

COPY <<EOF tailwind.config.js
module.exports = {
    plugins: [
        require('flowbite/plugin')
    ]
}
EOF

RUN node tailwind.config.js

It did not work, but at least the error has changed:

2024-05-31T06:48:44Z runner[9185e647c107d8] ams [info]Machine started in 553ms
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info][Error: EACCES: permission denied, open '/rails/app/assets/builds/tailwind.css'] {
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]  errno: -13,
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]  code: 'EACCES',
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]  syscall: 'open',
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]  path: '/rails/app/assets/builds/tailwind.css'
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]}
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]bin/rails aborted!
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]Command failed with exit 1: /usr/local/bundle/ruby/3.3.0/gems/tailwindcss-rails-2.5.0-x86_64-linux/exe/x86_64-linux/tailwindcss
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info]Tasks: TOP => assets:precompile => tailwindcss:build
2024-05-31T06:48:44Z app[e824121a7511e8] bos [info](See full trace by running task with --trace)
2024-05-31T06:48:45Z app[e824121a7511e8] bos [info] INFO Main child exited normally with code: 1
2024-05-31T06:48:45Z app[e824121a7511e8] bos [info] INFO Starting clean up.
2024-05-31T06:48:45Z app[e824121a7511e8] bos [info] INFO Umounting /dev/vdc from /data
2024-05-31T06:48:45Z app[e824121a7511e8] bos [info] WARN could not unmount /rootfs: EINVAL: Invalid argument
2024-05-31T06:48:45Z app[e824121a7511e8] bos [info][    6.391956] reboot: Restarting system

If you don’t have any more advice, can you just help me understand what this person did, so I can try to replicate it?
If also that doesn’t work, I might just remove Flowbite altogether.

Thank you very much and apologies for taking so much of your time. I truly appreciate your support.

It looks like you are real close now. In your Dockerfile you likely have a line that looks like:

chown -R rails:rails db log storage tmp

These are the list of directories that your application is allowed to write to. Try adding assets to this list?

You can also remove the entire section that starts with the following comment:

# Run and own only the runtime files as a non-root user for security

Adding app/assets or public give similar results. If I add app, the machines just don’t start. assets by itself is not found as a directory.

When I do this:

The app is actually deploy and the URL loads.
However, it doesn’t seem to access the database, so all the files I created, as well as the user to login, are not there.

I thought that Rails had a built-in db, did I get that wrong?

I’ve tried to implement the code from this cookbook on a separate branch, but was unsuccessful. :cry:

Rails doesn’t have a built-in db, but rails can create and update dbs on the machine it is running on.

At the moment, you likely are using either a sqlite3 or postgresql db. If you don’t know which, it probably is sqlite3. On your machine the db is in the db directory. On the fly machine it is in the /data directory. You likely are running in development mode on your machine and in production on fly, so the names of the dbs may be different.

You can use fly ssh sftp shell · Fly Docs to transfer files.

The command you would likely use would be something like:

put db/development.sqlite3 /data/production.sqlite3
1 Like

Thank you for clarifying that.

And, yes, I’m using sqlite3.

Your command work, although I had to take development.sqlite3 from storage rather than data, and had to delete /data/production.sqlite3 using fly ssh console because the put command wouldn’t overwrite the file.

There are still some issues in the CSS rendering, but I feel like I can deal with this by myself now.
The app is deployed and fully functional.

Thank you very much for your help and patience. I truly appreciate it. :heart: :people_hugging: