Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem deploying since commit d547ea10 #439

Closed
devvmh opened this issue Sep 19, 2016 · 9 comments
Closed

Problem deploying since commit d547ea10 #439

devvmh opened this issue Sep 19, 2016 · 9 comments

Comments

@devvmh
Copy link
Contributor

devvmh commented Sep 19, 2016

I can't deploy since d547ea1

The error is

       sh: line 0: cd: /home/deploy/mina-deploys/devin/cure: No such file or directory

 !     Run Error

The working branch I'm using is master...devvmh-forks:revert-d547ea10 (I had to resolve two conflicts during revert so it's not an exact revert)

It's possible I need to update my deploy.rb? My deploy task still starts with task deploy: :environment do, is that a problem?

@d4be4st
Copy link
Member

d4be4st commented Sep 26, 2016

@devvmh could you please give us your deploy script?

@devvmh
Copy link
Contributor Author

devvmh commented Sep 27, 2016

ok sure. Full disclosure: I have more tasks at the bottom of the file, but I've excluded them because they contain some details about my server setup, plus brevity.

require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'
require 'mina/whenever'
require 'slack-notifier'
require 'mina_sidekiq/tasks'

port = 22
site_name = ENV['on'] || 'staging'
rails_env = site_name == 'production' ? 'production' : 'staging'
project = ENV['project'] || 'cure'

need_migration = project == 'cure' || project == 'dist'
need_compile_assets = %(www cure dist).include?(project)
need_sidekiq = project == 'cure'
need_whenever = project == 'cure' && ['production', 'staging'].include?(site_name)
need_sync_assets = ENV['sync_assets'] == 'true'

if site_name == 'production'
  domain = 'www.example.com'
  branch = ENV['branch'] || 'master'
  deploy_to = "/home/deploy/#{project}"
elsif site_name == 'staging'
  domain = 'www.example.in'
  branch = ENV['branch'] || `git symbolic-ref --short HEAD`.chomp
  deploy_to = "/home/deploy/#{project}"
else
  domain = "#{site_name}.#{project}.example.in”
  branch = ENV['branch'] || `git symbolic-ref --short HEAD`.chomp
  deploy_to = "/home/deploy/mina-deploys/#{site_name}/#{project}"
  need_sidekiq = false
  need_whenever = false
end

# required config
set :domain, domain
set :deploy_to, deploy_to
set :repository, '[email protected]:organization/repo.git'
set :branch, branch
set :user, 'deploy'
set :port, port

# special config
set :rails_env, rails_env
set :site_name, site_name
set :project, project
set :whenever_name, “whenever_#{site_name}"
set :keep_releases, 3
set :notification_user, ENV['USER']
set :sidekiq_pid, "#{fetch(:shared_path)}/tmp/pids/sidekiq.pid"

# core mina config changes
set :bundle_bin, '/home/deploy/.rbenv/shims/bundle'
set :shared_dirs, fetch(:shared_dirs, []).push('node_modules')
set :shared_files, fetch(:shared_files, []).push('.env')

# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
  in_path(fetch(:deploy_to)) do
    invoke :'rbenv:load'
  end
end

