使用 Kamal 部署 Rails 应用程序会出现错误 ActiveRecord::AdapterNotSpecified

问题描述 投票:0回答:1

当使用 Rails 8 和 Kamal v2 运行

kamal setup
时,我遇到了错误:

Running docker exec kamal-proxy kamal-proxy deploy .........
ERROR bin/rails aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
Tasks: TOP => db:prepare => db:load_config
(See full trace by running task with --trace)
bin/rails aborted!
.... repeats error several times...
...
Finished all in 70.3 seconds
RROR (SSHKit::Command::Failed): Exception while executing on host 192.168.1.106: docker exit status: 1
docker stdout: Nothing written
docker stderr: Error: target failed to become healthy

postgres 容器已与其他容器一起设置

CONTAINER ID   IMAGE  COMMAND   CREATED  STATUS   PORTS    NAMES
ca123123d01d   postgres:16.2    "docker-entrypoint.s…"   8 hours ago  Exited (255) 7 hours ago    liveactivity-db

任何有关如何解决未找到适配器问题的想法都很棒!

部署.yml

service: liveactivity
image: my_image
servers:
  web:
    - 192.168.1.106
registry:
  username: my_username
  password:
    - KAMAL_REGISTRY_PASSWORD
env:
  secret:
    - RAILS_MASTER_KEY
  clear:
    SOLID_QUEUE_IN_PUMA: true
    DB_HOST: 192.168.1.106
aliases:
  console: app exec --interactive --reuse "bin/rails console"
  shell: app exec --interactive --reuse "bash"
  logs: app logs -f
  dbc: app exec --interactive --reuse "bin/rails dbconsole"
volumes:
  - "liveactivity_storage:/rails/storage"
asset_path: /rails/public/assets
builder:
  arch: arm64
ssh:
  user: my_ssh_username
  proxy: [email protected]
  keys: ["~/.ssh/id_rsa"]
accessories:
  db:
    image: postgres:16.2
    host: 192.168.1.106
    port: 5432
    env:
      clear:
        POSTGRES_USER: "postgres"
        POSTGRES_DB: "liveactivity_production"
      secret:
        - POSTGRES_PASSWORD
    directories:
      - data:/var/lib/postgresql/data

数据库.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

production:
  primary: &primary_production
    <<: *default
    host: <%= ENV["DB_HOST"] %>
    database: <%= ENV["POSTGRES_DB"] %>
    username: <%= ENV["POSTGRES_USER"] %>
    password: <%= ENV["POSTGRES_PASSWORD"] %>
  cache:
    <<: *primary_production
    database: liveactivity_production_cache
    migrations_paths: db/cache_migrate
  queue:
    <<: *primary_production
    database: liveactivity_production_queue
    migrations_paths: db/queue_migrate
  cable:
    <<: *primary_production
    database: liveactivity_production_cable
    migrations_paths: db/cable_migrate
ruby-on-rails kamal
1个回答
0
投票

在运行 kamal setup/deploy 之前对 config/deploy.yml、config/database.yml 或 .kamal/secrets 所做的任何尚未提交到 git 的更改都将被忽略。它实际上显示在运行 kamal setup 时的输出中:

Building from a local git clone, so ignoring these uncommitted changes:
 M .kamal/secrets
 M config/database.yml
 M config/deploy.yml

一旦我提交了更改,从服务器中删除了容器,并再次运行 kamal setup ,错误就得到了解决。

© www.soinside.com 2019 - 2024. All rights reserved.