Capistrano - can't deploy my database.yml

前端 未结 3 731
不思量自难忘°
不思量自难忘° 2021-02-08 03:14

When I try to deploy my app with capistrano, I\'ll get this error:

failed: \"sh -c \'cp /var/www/my_app/releases/20120313115055/config/database.stagi

相关标签:
3条回答
  • 2021-02-08 03:54

    If you don't need to "reference application objects or methods"(1) during precompile then you might be OK with setting config.assets.initialize_on_precompile to false in config/application.rb

    0 讨论(0)
  • 2021-02-08 03:59

    I'm not sure how to solve your problem. It looks like database.staging.yml is not being deployed, so there's nothing for it to copy over.

    I think there's a better workflow, though. Things like settings and database configs do not typically change between deployments, so those things can go in the shared folder of all the capistrano releases. Typically, you don't want your database.yml to be in your repo either since it's sensitive information. You can satisfy both of these things by excluding config/database.yml in your .gitignore.

    This requires you to do a one time set up on your servers. You need create a database.yml at your_app_path/shared/config. Shared is a sibling to current and releases.

    Your deploy.rb should have a task that symlinks the newly deployed release's database.yml to the on in the shared directory. Like this:

    before "deploy:assets:precompile" do
      run ["ln -nfs #{shared_path}/config/settings.yml #{release_path}/config/settings.yml",
           "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml",
           "ln -fs #{shared_path}/uploads #{release_path}/uploads"
      ].join(" && ")
    end
    

    This means that your repo will contain no database.yml files. Since they are probably already in your repo. You'll have to git rm them, commit. Add them to the .gitignore and commit that.

    0 讨论(0)
  • 2021-02-08 04:18

    In Capistrano 3, linking files is built-in. John's answer is simply:

    • In the shared/ folder create config/database.yml
    • In config/deploy.rb use this line

      set :linked_files, fetch(:linked_files, []).push('config/database.yml')
      

    This does what John was saying.

    0 讨论(0)
提交回复
热议问题