• Как сделать деплой Rails APi, с Nginx и Puma?

    @Dendi47 Автор вопроса
    oh_shi,
    После выполнения этой команды # cap production deploy:initial

    Выдает вот такую ошибку

    (Backtrace restricted to imported tasks)
    cap aborted!
    NameError: undefined local variable or method `user' for main:Object

    Tasks: TOP => production
    (See full trace by running task with --trace)

    Capfile:

    # Capfile
    require 'capistrano/setup'
    require 'capistrano/deploy'
    
    require 'capistrano/rvm'
    require 'capistrano/bundler'
    require 'capistrano/puma'
    require 'capistrano/rails/migrations' 
    require 'capistrano/rails'
    require 'capistrano/scm/git'
    
    install_plugin Capistrano::SCM::Git
    install_plugin Capistrano::Puma
    set :rvm_type, :user
    Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }


    deploy.rb:

    # config/deploy.rb
    # config valid for current version and patch releases of Capistrano
    lock "~> 3.10.0"
    
    set :application, -> {'phonebook-api'}
    set :repo_url, '.'
    
    set :user, 'semenvr' #ssh auth username
    set :rvm_ruby_version, 'ruby-2.4.2'
    
    set :tmp_dir, "/home/#{user}/#{application}/tmp"
    ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
    
    set :puma_threads,    [4, 6]
    set :puma_workers,    2
    
    set :pty, true
    set :use_sudo, false
    set :stage, -> {:production} # по умолчанию production
    set :deploy_via, :remote_cache
    set :deploy_to, -> {"/home/#{user}/#{application}"}
    set :puma_bind, -> {"unix:///home/#{user}/#{application}/tmp/sockets/puma.sock"}
    set :puma_state, -> {"/home/#{user}/#{application}/tmp/pids/puma.state"}
    set :puma_pid, -> {"/home/#{user}/#{application}/tmp/pids/puma.pid"}
    set :puma_access_log, -> {"#{release_path}/log/puma.error.log"}
    set :puma_error_log, ->  {"#{release_path}/log/puma.access.log"}
    set :ssh_options,  { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
    set :puma_preload_app, true
    set :puma_worker_timeout, nil
    set :puma_init_active_record, true  # Change to false when not using ActiveRecord
    set :nginx_use_ssl, false
    
    
    set :log_level,     :debug
    set :keep_releases, 3
    
    ## Linked Files & Directories (Default None):
    set :linked_files, %w{config/database.yml config/secrets.yml}
    set :linked_dirs,  %w{log tmp public/uploads}


    nginx.conf:

    upstream puma {
      server unix:///home/semenvr/phonebook-api/tmp/sockets/puma.sock;
    }
    
    
    server {
      listen 80;
    
      root /home/semenvr/phonebook-api/public;
      access_log /home/semenvr/phonebook-api/log/nginx.access.log;
      error_log /home/semenvr/phonebook-api/log/nginx.error.log info;
    
    
      try_files $uri/index.html $uri @puma;
      location @puma {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://puma;
      }
    
      client_max_body_size 50M;
      keepalive_timeout 10;
    }


    deploy.rake:

    namespace :puma do
      desc 
      task :make_dirs do
        on roles(:app) do
          execute "mkdir #{shared_path}/tmp/sockets -p"
          execute "mkdir #{shared_path}/tmp/pids -p"
        end
      end
    
      before :start, :make_dirs
    end
    
    namespace :deploy do
      desc 
      task :copy_config do
        on release_roles :app do |role|
          fetch(:linked_files).each do |linked_file|
            user = role.user ? role.user + '@' : nil
            hostname = role.hostname
            linked_files(shared_path).each do |file|
              run_locally do
                execute :rsync, "config/#{file.to_s.gsub(/.*\/(.*)$/,"\\1")}", "#{user}#{hostname}:#{file.to_s.gsub(/(.*)\/[^\/]*$/, "\\1")}/"
              end
            end unless user.nil?
          end
        end
      end
    
      desc 
      task :check_revision do
        on roles(:app) do
          unless `git rev-parse HEAD` == `git rev-parse origin/master`
            puts 'WARNING: HEAD is not the same as origin/master'
            puts 'Run `git push` to sync changes.'
            exit
          end
        end
      end
    
      desc 
      task :initial do
        on roles(:app) do
          before 'deploy:restart', 'puma:start'
          invoke 'deploy'
        end
      end
    
      desc 
      task :restart do
        on roles(:app), in: :sequence, wait: 5 do
          invoke 'puma:restart'
        end
      end
    
      before :starting,     :check_revision
      before 'deploy:check:linked_files', 'deploy:copy_config'
     # after  :finishing,    :compile_assets # закомментируйте эту строчку если используете Rails API
      after  :finishing,    :cleanup
      after  :finishing,    :restart
    end
  • Как сделать деплой Rails APi, с Nginx и Puma?

    @Dendi47 Автор вопроса
    oh_shi, Я сделал вот по обычному деплою Rails (fsdev.blog/2017/11/5-how-to-make-deploy-ror-with-p... и не работает
  • Как сделать деплой Rails APi, с Nginx и Puma?

    @Dendi47 Автор вопроса
    oh_shi, например это:
    location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
      }