basecamp / kamal

Deploy web apps anywhere.
https://kamal-deploy.org
MIT License
10.51k stars 398 forks source link

Vanilla Rails 7.1 app fails to deploy with Kamal. #834

Closed sergiotapia closed 3 months ago

sergiotapia commented 3 months ago

Hi, exploring using Kamal and moving away from PaaS and stuck on this last bit.

My deploy.yml:

# Name of your application. Used to uniquely configure containers.
service: senti

# Name of the container image.
image: sergiotapia1/senti

# Deploy to these servers.
servers:
  - 5.161.246.176

# Credentials for your image host.
registry:
  # Specify the registry server, if you're not using Docker Hub
  # server: registry.digitalocean.com / ghcr.io / ...
  username: sergiotapia1

  # Always use an access token rather than real password when possible.
  password:
    - KAMAL_REGISTRY_PASSWORD

# Inject ENV variables into containers (secrets come from .env).
# Remember to run `kamal env push` after making changes!
env:
  clear:
    DB_HOST: 192.168.0.2
  secret:
    - RAILS_MASTER_KEY
    - POSTGRES_PASSWORD

# Use a different ssh user than root
# ssh:
#   user: app

# Configure builder setup.
builder:
  args:
    RUBY_VERSION: 3.3.1
    SECRET_KEY_BASE_DUMMY: 1
#   secrets:
#     - GITHUB_TOKEN
#   remote:
#     arch: amd64
#     host: ssh://app@192.168.0.1

# Use accessory services (secrets come from .env).
accessories:
  db:
    image: postgres:15
    host: 5.161.246.176
    port: 5432
    env:
      clear:
        POSTGRES_USER: "kamal_pg"
        POSTGRES_DB: "kamal_pg_production"
      secret:
        - POSTGRES_PASSWORD
    files:
      - db/production.sql:/docker-entrypoint-initdb.d/setup.sql
    directories:
      - data:/var/lib/postgresql/data
#   redis:
#     image: redis:7.0
#     host: 192.168.0.2
#     port: 6379
#     directories:
#       - data:/data

# Configure custom arguments for Traefik. Be sure to reboot traefik when you modify it.
# traefik:
#   args:
#     accesslog: true
#     accesslog.format: json

# Configure a custom healthcheck (default is /up on port 3000)
# healthcheck:
#   path: /healthz
#   port: 4000

# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
# hitting 404 on in-flight requests. Combines all files from new and old
# version inside the asset_path.
#
# If your app is using the Sprockets gem, ensure it sets `config.assets.manifest`.
# See https://github.com/basecamp/kamal/issues/626 for details
#
# asset_path: /rails/public/assets

# Configure rolling deploys by setting a wait time between batches of restarts.
# boot:
#   limit: 10 # Can also specify as a percentage of total hosts, such as "25%"
#   wait: 2

# Configure the role used to determine the primary_host. This host takes
# deploy locks, runs health checks during the deploy, and follow logs, etc.
#
# Caution: there's no support for role renaming yet, so be careful to cleanup
#          the previous role on the deployed hosts.
# primary_role: web

# Controls if we abort when see a role with no hosts. Disabling this may be
# useful for more complex deploy configurations.
#
# allow_empty_roles: false

And here's my .env

KAMAL_REGISTRY_PASSWORD=dckr_pat_m123123123
RAILS_MASTER_KEY=78bdfcd9911273cef4544b86b0f770b0
POSTGRES_PASSWORD=123123123123

I can successfully do a kamal env push. That finishes with no errors.

The problem is after doing a kamal deploy, the rails app container doesn't get healthy so it fails to deploy.

The app container doesn't start, can't see logs to see what's wrong.

Logs:

