require 'json'
file = File.read("config/server.json")
deploy_config = JSON.parse(file)

branch = deploy_config['branch'] || 'release'
set :branch, branch

append :linked_files, 'config/server.json'

set :stage, :production
set :rails_env, :production
set :port, 40022
set :repo_url, 'ssh://gitlab@gitlab.ikcrm.com:40022/ikcrm_server/app_push.git'
set :application, 'app_push'

set :deploy_to, deploy_config['deploy_to']
set :shared_path, -> { fetch(:deploy_to) + '/shared' }
# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :puma_bind,       "unix://#{fetch(:shared_path)}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{fetch(:shared_path)}/tmp/pids/puma.state"
set :puma_pid,        "#{fetch(:shared_path)}/tmp/pids/puma.pid"
set :puma_access_log, "#{fetch(:release_path)}/log/puma_error.log"
set :puma_error_log,  "#{fetch(:release_path)}/log/puma_access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to true if using ActiveRecord

deploy_config['servers'].each do |set|
  server set['server'], user: set['user'], roles: set['roles'], my_property: :my_value
end