mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.34k stars 491 forks source link

How to find out whether it's the first deployment (in the deploy command itself)? #652

Open jmuheim opened 4 years ago

jmuheim commented 4 years ago

(Related to https://github.com/mina-deploy/mina/issues/651)

I'd like to execute some commands depending on whether a deployment is the first one or not.

In the following pseudo code, I'm using a hypothetical first_deploy? method:

task :deploy do
  # uncomment this line to make sure you pushed your local branch to the remote origin
  invoke :'git:ensure_pushed'

  deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_schema_load' if first_deploy?
    invoke :'rails:db_migrate'
    command %{#{fetch(:rails)} db:seed} if first_deploy?
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      if first_deploy?
        invoke :'puma:start'
      else
        invoke :'puma:phased_restart'
      end
    end
  end
end

How can I achieve this?

jmuheim commented 4 years ago

I see that https://github.com/windy/mina-ng-puma offers the specific case of starting or restarting Puma:

phased_restart and restart need start puma correctly when puma is down.

Still, for loading the DB schema and seeding, a first_deploy? or similar is still needed.

jmuheim commented 4 years ago

I asked on StackOverflow: https://stackoverflow.com/questions/58372477/deployment-of-a-rails-app-how-should-the-db-be-loaded-and-filled-during-the-ver