First time rails launch produces an error

I am using latest ruby with latest rails in a docker container for development. I have a dockerfile for the production environment.

I had been using sqlite3 for development and testing. It was working fine for “production” on render.com However, I just migrated to postgresql to be able to deploy on fly.io The new database adapter is working for development and testing. I did not test “production” since I am going to try that in fly.io

I installed the fly CLI in my docker container. Here is my attempt at launching:

...
==> Monitoring health checks
  Waiting for 908061d4a16568 to become healthy (started, 3/3)
...
Failed attaching tabs to the Postgres cluster tabs-db: can't establish agent agent: failed to start.
Try attaching manually with 'fly postgres attach --app tabs tabs-db'
Error creating Postgres database. Be warned that this may affect deploys
Error creating Postgres cluster: can't establish agent agent: failed to start
...
Your Rails app is prepared for deployment.

Before proceeding, please review the posted Rails FAQ:
https://fly.io/docs/rails/getting-started/dockerfiles/.

Once ready: run 'fly deploy' to deploy your Rails app.

So I tried the command to connect the db – even though I don’t know what I’m doing tbh:

root@2c2ec6d2bfc6:~# fly postgres attach --app tabs tabs-db
Error: can't establish agent agent: failed to start
The agent failed to start with the following error log:

2023/12/15 21:09:47.827984 srv failed removing existing socket: lstat /root/.fly/fly-agent.sock: invalid argument


A copy of this log has been saved at /root/.fly/agent-logs/2708186817.log

root@2c2ec6d2bfc6:~# cat /root/.fly/agent-logs/2708186817.log 
2023/12/15 21:09:47.827984 srv failed removing existing socket: lstat /root/.fly/fly-agent.sock: invalid argument

And a similar issue when deploying:

root@2c2ec6d2bfc6:~# fly deploy
==> Verifying app config
Validating /root/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
WARN Failed to start remote builder heartbeat: failed building options: agent: failed to start

Error: failed to fetch an image or build from source: error connecting to docker: failed building options: agent: failed to start
The agent failed to start with the following error log:

2023/12/15 21:20:08.669645 srv failed removing existing socket: lstat /root/.fly/fly-agent.sock: invalid argument


A copy of this log has been saved at /root/.fly/agent-logs/573799191.log

I am not sure what I am doing wrong.

Okay… Looks like some bad cache was the issue.

I removed my /root/.fly/ directory. Reinstalled the CLI. And viola, it can connect the db.

Wait that fixed the db issue. But now I have another issue:

