From 69b621a6439748fdecfb5ec43f2ed9245b14cb93 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Mon, 27 May 2019 22:13:10 -0400 Subject: [PATCH] Python recipe --- attributes/python.rb | 3 +++ recipes/python.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 attributes/python.rb create mode 100644 recipes/python.rb diff --git a/attributes/python.rb b/attributes/python.rb new file mode 100644 index 0000000..5d8bcf3 --- /dev/null +++ b/attributes/python.rb @@ -0,0 +1,3 @@ +default['python']['env_path'] = "/opt/theta42/#{node['app']['name']}/env/python" +default['python']['version'] = '3.6' +default['python']['pip_requirements_path'] = 'requirements.txt' diff --git a/recipes/python.rb b/recipes/python.rb new file mode 100644 index 0000000..12843b4 --- /dev/null +++ b/recipes/python.rb @@ -0,0 +1,42 @@ +# +# Cookbook:: django-bakend +# Recipe:: default +# +# Copyright:: 2019, The Authors, All Rights Reserved. + +unless node['python']['working-dir'][0] == '/' + node.override['python']['working-dir'] = "#{node['working-dir']}/#{node['python']['working-dir']}" +end + + +apt_repository 'Python apt repo' do + uri 'ppa:deadsnakes/ppa' + repo_name 'ppa-deadsnakes' + deb_src true + action :add +end + +apt_update + +[ + "python#{node['python']['version']}", + "python#{node['python']['version']}-dev", + "python#{node['python']['version'][0]}-pip", + +].each do |pkg| + apt_package pkg +end + +execute 'Install virtual' do + command "pip#{node['python']['version'][0]} install virtualenv" +end + +bash 'Install python requirements file' do + # user 'root' + # cwd '/mydir' + code <<~EOH + virtualenv #{node['python']['env_path']} + source #{node['python']['env_path']}/bin/activate + pip install -r #{node['python']['working-dir']}/#{node['python']['pip_requirements_path']} + EOH +end