NFO [139b1b75] Finished in 0.253 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [427d64c8] Running docker container start traefik || docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log-opt max-size="10m" --label traefik.http.routers.catchall.entryPoints="http" --label traefik.http.routers.catchall.rule="PathPrefix(\`/\`)" -│
│-label traefik.http.routers.catchall.service="unavailable" --label traefik.http.routers.catchall.priority="1" --label traefik.http.services.unavailable.loadbalancer.server.port="0" traefik:v2.10 --providers.docker --log.level="DEBUG" on 5.161.246.176                                                                                                                             │
│  INFO [427d64c8] Finished in 0.187 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│Detect stale containers...                                                                                                                                                                                                                                                                                                                                                             │
│  INFO [7e55ac44] Running docker ps --filter label=service=senti --filter label=role=web --format "{{.Names}}" | while read line; do echo ${line#senti-web-}; done on 5.161.246.176                                                                                                                                                                                                    │
│  INFO [7e55ac44] Finished in 0.185 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [5ecb53f4] Running /usr/bin/env sh -c 'docker ps --latest --format '\''{{.Names}}'\'' --filter label=service=senti --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=sergiotapia1/senti:latest --format '\''{{.ID}}'\'') ; docker ps --latest --format '\''{{.Names}}'\'' --filter label=service│
│=senti --filter label=role=web --filter status=running --filter status=restarting' | head -1 | while read line; do echo ${line#senti-web-}; done on 5.161.246.176                                                                                                                                                                                                                      │
│  INFO [5ecb53f4] Finished in 0.246 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│Start container with version 1f8b5a9fd214d92956810d0072d21919dd2cba40 using a 7s readiness delay (or reboot if already running)...                                                                                                                                                                                                                                                     │
│  INFO [f8daf9e5] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet on 5.161.246.176                                                                                                                                                                                                                                        │
│  INFO [f8daf9e5] Finished in 0.183 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO Renaming container 1f8b5a9fd214d92956810d0072d21919dd2cba40 to 1f8b5a9fd214d92956810d0072d21919dd2cba40_replaced_fdc08787b4fb488b as already deployed on 5.161.246.176                                                                                                                                                                                                          │
│  INFO [23f18eb5] Running docker rename senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40 senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40_replaced_fdc08787b4fb488b on 5.161.246.176                                                                                                                                                                                               │
│  INFO [23f18eb5] Finished in 0.187 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [59c617c5] Running /usr/bin/env sh -c 'docker ps --latest --format '\''{{.Names}}'\'' --filter label=service=senti --filter label=role=web --filter status=running --filter status=restarting --filter ancestor=$(docker image ls --filter reference=sergiotapia1/senti:latest --format '\''{{.ID}}'\'') ; docker ps --latest --format '\''{{.Names}}'\'' --filter label=service│
│=senti --filter label=role=web --filter status=running --filter status=restarting' | head -1 | while read line; do echo ${line#senti-web-}; done on 5.161.246.176                                                                                                                                                                                                                      │
│  INFO [59c617c5] Finished in 0.218 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [76586795] Running /usr/bin/env mkdir -p .kamal/cords/senti-web-ef8d06aa231c4260b3d57c79e90e41a9 ; touch .kamal/cords/senti-web-ef8d06aa231c4260b3d57c79e90e41a9/cord on 5.161.246.176                                                                                                                                                                                          │
│  INFO [76586795] Finished in 0.171 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [f0e76d5f] Running docker run --detach --restart unless-stopped --name senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40 --hostname 5.161.246.176-9426340a5771 -e KAMAL_CONTAINER_NAME="senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40" -e KAMAL_VERSION="1f8b5a9fd214d92956810d0072d21919dd2cba40" --env-file .kamal/env/roles/senti-web.env --env DB_HOST="192.168.0.2" -│
│-health-cmd "(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)" --health-interval "1s" --volume $(pwd)/.kamal/cords/senti-web-ef8d06aa231c4260b3d57c79e90e41a9:/tmp/kamal-cord --log-opt max-size="10m" --label service="senti" --label role="web" --label destination --label traefik.http.services.senti-web.loadbalancer.server.sche│
│me="http" --label traefik.http.routers.senti-web.rule="PathPrefix(\`/\`)" --label traefik.http.routers.senti-web.priority="2" --label traefik.http.middlewares.senti-web-retry.retry.attempts="5" --label traefik.http.middlewares.senti-web-retry.retry.initialinterval="500ms" --label traefik.http.routers.senti-web.middlewares="senti-web-retry@docker" sergiotapia1/senti:1f8b5a9│
│fd214d92956810d0072d21919dd2cba40 on 5.161.246.176                                                                                                                                                                                                                                                                                                                                     │
│  INFO [f0e76d5f] Finished in 0.373 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [1e5ef9e1] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [1e5ef9e1] Finished in 0.209 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (starting), retrying in 1s (attempt 1/7)...                                                                                                                                                                                                                                                                                                                 │
│  INFO [a0292677] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [a0292677] Finished in 0.121 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (starting), retrying in 2s (attempt 2/7)...                                                                                                                                                                                                                                                                                                                 │
│  INFO [316a092e] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [316a092e] Finished in 0.129 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (unhealthy), retrying in 3s (attempt 3/7)...                                                                                                                                                                                                                                                                                                                │
│  INFO [0db810e1] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [0db810e1] Finished in 0.122 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (unhealthy), retrying in 4s (attempt 4/7)...                                                                                                                                                                                                                                                                                                                │
│  INFO [0a2bc157] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [0a2bc157] Finished in 0.128 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (unhealthy), retrying in 5s (attempt 5/7)...                                                                                                                                                                                                                                                                                                                │
│  INFO [56135351] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [56135351] Finished in 0.124 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (unhealthy), retrying in 6s (attempt 6/7)...                                                                                                                                                                                                                                                                                                                │
│  INFO [6bceaabe] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [6bceaabe] Finished in 0.122 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO container not ready (unhealthy), retrying in 7s (attempt 7/7)...                                                                                                                                                                                                                                                                                                                │
│  INFO [dd7e0ab7] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' on 5.161.246.176                                                                                                                         │
│  INFO [dd7e0ab7] Finished in 0.124 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                           │
│  INFO [481beb4a] Running docker container ls --all --filter name=^senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40$ --quiet | xargs docker stop on 5.161.246.176                                                                                                                                                                                                                    │
│  INFO [481beb4a] Finished in 10.339 seconds with exit status 0 (successful).                                                                                                                                                                                                                                                                                                          │
│Releasing the deploy lock...                                                                                                                                                                                                                                                                                                                                                           │
│  Finished all in 50.5 seconds                                                                                                                                                                                                                                                                                                                                                         │
│  ERROR (Kamal::Cli::Healthcheck::Error): Exception while executing on host 5.161.246.176: container not ready (unhealthy) 
sergiotapia commented 3 months ago