root@3b8d4e0360a0:~# fly deploy
==> Verifying app config
Validating /root/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-aged-river-8565 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 3.3s (9/21)                                                                                                                                                          
[+] Building 3.3s (9/21)                                                                                                                                                          
 => [internal] load build definition from Dockerfile                                                                                                                         0.1s
 => => transferring dockerfile: 2.08kB                                                                                                                                       0.1s
 => [internal] load .dockerignore                                                                                                                                            0.1s
 => => transferring context: 782B                                                                                                                                            0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                                   0.6s
 => docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021                                                     0.4s
 => => resolve docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021                                                         0.0s
 => => sha256:657fcc512c7369f4cb3d94ea329150f8daf626bc838b1a1e81f1834c73ecc77e 482B / 482B                                                                                   0.0s
 => => sha256:a17ee7fff8f5e97b974f5b48f51647d2cf28d543f2aa6c11aaa0ea431b44bb89 1.27kB / 1.27kB                                                                               0.0s
 => => sha256:9d9c93f4b00be908ab694a4df732570bced3b8a96b7515d70ff93402179ad232 11.80MB / 11.80MB                                                                             0.2s
 => => sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021 8.40kB / 8.40kB                                                                               0.0s
 => => extracting sha256:9d9c93f4b00be908ab694a4df732570bced3b8a96b7515d70ff93402179ad232                                                                                    0.2s
 => [internal] load build definition from Dockerfile                                                                                                                         0.0s
 => [internal] load metadata for docker.io/library/ruby:3.2.2-slim                                                                                                           0.3s
 => [internal] load .dockerignore                                                                                                                                            0.0s
 => ERROR [internal] load build context                                                                                                                                      1.6s
 => => transferring context: 2.36MB                                                                                                                                          1.6s
 => CANCELED [base 1/3] FROM docker.io/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8                                       1.6s
 => => resolve docker.io/library/ruby:3.2.2-slim@sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8                                                     0.0s
 => => sha256:032f78a9a8d56c57bc1daf27956c8bac0c9a0bdb7d7934d0068a10982453a304 13.85MB / 13.85MB                                                                             0.8s
 => => sha256:49e36bd6cba5164fde3c6284b9dddded584fe2a620d97d5b24e73828ad634939 199B / 199B                                                                                   0.2s
 => => sha256:f40145a670baf0cc52d80de4bc9005aec39cdd63e69950fbbe1a8b035e8598d9 34.99MB / 34.99MB                                                                             1.1s
 => => sha256:4aeff82d459c24d05fa0a7a412b10b63091d632a8191a2738ad8adbad5857e65 177B / 177B                                                                                   0.1s
 => => sha256:14eba677236d3360f2b66595c7fa0f2440ed6e33c519befe4d11c1242a8815a8 1.86kB / 1.86kB                                                                               0.0s
 => => sha256:b3361922e505b782dee096a84b33b715b7d0c53c20f929973613c47d26835dea 1.37kB / 1.37kB                                                                               0.0s
 => => sha256:3854ecbc02a168ab727d2f841ab519c3bc4facd4ee98a35c07a84eb9c10e8eb7 6.99kB / 6.99kB                                                                               0.0s
 => => sha256:1f7ce2fa46ab3942feabee654933948821303a5a821789dddab2d8c3df59e227 29.15MB / 29.15MB                                                                             0.6s
 => => extracting sha256:1f7ce2fa46ab3942feabee654933948821303a5a821789dddab2d8c3df59e227                                                                                    1.1s
------
 > [internal] load build context:
------
Error: failed to fetch an image or build from source: error building: failed to solve: error from sender: lstat /root/.fly/fly-agent.sock: invalid argument

That looks like the directory you deleted. Something is confused. It often is easier to delete the builder rather than try to clean things up:

fly apps destroy fly-builder-aged-river-8565

It is perfectly safe to delete a builder, the next time you deploy another one will be created for you.

Oh, that would have been nice to know. Haha, I was manually deleting the CLI folder and each app in fly.io UI :dizzy_face:

I seem to have fixed the issue.

My docker compose used to be:

  app:
    image: ruby:latest
    command: ./bin/rails server -b 0.0.0.0
    environment:
      DATABASE_HOST: db
      DATABASE_PASSWORD: password
    ports:
      - "3000:3000"
    volumes:
      - .:/root
      - bundle-cache:/usr/local/bundle
    working_dir: "/root"

Placing the project directory directly into the home folder was causing some weird loop in the fly CLI – since the CLI installs itself in the home folder (I would recommend installing 3rd party software somewhere outside the home folder). So I nested it:

  app:
    image: ruby:latest
    command: ./bin/rails server -b 0.0.0.0
    environment:
      DATABASE_HOST: db
      DATABASE_PASSWORD: password
    ports:
      - "3000:3000"
    volumes:
      - .:/root/tabs
      - bundle-cache:/usr/local/bundle
    working_dir: "/root/tabs"

But I got an easy error to fix which was surprising:

This deployment will:
 * create 2 "app" machines

No machines in group app, launching a new machine

-------
 ✖ Failed: error creating a new machine: failed to launch VM: To create more than 1 machine per app please add a payment method. https://fly.io/dashboard/…
-------
Error: error creating a new machine: failed to launch VM: To create more than 1 machine per app please add a payment method. https://fly.io/dashboard/.../billing
Please note that release commands run in their own ephemeral machine, and therefore count towards the machine limit. (Request ID: 01HHQTH11QK872PR78BNB3G835-lax)
root@1d4128c70c68:~/tabs# 

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