0

主に価格が理由で、HerokuではなくDigitalOceanに初めてレールアプリをデプロイしようとしています。私はCapistranoとVPSの展開にまったく慣れておらず、完全に迷っています。1-click-Rails-droplet を作成し、次のチュートリアルに従いました: http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html

これは私の deploy.rb ファイルの設定です:

require 'capistrano/ext/multistage'

set :stages, ["staging", "production"]
set :default_stage, "staging"

set :application, "myAppName"
set :scm, :git
set :repository, "myGitRepository"
set :use_sudo, :false

set :deploy_via, :remote_cache

set :scm_passphrase, "myPassword"
set :user, "root"
role :web, "xx.xxx.x.xxx" 
role :app, "xx.xxx.x.xxx" 

staging.rb ファイル:

server "xx.xxx.x.xxx", :app, :web, :db, :primary => true
set :deploy_to, "/var/www/xx.xxx.x.xxx_staging"

そして production.rb ファイル

server "xx.xxx.x.xxx", :app, :web, :db, :primary => true
set :deploy_to, "/var/www/xx.xxx.x.xxx"

今、私が走るとき

cap deploy:check

ターミナルでは、次のようになります。

[xx.xxx.x.xxx] executing command
xx.xxx.x.xxx: env: 
xx.xxx.x.xxx: sh
xx.xxx.x.xxx: : No such file or directory
xx.xxx.x.xxx: 
    command finished in 88ms
  * executing "test -w /var/www/xx.xxx.x.xxx_staging"
    servers: ["xx.xxx.x.xxx"]
    [xx.xxx.x.xxx] executing command
xx.xxx.x.xxx: env: 
xx.xxx.x.xxx: sh
xx.xxx.x.xxx: : No such file or directory
xx.xxx.x.xxx: 
    command finished in 79ms
  * executing "test -w /var/www/xx.xxx.x.xxx_staging/releases"
    servers: ["xx.xxx.x.xxx"]
    [xx.xxx.x.xxx] executing command
xx.xxx.x.xxx: env: 
xx.xxx.x.xxx: sh
xx.xxx.x.xxx: : No such file or directory
xx.xxx.x.xxx: 
    command finished in 72ms
  * executing "which git"
    servers: ["xx.xxx.x.xxx"]
    [xx.xxx.x.xxx] executing command
xx.xxx.x.xxx: env: 
xx.xxx.x.xxx: sh
xx.xxx.x.xxx: : No such file or directory
xx.xxx.x.xxx: 
    command finished in 85ms
  * executing "test -w /var/www/xx.xxx.x.xxx_staging/shared"
    servers: ["xx.xxx.x.xxx"]
    [xx.xxx.x.xxx] executing command
xx.xxx.x.xxx: env: 
xx.xxx.x.xxx: sh
xx.xxx.x.xxx: : No such file or directory
xx.xxx.x.xxx: 
    command finished in 81ms
The following dependencies failed. Please check them and try again:
--> `/var/www/xx.xxx.x.xxx_staging/releases' does not exist. Please run `cap staging deploy:setup'. (xx.xxx.x.xxx)
--> You do not have permissions to write to `/var/www/xx.xxx.x.xxx_staging'. (xx.xxx.x.xxx)
--> You do not have permissions to write to `/var/www/3xx.xxx.x.xxx_staging/releases'. (xx.xxx.x.xxx)
--> `git' could not be found in the path (xx.xxx.x.xxx)
--> `/var/www/xx.xxx.x.xxx_staging/shared' is not writable (xx.xxx.x.xxx)

私は長い間グーグルで検索しましたが、これを修正できません。私はこれにまったく慣れていないので、Rails アプリの作成方法を学ぶことと、それらのデプロイに関するすべてのことを知ることの間には大きなギャップがあるように感じます (ところで、以前の ftp アップロードはどうなったのでしょうか?)、誰かが知っていることを本当に願っています。これを修正する方法と、展開の学習曲線がそれほど急ではない方向に私を導くことができます。ところで、私がやろうとしていることを行うための「より簡単な」方法はありますか? どうもありがとうございました!

編集:もう1つの質問:サーバーへの途中でgithubにアプリをデプロイする必要がありますか?

4

1 に答える 1

1
require "bundler/capistrano"

server "XXX.XX.XXX.XXX", :web, :app, :db, primary: true

これは、アクセスするサーバーを Capistrano に通知するだけです。今のところ、サーバーは 1 つしかないため、Web、アプリ、および db サーバーとして機能します。Web サーバーは nginx + ユニコーンです。app サーバーは Rails アプリケーションで、db はデータベース サーバーです。primary true は、他のデータベース サーバーに拡張した場合に、これがプライマリ データベース サーバーであることを示します。これらはロールと呼ばれ、さらに定義できますが、これらは必須の主なものです。いくつかのタスクを特定のロールで実行し、他のロールで実行しないように指定できますが、複数のサーバーがある場合はそれだけです。

set :application, "applicationName"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, :git 
set :repository,  "GIT REPO URL"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true

これらは、Capistrano が使用するいくつかの変数をセットアップするだけです。アプリケーション名、デプロイするユーザー (root を使用して別のユーザーを作成しないでください)、デプロイする場所、コマンドを実行するときに sudo を使用するかどうか (Ryan は、sudo を使用するとパーミッション エラーが発生することがあると言っています)。次に、git / subversion としてのソース コード管理システム、およびデプロイ先のリポジトリとブランチへのリンク。次の2つのオプションは、sshキーを使用していくつかのことを処理することでした。

したがって、Capistrano がどのように機能するかを考えるときは、Rakefile と Rake タスクがどのように機能するかを正確に考えてください。

after "deploy", "deploy:cleanup"    

「XXX」、「YYY」の後にこの種のステートメントが表示されている場合は、タスク XXX が完了した後に YYY を実行すると言っているだけです。この場合、タスクのデプロイが完了したら、deploy:cleanup を実行します。

namespace :deploy do
  %w[start,stop,restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
  end
end

このタスクは、ユニコーン サーバーの開始と停止を停止および再起動できるようにするためのタスクを作成するだけです。したがって、このタスクは、後でサイトが展開されてユニコーン サーバーを再起動するとすぐに組み合わせて使用​​できます。

task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"
  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

これは非常に複雑に見えるタスクですが、実際にはあまり機能していません。Railscasts では、Ryan は自分の database.yml ファイルを git に入れていなかったので (本番用の値を使用)、彼はテンプレートの database.example.yml ファイルを作成しました。これはフォルダー apps/APPNAME/shared/ に入れられます。手動で移動する必要があります。それを編集します。これらの共有構成は、現在のフォルダーにシンボリック リンクされています。

他のファイル nginx.conf unicorn.rb および unicorn_init.sh では、正しいパスを指すようにパスを編集する必要があります。

その他のリソース

Railscasts Capistrano Recipesも参照してください。彼はレシピの詳細を拡張し、より DRY にしています。Capistrano Wiki には、最初からと呼ばれる優れたリソースもあります。さらに、Nginx & Unicornでは、これら 2 つのことについて詳しく説明しています。また、Unicorn に関する Github のブログ投稿と、このNginx 入門書を読むことをお勧めします。

しかし、ほとんどの場合、エラーが発生しても心配する必要はありません。一度に 1 つのエラーに分解してみてください。幸運を祈ります。

于 2013-08-06T11:05:57.970 に答える