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 get command output? #662

Closed run27017 closed 2 years ago

run27017 commented 3 years ago

How to get command output so that writing elegant ruby?

comment 'Copying node_modules and dist from old release'
max_release = command %(ls #{fetch(:releases_path)} -A1 | sort -rn | head -1)
command %(cp -r #{fetch(:releases_path)}/#{max_release}/node_modules node_modules)
command %(cp -r #{fetch(:releases_path)}/#{max_release}/node_modules node_modules)
lovro-bikic commented 2 years ago

Hi, this is not possible as Mina commands aren't executed one after the other, rather they're all queued first and then executed once as a single command.

However, the feature you're trying to implement (copying node_modules between releases) can be achieved with shared_dirs variable. It sets directories which will be symlinked between releases.

You can add node_modules to shared dirs like this (or you can reuse an existing set :shared_dirs and just append node modules):

set :shared_dirs, fetch(:shared_dirs, []).push('node_modules')

Once you change that, run mina setup again and node_modules will then be shared between releases.

Does this solve your issue?

paulalbertdev commented 2 years ago

May I add that in your example, each command is executed on the server, so you don't have to store the max_release var, you could have just replaced #{max_release} by `ls #{fetch(:releases_path)} -A1 | sort -rn | head -1`