In my server, I can run docker ps to get a list of running containers. The rails app isn't there.

root@senti:~# docker ps                                                                                                                                                                                                                   │
│CONTAINER ID   IMAGE           COMMAND                  CREATED          STATUS          PORTS                                       NAMES                                                                                                │
│f59d54999b56   traefik:v2.10   "/entrypoint.sh --pr…"   54 minutes ago   Up 54 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp           traefik                                                                                              │
│b826fe023fe7   postgres:15     "docker-entrypoint.s…"   54 minutes ago   Up 54 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   senti-db 

I'm doing a fresh, vanilla Rails app - hoping once I figure this out with help I can provide improvements to the documentation.

sergiotapia commented 3 months ago

Created a brand new rails app, and followed this guide https://gist.github.com/code-206/682c46bd6414b01f912096b4f8865a4b - still see the exact same issue. Don't know where to start to debug this.

djmb commented 3 months ago

Hi @sergiotapia - does docker ps -a show the container? Is there anything use when you run docker logs senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40?

imWildCat commented 3 months ago

I'm seeing the same problem. relatively new rails app. yesterday I can deploy it onto my staging server. but today it failed on my production server.

Same code. All ubuntus. no logs at all

update 1: I have one cent: maybe the public IP address is blocked by Azure network security group. That leads to the stuck status of my docker container. investigating.

