给基于bosh安装的cloudfoundry添加python支持

前言:

      最近由于项目需要,建立了一个基于cloudfoundry的PaaS云,由于基于bosh安装的cloudfoundry官方代码中未提供对python的支持,所以就必须自己实现了,也就有了本文, 至于使用Django的用户,请参照添加python的方法添加Django.


  1.在blobstore中添加python的安装包

      这里,我选择了建立一个本地的simple_blobstore_proxy.
      code: https://github.com/yudai/simple_blobstore_proxy
     启动simple_blobstore_proxy:

Shell代码   收藏代码
  1. bundle install  
  2. bundle exec ./bin/simple_blobstore_server  

     向本地blobstore中添加python的安装包,执行以下脚本以完成添加

Ruby代码   收藏代码
  1. require 'base64'  
  2. require 'httpclient'  
  3. require 'multi_json'  
  4. require "atmos"  
  5. require "uri"  
  6.   
  7. file_path = '/Users/leon/cf-release/final_builds/packages/python/1/python/python-2.7.4.tgz' #修改成你的文件path  
  8.   
  9. SHARE_URL_EXP = '1893484800'  
  10. @atmos_options = {:unsupported => true}  
  11. @atmos_options[:uid] = 'bb6a0c89ef4048a8a0f814e25385d1c5/user1'  
  12. @atmos_options[:url] = 'http://10.0.0.211:9999'  
  13. @atmos_options[:secret] = 'secret'  
  14. @endpoint = 'http://10.0.0.211:9999'  
  15. @bucket = ''  
  16. @client = HTTPClient.new  
  17. @bucket = @options && @options[:bucket] || "resources"  
  18. @headers = {}  
  19. user = 'admin'  
  20. password = 'admin'  
  21.   
  22. if user && password  
  23.   @headers["Authorization"] = "Basic " + Base64.encode64("#{user}:#{password}").strip  
  24. end  
  25.   
  26. def url(id=nil)  
  27.   ["#{@endpoint}/#{@bucket}", id].compact.join("/")  
  28. end  
  29.   
  30. def create_file(id, file)  
  31.   @client.post(url(id), {:content => file}, @headers).content  
  32. end  
  33.   
  34. def encode_object_id(object_id)  
  35.   hash_string = "GET\n/rest/objects/#{object_id}\n#{@atmos_options[:uid]}\n#{SHARE_URL_EXP}"  
  36.   secret = Base64.decode64(@atmos_options[:secret])  
  37.   sig = HMAC::SHA1.digest(secret, hash_string)  
  38.   signature = Base64.encode64(sig.to_s).chomp  
  39.   json = MultiJson.encode({:oid => object_id, :sig => signature})  
  40.   URI::escape(Base64.encode64(json))  
  41. end  
  42.   
  43. file = File.open(file_path,'r:utf-8')  
  44. oid = create_file(nil, file)  
  45.   
  46. puts  oid  
  47. puts  Digest::SHA1.file(file_path).hexdigest  
  48. puts  file.size  

 

2.修改本地cf的final.yml使用本地blobstore

Yml代码   收藏代码
  1. ---  
  2. final_name: appcloud  
  3. min_cli_version: 1.0.3  
  4. blobstore:  
  5.   provider: simple  
  6.   options:  
  7.     endpoint: http://10.0.0.201:9999  #这里填写simple_blobstore_server的IP  
  8. blobstore_options: deprecated  

     创建private.yml   

Yml代码   收藏代码
  1. ---  
  2. blobstore:  
  3.   simple:  
  4.     user: admin  
  5.     password: admin  

  blob.yml中添加

Shell代码   收藏代码
  1. python/python-2.7.4.tgz:  
  2.   object_id: f6ffff96-a78a-4bd2-b86d-45b7e28e73e0  
  3.   sha: 2283858b832fc391b8e96bb600e0b39e52ae97bd  
  4.   size: 14489063  

cloud_controller中添加python
   cf-release/jobs/cloud_controller/templates/runtimes.yml

Yml代码   收藏代码
  1. ---  
  2. python27:  
  3.   description: Python 2.7.4  
  4.   version: 2.7.4  
  5.   executable: /var/vcap/packages/dea_python27/bin/python2.7  
  6.   staging: /var/vcap/packages/ruby/bin/ruby stage  
  7.   version_output: 2.7.4  
  8.   version_flag: "python -c 'import platform; print platform.python_version()'  
  9.   environment:  
  10.     PATH: /var/vcap/packages/ruby/bin:/var/vcap/packages/dea_python27/bin:/var/vcap/packages/imagemagick/bin:$PATH  
  11.     LD_LIBRARY_PATH: '/var/vcap/packages/mysqlclient/lib/mysql:/var/vcap/packages/sqlite/lib:/var/vcap/packages/libpq/lib:/var/vcap/packages/imagemagick/lib:$LD_LIBRARY_PATH'  
  12.   status:  
  13.     name: current  
  14.   series: python27  
  15.   category: python  

  cf-release/jobs/cloud_controller/spec

Spec代码   收藏代码
  1. - dea_python27  

   cf-release/jobs/dea/spec

Spec代码   收藏代码
  1. - dea_python27  

   cf-release/packages中添加dea_python27目录
      dea_python27目录中创建文件packaging , spec   
    packaging

Packaging代码   收藏代码
  1. # abort script on any command that exit with a non zero value  
  2. set -e  
  3.   
  4. tar xzf python/python-2.7.4.tgz  
  5. (  
  6.   cd Python-2.7.4  
  7.   ./configure --prefix=${BOSH_INSTALL_TARGET}   
  8.   make  
  9.   make install  
  10. )  

    spec

Spec代码   收藏代码
  1. ---  
  2. name: dea_python27  
  3. dependencies:  
  4. files:  
  5. - python/python-2.7.4.tgz  

 
修改src
       cf-release/src/dea/config/dea.yml中添加   

Yml代码   收藏代码
  1. python27:  
  2.     executable: /var/vcap/packages/dea_python27/bin/python2.7#python  
  3.     version: 2.7.4  
  4.     version_flag: python -c 'import platform; print platform.python_version()'  
  5. environment:  

 4.创建修改后的release,上传,部署

Shell代码   收藏代码
  1. bosh create release –force  
  2. bosh upload release dev_releases/envcloud-131.1.yml  
  3. bosh deployment new-cf.yml  
  4. bosh deploy 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值