Chef入门,并在部署时运行composer安装 [英] Getting started with chef, and running composer install on deploy

查看:84
本文介绍了Chef入门,并在部署时运行composer安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望通过OpsWorks在亚马逊上部署一些基于 Laravel4 的PHP应用程序,这需要一些注意事项:

We're looking to deploy a few Laravel4 based PHP apps on amazon with OpsWorks, this requires a few things:

  • 从git抓取代码
  • 从getcomposer.com下载composer.phar
  • 运行php composer.phar install
  • 更改一些特定文件夹的权限
  • Grab code from git
  • Download composer.phar from getcomposer.com
  • Run php composer.phar install
  • Change permissions on a few specific folders

我对厨师一无所知,因此,最初寻找一个掌握厨师基础知识的地方,然后如何实现上述任务,将不胜感激.

I'm completely fresh with it comes to chef, so initially looking for a place to get to grips with the basics of chef, and then how to achieve the tasks above, would appreciate any pointers.

推荐答案

我不是厨师大师(我通常使用Puppet),但是请尝试以下操作:

I'm no Chef guru (I usually use Puppet) but try the following:

您可能要执行wget命令(请参见下面的示例).

You may want to execute a wget command (see examples below).

如果您想要更复杂的内容,请参见 http://docs.opscode.com/resource_deploy.html

If you want something more sophisticated see http://docs.opscode.com/resource_deploy.html

deploy_revision "/path/to/application" do
  repo 'ssh://name-of-git-repo/repos/repo.git'
  migrate false
  purge_before_symlink %w{one two folder/three}
  create_dirs_before_symlink []
  symlinks(
    "one"   => "one",
    "two"   => "two",
    "three" => "folder/three"
  )
  before_restart do
    # some Ruby code
  end
  notifies :restart, "service[foo]"
  notifies :restart, "service[bar]"
end

从getcomposer.com下载composer.phar

我要执行一个wget.

Download composer.phar from getcomposer.com

I would execute a wget.

我从此处提取了一些代码: http://cookingclouds. com/2012/06/23/chef-simple-cookbook-example/

I lifted some code from here: http://cookingclouds.com/2012/06/23/chef-simple-cookbook-example/

基本上,它只是在特定文件夹中执行wget,提取tar& amp;的内容.更新对新文件的某些权限.如果文件夹不存在,则只会执行此操作.

It's basically just doing a wget in a specific folder, extracting the contents of the tar & updating some permissions on the new files. It only does this if the folder doesn't already exist.

# Run a bash shell -  download and extract composer
bash "install_composer" do
     user "root"
     cwd "/folder/to/extact/to"
     code <<-EOH
       wget http://getcomposer.com/composer.tar.gz
       tar -xzf composer.tar.gz
       chown -R user:group /folder/to/extact/to
     EOH
     not_if "test -d /folder/to/extact/to"
end

运行php composer.phar install

http://docs.opscode.com/resource_execute.html

execute "composer install" do
  command "php composer.phar install && touch /var/log/.php_composer_installed"
  creates "/var/log/.php_composer_installed"
  action :run
end

这只会运行一次,否则您可以删除创建",并且每次都会运行.

This will only run it once, otherwise you can remove the "creates" and it will run it each time.

http://docs.opscode.com/resource.html

directory "/tmp/folder" do
  owner "root"
  group "root"
  mode 0755
  action :create
end

如果目录已经存在,则不会发生任何事情.如果以任何方式更改了目录,则该资源将被标记为已更新.

If the directory already exists, nothing will happen. If the directory was changed in any way, the resource is marked as updated.

我发现搜索很方便,在Chef网站上浏览内容似乎毫无希望(太多内容可供挖掘). http://docs.opscode.com/search.html

I find the search handy, browsing stuff on the Chef site seems to be hopeless (too much stuff to dig through). http://docs.opscode.com/search.html

这篇关于Chef入门,并在部署时运行composer安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