sergiotapia commented 3 months ago
│  INFO [a65dad48] Finished in 0.154 seconds with exit status 0 (successful).                                                                                                                                                              │
│Acquiring the deploy lock...                                                                                                                                                                                                              │
│Ensure Traefik is running...                                                                                                                                                                                                              │
│  INFO [7e25ff8e] Running docker login -u [REDACTED] -p [REDACTED] on 5.161.246.176                                                                                                                                                       │
│  INFO [7e25ff8e] Finished in 0.228 seconds with exit status 0 (successful).                                                                                                                                                              │
│  INFO [b2a4abd7] Running docker container start traefik || docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --env-file .kamal/env/traefik/traefik.env --log│
│-opt max-size="10m" --label traefik.http.routers.catchall.entryPoints="http" --label traefik.http.routers.catchall.rule="PathPrefix(\`/\`)" --label traefik.http.routers.catchall.service="unavailable" --label traefik.http.routers.catch│
│all.priority="1" --label traefik.http.services.unavailable.loadbalancer.server.port="0" traefik:v2.10 --providers.docker --log.level="DEBUG" on 5.161.246.176                                                                             │
│Releasing the deploy lock...                                                                                                                                                                                                              │
│  Finished all in 13.8 seconds                                                                                                                                                                                                            │
│  ERROR (SSHKit::Command::Failed): Exception while executing on host 5.161.246.176: docker exit status: 125                                                                                                                               │
│docker stdout: 9ff6ad229d2e915ecae20efdf2c27d1bc2537d32134df1267c29133d179980e9                                                                                                                                                           │
│docker stderr: Error response from daemon: No such container: traefik                                                                                                                                                                     │
│Error: failed to start containers: traefik                                                                                                                                                                                                │
│docker: Error response from daemon: driver failed programming external connectivity on endpoint traefik (3c95a0d9f01e0358de9ed494e1d5900c746e05dcaa5f5e2255f5e8b02460f077): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: a│
│ddress already in use.                                                                                                                                                                                                                    │
│                        

Seeing a totally different error today on the same box I left to help troubleshoot the original bug. When I run kamal setup I see the error above.

I hope v2 of Kamal is better - this is very difficult and if this were a production server/app I would be cooked.

sergiotapia commented 3 months ago

Hi @sergiotapia - does docker ps -a show the container? Is there anything use when you run docker logs senti-web-1f8b5a9fd214d92956810d0072d21919dd2cba40?

I destroy all the docker containers from the server, then run kamal setup and see a totally different error than yesterday.

imWildCat commented 3 months ago

@sergiotapia do you have something like a firewall of your cloud provider or ufw?

I disabled them and it works again.

Looks like the app container would get stuck if the 80 port is not accessible

djmb commented 3 months ago

Error: failed to start containers: traefik
docker: Error response from daemon: driver failed programming external connectivity on endpoint traefik (3c95a0d9f01e0358de9ed494e1d5900c746e05dcaa5f5e2255f5e8b02460f077): Error starting userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.

Something is using port 80 on the machine you are trying to deploy to, so Traefik cannot start.

hecbuma commented 3 months ago

Hi, I'm experiencing something similar. I have an AWS setup with 1 bastion server, 1 web server and 1 worker. Web and worker are in the same private network. port 80 is open

My deployment goes all the way to docker run step, then it start waiting for the health checks.

I got this message

Exception while executing on host <privaye IP>: container not ready (unhealthy)

Then in the server I see the stopped containers

$ docker ps -a
CONTAINER ID   IMAGE                                                                                                           COMMAND                  CREATED          STATUS                     PORTS                               NAMES
9f8b7fff4d26   <url>/solorails-kamal-staging:sha   "entrypoint.sh"          3 minutes ago    Exited (0) 2 minutes ago                                       solorails-web-sha
c345224a88b6   d07ae8c301ce                                                                                                    "entrypoint.sh"          10 minutes ago   Exited (0) 9 minutes ago                                       solorails-web-44b5b61987472b11bdf14b7da6dee7d5d83d5151_replaced_61750ab791199297
f95411ddfde3   traefik:v2.10                                                                                                   "/entrypoint.sh --pr…"   10 minutes ago   Up 10 minutes              0.0.0.0:80->80/tcp, :::80->80/tcp   traefik

If try to see the docker logs on the container I get nothing.

The only log I can get is with journalctl but it doesn't make much sense for me.

