##状況
Railsアプリをec2 + nginx + unicorn + capistranoでの自動デプロイに挑戦しているのですが、設定をし終えてbundle exec cap production deploy
をするとGit周りのエラーが起こってしまいます。
##エラー内容
local
1$ bundle exec cap production deploy 2省略 3(Backtrace restricted to imported tasks) 4cap aborted! 5SSHKit::Runner::ExecuteError: Exception while executing as Stelle@3.112.153.67: git exit status: 1 6git stdout: error: cannot open FETCH_HEAD: 許可がありません 7git stderr: Nothing written
これまでの流れとしては、サーバー上で~から.gitconfigを編集し、その後は以下のとおりです。
server
1[Stelle@ip- ~]$ chmod 700 .ssh 2 3[Stelle@ip- ~]$ cd .ssh 4 5[Stelle@ip- .ssh]$ ssh-keygen -t rsa 6Generating public/private rsa key pair. 7省略 8 9[Stelle@ip- .ssh]$ vim config 10Host github 11 Hostname github.com 12 User git 13 IdentityFile ~/.ssh/xxx_key_rsa 14これで保存 15 16[Stelle@ip- .ssh]$ cat xxx_key_rsa.pub 17Githubにssh接続 18 19[Stelle@ip- .ssh]$ chmod 600 config 20 21[Stelle@ip- .ssh]$ ssh -T github 22Hi sakanafuto! You've successfully authenticated, but GitHub does not provide shell access. 23 24[Stelle@ip- .ssh]$ cd 25 26[Stelle@ip- ~]$ ssh-add ~/.ssh/xxx_key_rsa 27Could not open a connection to your authentication agent. 28 29[Stelle@ip- ~]$ eval "$(ssh-agent)" 30Agent pid 27483 31 32[Stelle@ip- ~]$ ssh-add ~/.ssh/xxx_key_rsa 33Identity added: /home/Stelle/.ssh/xxx_key_rsa (/home/Stelle/.ssh/xxx_key_rsa)
この後にローカルで先程のようにデプロイするとエラーに成ってしまいます。
##該当コード
config/deproy.rb
lock "3.5.0" set :application, "stelle" set :repo_url, "git@github.com:sakanafuto/xxx.git" set :deploy_to, "/var/www/stelle" set :scm, :git set :format, :pretty set :log_level, :debug set :pty, true set :keep_releases, 5 set :rbenv_type, :user set :rbenv_ruby, '2.6.5' set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" set :rbenv_map_bins, %w{rake gem bundle ruby rails} set :linked_files, fetch(:linked_files, []).push('config/master.key') set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system') set :bundle_jobs, 4 namespace :deploy do desc 'Restart application' task :restart do on roles(:app) do invoke 'unicorn:restart' end end desc 'Create database' task :db_create do on roles(:db) do |host| with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:create' end end end end desc 'Run seed' task :seed do on roles(:app) do with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:seed' end end end end end after 'deploy:publishing', 'deploy:restart'
config/deploy/production.rb
server '3.xxx.xxx.x', user: 'Stelle', roles: %w{app db web} set :ssh_options, { keys: '~/.ssh/xxx_key_rsa', forward_agent: true }
config/unicorn/production.rb
app_path = '/var/www/stelle' worker_processes 2 working_directory "#{app_path}" + "/current" preload_app true timeout 30 listen "/tmp/sockets/unicorn.sock", :backlog => 64 pid "#{app_path}/shared/tmp/pids/unicorn.pid" # Set the path of the log files inside the log folder of the testapp stderr_path "#{app_path}/current/log/unicorn.stderr.log" stdout_path "#{app_path}/current/log/unicorn.stdout.log" before_fork do |server, worker| ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT']) end before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill(sig, File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH end end sleep 1 end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
Capfile
require "capistrano/setup" require "capistrano/deploy" # require "capistrano/scm/git" # install_plugin Capistrano::SCM::Git require "capistrano/rbenv" require "capistrano/rails" require "capistrano/rails/assets" require "capistrano/rails/migrations" require "capistrano/bundler" require "capistrano3/unicorn" Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
Gemfile
gem 'capistrano', '~>3.5.0' gem 'capistrano-bundler', '~> 1.1.3' gem 'capistrano-rails', '~> 1.1.7' gem 'capistrano-rbenv' gem 'capistrano3-unicorn'
回答1件
あなたの回答
tips
プレビュー