Engine Yard Developer Center

Migrating Custom Chef Recipes from V4 to V5

NOTE: When migrating to v5 we recommend that you boot a new environment and test your application there first. We do not recommend an in-place upgrade from v1/v2/v4 to v5.

Custom chef recipes work differently on v5. All custom chef recipes that work on v2 and v4 need to be updated.

  1. Create the cookbooks/ directory. We recommend that you add the cookbooks/directory to the root of your application. If you have an existing cookbooks/ directory, move it to a temporary directory first.

      cd /path/to/app
      mv -i cookbooks cookbooks.v4
      mkdir cookbooks
  2. Create cookbooks/ey-custom/recipes/after-main.rb and cookbooks/ey-custom/metadata.rb.

    ey-custom/recipes/after-main.rb is now the entrypoint of custom chef recipes. You do not need the main/ directory that you used on v4.

      # cookbooks/ey-custom/metadata.rb
      name 'ey-custom'
  3. You can use some custom chef recipes without copying the actual recipes. The list of Engine Yard supported recipes can be found here. Add include_recipe and depends.

    On v5, you can use many chef recipes without adding a copy of the recipe to cookbooks/. Check out https://github.com/engineyard/ey-cookbooks-stable-v5/tree/next-release/custom-cookbooks for the list of currently available recipes.

    For example, to use the delayed_job4 recipe that EY maintains, you only need to copy custom-delayed_job4 on https://github.com/engineyard/ey-cookbooks-stable-v5/tree/next-release/custom-cookbooks/delayed_job4/cookbooks to your cookbooks/ directory. Remove cookbooks/delayed_job4 if it still exists.

    On cookbooks/ey-custom/recipes/after-main.rb, add

      include_recipe 'custom-delayed_job4'

    On cookbooks/ey-custom/metadata.rb, add

      depends 'custom-delayed_job4'

    If you want to convert your existing custom chef recipes to v5 because we have not converted them yet or if it's something you wrote, follow steps 4-9.

  4. Copy the recipe from cookbooks.v4/ to cookbooks/. If you follow our instructions above, you will start with an empty cookbooks/.

      cd /path/to/app
      cp -pr cookbooks.v4/RECIPE_NAME cookbooks/
  5. Add cookbooks/RECIPE_NAME/metadata.rb.

      name 'RECIPE_NAME'
  6. Add include_recipe and depends. You always need to add these 2 for any recipe that you want to use.

    On cookbooks/ey-custom/recipes/after-main.rb, add

      include_recipe 'RECIPE_NAME'

    On cookbooks/ey-custom/metadata.rb, add

      depends 'RECIPE_NAME'
  7. Replace node['instance_role'], node['name'], and similar code and add ['dna']. We moved some data on dna.json from the "root" to dna{}. Check out/etc/chef/dna.json on a v5 instance to see the new format.'

    Run the code below to view the code that needs to be changed

      cd /path/to/cookbooks.v4/ # or cookbooks/
      grep -r "node\[\(:\|'\|\"\)\(applications\|engineyard\|environment\|instance_role\|members\|name\|users\|utility_instances\)" .
      # node['instance_role'] on v4
      # node ['name'] on v4

    Data specified on the attributes directory will not change. If you have

      default['redis'] = {'version' => "3.2.1"}

    you would still use

  8. Change the package versions. The v5 stack has new packages. Update your recipes to use these new versions. Refer to the table of common packages below.

    Package Package name V5 Version
    Imagemagick media-gfx/imagemagick
    Java dev-java/icedtea-bin 3.3.0 (JDK 8) (JDK 7)
    Memcached net-misc/memcached 1.4.25
    Redis dev-db/redis 3.2.0
    wkhtmltopdf media-gfx/wkhtmltopdf-bin
  9. (Optional) Use a string instead of symbol when accessing node attributes. The code below are similar. Either can be used. Foodcritic (lint tool for Chef) suggests using a string.

      # use this
      # don't use this
Was this article helpful?
1 out of 2 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.

Powered by Zendesk