$ sudo journalctl -u docker
Jun 12 04:19:52 ip-10-0-25-133 systemd[1]: Starting docker.service - Docker Application Container Engine...
Jun 12 04:19:52 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:52.548928965Z" level=info msg="Starting up"
Jun 12 04:19:52 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:52.553862826Z" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/syst>
Jun 12 04:19:53 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:53.115925279Z" level=info msg="Loading containers: start."
Jun 12 04:19:53 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:53.455704575Z" level=info msg="Loading containers: done."
Jun 12 04:19:53 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:53.503148846Z" level=info msg="Docker daemon" commit=de5c9cf containerd-snapshotter=false storage-driver=overlay2 version>
Jun 12 04:19:53 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:53.503364922Z" level=info msg="Daemon has completed initialization"
Jun 12 04:19:53 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:19:53.577242755Z" level=info msg="API listen on /run/docker.sock"
Jun 12 04:19:53 ip-10-0-25-133 systemd[1]: Started docker.service - Docker Application Container Engine.
Jun 12 04:28:02 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:28:02.214096570Z" level=warning msg="Error while looking up for image " spanID=ec212b71fee47fa4 traceID=9b1f6321dba633e6dfe1>
Jun 12 04:28:05 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:28:05.174741560Z" level=warning msg="Error while looking up for image " spanID=da0be03a9008bb96 traceID=3a1ec7a9c52dd086bdcd>
Jun 12 04:28:06 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:28:06.412805386Z" level=info msg="ignoring event" container=c345224a88b6452b00783a962018fd75fd6ef319aea15881ed5b42b2b534f13a>
Jun 12 04:28:06 ip-10-0-25-133 dockerd[2431]: time="2024-06-12T04:28:06.819880363Z" level=info msg="ignoring event" container=c345224a88b6452b00783a962018fd75fd6ef319aea15881ed5b42b2b534f13a>
hecbuma commented 3 months ago

I found my issue, my dockerfile and entrypoint.sh aren't correctly setup.

gauravmc commented 1 month ago

@hecbuma how did you end up setting up entrypoint.sh? I'm setting up kamal on an existing repo, and everything seems to be running/setting up okay until the entrypoint line and errors out with this:

docker stderr: docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/rails/bin/docker-entrypoint": stat /rails/bin/docker-entrypoint: no such file or directory: unknown.

It seems /rails/bin/docker-entrypoint file should exist in the vps. Not sure how/when does is it normally created on a new Rails project.

hecbuma commented 1 month ago

@gauravmc this is my entrypoint.sh

#!/bin/bash
set -e

case $1 in
web)
    echo "About to run rake db:migrate and assets:precompile with RAILS_ENV=${RAILS_ENV} in folder ${PWD}"
    bundle exec rake db:migrate
    bundle exec rake assets:precompile

    echo "Additional scripts"
    bundle exec rake setup:seed_excluded_clinics

    echo "About remove server.pid file and run rails server in folder ${PWD}"
    rm -f tmp/pids/server.pid
    echo "About to run rails server"
    bin/rails server -p 3000 -b '0.0.0.0'
    ;;
worker)
    echo "About to run rake db:migrate and assets:precompile with RAILS_ENV=${RAILS_ENV}"
    bundle exec rake db:migrate
    echo "About to run rails server"
    rm -f tmp/pids/server.pid
    bin/rails server -p 3000 -b '0.0.0.0' &
    echo "About to run solid_queue:start"
    bin/rails solid_queue:start
    ;;
*)
    exec "$@"
    ;;
esac
exec "$@"

And my dockerfile


FROM --platform=linux/amd64 ruby:3.3.4

RUN apt-get update -qq && apt-get install -y \
  build-essential \
  nodejs \
  postgresql-client

RUN mkdir -p /opt/app
WORKDIR /opt/app

COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . ./

COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

EXPOSE 3000
ENTRYPOINT ["entrypoint.sh"]
gauravmc commented 1 month ago

@hecbuma Thanks. I end up copy pasting bin/entrypoint from a new Rails 7.1 app, which resolved the issue.