dongwh1992 2014-04-11 11:26
浏览 69

OpsWorks / Chef PHP部署过程

I'm having some serious frustration getting a simple PHP application to deploy reliably using OpsWorks, I can't find any documentation of how the srv/www/app-name/releases directory is managed, but I think that may been the cause of my current problem.

I'm deploying a Laravel application, so I need two things to happen with chef recipes on deploy: composer install, and some directories to be made writable. Composer does seem to be installing fine, but my recipe to create & chmod the directories seems to happen to the previous release - which makes no sense to me at all.

Install composer:

node[:deploy].each do |application, deploy|
  script "composer-install" do
    interpreter "bash"
    cwd "#{deploy[:deploy_to]}/current"
    user "root"
    code <<-EOH
    composer install
    EOH
  end
end

This works fine, I can refresh the vendor directory as this runs see the dependencies appearing. But the next recipe to run:

node[:deploy].each do |application, deploy|
    Chef::Log.info("Application path: #{deploy[:deploy_to]}");

    node['directories'].each do |path|

        # Get the path we need
        new_path = "#{deploy[:deploy_to]}/current/"+path

        Chef::Log.info("Checking directory: "+new_path);

        # Ensure the dir exists
        unless File.exists?(new_path)
            Chef::Log.info("Creating directory: "+new_path);
            Dir.mkdir( new_path, 777 )
        end

        # Ensure its writable
        File.chmod( 777, new_path )

    end
end

The content from Chef::log does appear in the log, there are no errors, but the directories are simply not there - they are created in the PREVIOUS release/timestamp directory, as if the 'current' symlink has reverted back for the duration of this recipe. They are also created with permissions '411'.

Can anyone explain where I'm going wrong here? Can I access the new directory path instead of using the 'current' symlink?

  • 写回答

1条回答 默认 最新

  • dongzouhe9734 2014-04-13 23:33
    关注

    What is very likely happening is that you're applying these two specified recipes at different stages of the deployment. Since you're using Current - it will be at one stage the old directory, while checking out the next part of the application.

    What you should be maybe doing instead is :

    1. use the "#{release_path}" variable in your recipes to generate build specific files/events in your app.
    2. use the deploy/before_restart.rb file to execute some symlinks that provide the files at a predictable location

    If you provide screenshot of the recipes that are being called and on what layer from the layer edit view, it will help people here to see what is happening and give you a better feedback.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集