2014-10-08 89 views
1

我們的應用程序(1回購)有一個Rails後端和一個Angular前端。因此,部署過程在某個時候有一個npm install, bower install, grunt build --force。問題在於部署需要很長時間,因爲即使我們只是更新與Rails相關的東西,這些命令仍然可以執行。Capistrano:檢查Git中的文件夾是否已更改?

是否有某種鉤子,以便我可以檢查if the folder containing frontend code has changes, then npm install?或者,我們是否應該將回購利用各自的部署流程分成兩個回購協議?

回答

0

apistrano-faster-assets插件爲普通的Rails資產提供了這種功能。

您可能需要檢查core task to see how that's done並修改或複製粘貼代碼以供使用。

這裏是我的嘗試只提取相關的步驟,並提供一些更多的評論:

class PrecompileRequired < StandardError; end 
begin 
    # get the previous release 
    latest_release = capture(:ls, '-xr', releases_path).split[1] 

    # precompile if this is the first deploy 
    raise PrecompileRequired unless latest_release 

    # create a 'Pathname' object for latest_relase 
    latest_release_path = releases_path.join(latest_release) 

    # execute raises if there is a diff 
    execute(:diff, '-Naur', release_path.join('path/to/frontend/code'), latest_release_path.join('path/to/frontend/code')) rescue raise(PrecompileRequired) 

    info("Skipping asset precompile, no asset diff found") 

    # copy over all of the assets from the last release 
    execute(:cp, '-r', latest_release_path.join('public', fetch(:assets_prefix)), release_path.join('public', fetch(:assets_prefix))) 

rescue PrecompileRequired 
    # execute compile command here 
end 
相關問題