desc 'Deploys the current version to the server.'
task deploy: :environment do
  system %(echo "Deploying branch #{branch} to #{deploy_to} on #{site_name}")

  run(:local) { invoke :'notification:start_deploy' }

  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    comment %(Installing node modules) if need_compile_assets
    command %(npm install --loglevel=error) if need_compile_assets
    invoke :'rails:db_migrate' if need_migration
    invoke :'rails:assets_precompile' if need_compile_assets
    invoke :’assets:sync' if need_sync_assets
    invoke :'deploy:cleanup'

    on :launch do
      invoke :'passenger:restart'
      invoke :'sidekiq:restart' if need_sidekiq
      invoke :'whenever:update' if need_whenever
      in_path(fetch(:current_path)) do
        command %(RAILS_ENV=#{fetch(:rails_env)} #{fetch(:bundle_bin)} exec rake coverband:baseline > /dev/null)
      end
    end
  end

  run(:local) { invoke :'notification:finish_deploy' }
end

namespace :passenger do
  task :restart do
    in_path(fetch(:current_path)) do
      comment 'Restarting passenger'
      # this version is deprecated but works reliably
      # command %(touch tmp/restart.txt)
      # this version seems to cause problems sometimes
      command %(passenger-config restart-app #{fetch(:deploy_to)} --ignore-app-not-running)
    end
  end
end

namespace :assets do
  task :sync do
    in_path(fetch(:current_path)) do
      comment 'Syncing assets'
      command %(#{fetch(:bundle_bin)} exec rake assets:sync RAILS_ENV=#{fetch(:rails_env)})
    end
  end
end

namespace :notification do
  notifier = Slack::Notifier.new('https://....')
  task :start_deploy do
    command %(echo '') # workaround mina bug
    next if ARGV.include?('-s') || ARGV.include?('--simulate')

    site_name = fetch(:site_name)
    user = fetch(:notification_user)

    if site_name == 'production' || site_name == 'staging'
      notifier.ping %(
        @#{user} is deploying `#{fetch(:project)}` to `#{site_name}` with `#{fetch(:branch)}` branch @group
      ).strip
    end
  end

  task :finish_deploy do
    command %(echo '') # workaround mina bug
    next if ARGV.include?('-s') || ARGV.include?('--simulate')

    site_name = fetch(:site_name)
    user = fetch(:notification_user)

    if site_name == 'production' || site_name == 'staging'
      notifier.ping %(
        @#{user} successfully deployed `#{fetch(:project)}` to `#{site_name}` with `#{fetch(:branch)}` branch @group
      ).strip
    end
  end
end

@d4be4st
Copy link
Member

d4be4st commented Sep 27, 2016

seem like you are missing your deploy_to directory on server

deploy_to = "/home/deploy/mina-deploys/#{site_name}/#{project}"

you need to either run mina setup or just create the folder on the server

@devvmh
Copy link
Contributor Author

devvmh commented Sep 27, 2016

No, that's not the case. The same file works if I revert the commit I mentioned

My best guess is that the commands are being run on my localhost instead of over ssh.

@d4be4st
Copy link
Member

d4be4st commented Sep 27, 2016

hm.. weird.

if you try to run deploy with --simulate do you get what you expect?

When i try your deploy script i get normally
# Executing the following:
...
# Executing the following via 'ssh [email protected] -p 22 -tt':
...
# Executing the following:

Can you please check your simulate script

@devvmh devvmh changed the title Need to revert commit d547ea10? Problem deploying since commit d547ea10 Sep 27, 2016
@devvmh
Copy link
Contributor Author

devvmh commented Sep 28, 2016

Awesome, so either I messed it up before, or this issue is mostly fixed in 1.0.0. I just tested with the latest mina release, and it works!

I do still get an error message, I'm assuming because run :local is trying to load rbenv (which will fail, since I use rvm locally). Here's the top part of mina deploy on=minatest --simulate:

uniqueway-devin:uniqueway devin$ mina deploy on=minatest --simulate
Deploying branch testing/mina to /home/deploy/mina-deploys/minatest/cure on minatest
#!/usr/bin/env bash
# Executing the following:
#
(cd /home/deploy/mina-deploys/minatest/cure && echo "-----> Loading rbenv" && export RBENV_ROOT="$HOME/.rbenv" && export PATH="$HOME/.rbenv/bin:$PATH" && if ! which rbenv >/dev/null; then
  echo "! rbenv not found"
  echo "! If rbenv is installed, check your :rbenv_path setting."
  exit 1
fi && eval "$(rbenv init -)")
echo ''

       Elapsed time: 0.00 seconds
#!/usr/bin/env bash
# Executing the following via 'ssh [email protected] -p 22 -tt':
#
#!/usr/bin/env bash

# Go to the deploy path
cd "/home/deploy/mina-deploys/minatest/cure" || (
echo "! ERROR: not set up."
echo "The path '/home/deploy/mina-deploys/minatest/cure' is not accessible on the server."
echo "You may need to run 'mina setup' first."
false
) || exit 15

#...

Any thoughts on whether run :local should/shouldn't load the environment? I assume it's a simple, but important to decide, fix

@d4be4st
Copy link
Member

d4be4st commented Sep 28, 2016

Just remove the dependency of your deploy task on :environment

It is invoked here if on remote:
https://github.com/mina-deploy/mina/blob/master/lib/mina/dsl.rb#L28

@d4be4st d4be4st closed this as completed Sep 28, 2016
@devvmh
Copy link
Contributor Author

devvmh commented Sep 28, 2016

OK sounds good. This might be a good candidate for adding to https://github.com/mina-deploy/mina/blob/master/docs/migrating.md

Thanks and congratulations on the release!

@d4be4st
Copy link
Member

d4be4st commented Sep 28, 2016

Good idea!

Thx

On Wed, Sep 28, 2016, 07:53 Devin Howard [email protected] wrote:

OK sounds good. This might be a good candidate for adding to
https://github.com/mina-deploy/mina/blob/master/docs/migrating.md

Thanks and congratulations on the release!


You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
#439 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA7cMD7wKAAERRK4_OR28SLwGKETASxGks5qugDqgaJpZM4KAGFk
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants