前言:
????? 最近由于项目需要,建立了一个基于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:
class="shell">bundle install bundle exec ./bin/simple_blobstore_server
? ? ?向本地blobstore中添加python的安装包,执行以下脚本以完成添加
require 'base64' require 'httpclient' require 'multi_json' require "atmos" require "uri" file_path = '/Users/leon/cf-release/final_builds/packages/python/1/python/python-2.7.4.tgz' #修改成你的文件path SHARE_URL_EXP = '1893484800' @atmos_options = {:unsupported => true} @atmos_options[:uid] = 'bb6a0c89ef4048a8a0f814e25385d1c5/user1' @atmos_options[:url] = 'http://10.0.0.211:9999' @atmos_options[:secret] = 'secret' @endpoint = 'http://10.0.0.211:9999' @bucket = '' @client = HTTPClient.new @bucket = @options && @options[:bucket] || "resources" @headers = {} user = 'admin' password = 'admin' if user && password @headers["Authorization"] = "Basic " + Base64.encode64("#{user}:#{password}").strip end def url(id=nil) ["#{@endpoint}/#{@bucket}", id].compact.join("/") end def create_file(id, file) @client.post(url(id), {:content => file}, @headers).content end def encode_object_id(object_id) hash_string = "GET\n/rest/objects/#{object_id}\n#{@atmos_options[:uid]}\n#{SHARE_URL_EXP}" secret = Base64.decode64(@atmos_options[:secret]) sig = HMAC::SHA1.digest(secret, hash_string) signature = Base64.encode64(sig.to_s).chomp json = MultiJson.encode({:oid => object_id, :sig => signature}) URI::escape(Base64.encode64(json)) end file = File.open(file_path,'r:utf-8') oid = create_file(nil, file) puts oid puts Digest::SHA1.file(file_path).hexdigest puts file.size
?
2.修改本地cf的final.yml使用本地blobstore
--- final_name: appcloud min_cli_version: 1.0.3 blobstore: provider: simple options: endpoint: http://10.0.0.201:9999 #这里填写simple_blobstore_server的IP blobstore_options: deprecated
?? ? 创建private.yml???
--- blobstore: simple: user: admin password: admin
? blob.yml中添加
python/python-2.7.4.tgz: object_id: f6ffff96-a78a-4bd2-b86d-45b7e28e73e0 sha: 2283858b832fc391b8e96bb600e0b39e52ae97bd size: 14489063
cloud_controller中添加python
? ?cf-release/jobs/cloud_controller/templates/runtimes.yml
--- python27: description: Python 2.7.4 version: 2.7.4 executable: /var/vcap/packages/dea_python27/bin/python2.7 staging: /var/vcap/packages/ruby/bin/ruby stage version_output: 2.7.4 version_flag: "python -c 'import platform; print platform.python_version()' environment: PATH: /var/vcap/packages/ruby/bin:/var/vcap/packages/dea_python27/bin:/var/vcap/packages/imagemagick/bin:$PATH 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' status: name: current series: python27 category: python
??cf-release/jobs/cloud_controller/spec
- dea_python27
?? cf-release/jobs/dea/spec
- dea_python27
? ?cf-release/packages中添加dea_python27目录
????? dea_python27目录中创建文件packaging , spec???
??? packaging
# abort script on any command that exit with a non zero value set -e tar xzf python/python-2.7.4.tgz ( cd Python-2.7.4 ./configure --prefix=${BOSH_INSTALL_TARGET} make make install )
? ? spec
--- name: dea_python27 dependencies: files: - python/python-2.7.4.tgz
?
修改src
?????? cf-release/src/dea/config/dea.yml中添加???
python27: executable: /var/vcap/packages/dea_python27/bin/python2.7#python version: 2.7.4 version_flag: python -c 'import platform; print platform.python_version()' environment:
?4.创建修改后的release,上传,部署
bosh create release –force bosh upload release dev_releases/envcloud-131.1.yml bosh deployment new-cf.yml bosh deploy
?