本文通过给cloudfoundry添加Django的支持,简要介绍添加Framework的方法.(如何添加Runtime请阅读 http://oldfritters.iteye.com/blog/1867876)
首先,向blobstore中添加Django以及相关的包,方法同前文中添加Python.
其次,添加package
packaging:cf-release/packages/dea_python27/packaging
- # abort script on any command that exit with a non zero value
- set -e
- echo "Setup python2.7.4"
- tar xzvf python/python-2.7.4.tgz
- (
- cd Python-2.7.4
- ./configure --prefix=${BOSH_INSTALL_TARGET}
- make
- make install
- )
- echo "Setup Django"
- tar xzvf python/Django-1.4.5.tar.gz
- (
- cd Django-1.4.5
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
- echo "Setup Setuptools"
- tar xzvf python/setuptools-0.6c11.tar.gz
- (
- cd setuptools-0.6c11
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
- echo "Setup pip"
- tar xzvf python/pip-1.3.1.tar.gz
- (
- cd pip-1.3.1
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
- echo "Setup gunicorn"
- tar xzvf python/gunicorn-0.17.4.tar.gz
- (
- cd gunicorn-0.17.4
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
- echo "Setup mysql-connector-python"
- tar xzvf python/mysql-connector-python-1.0.10.tar.gz
- (
- cd mysql-connector-python-1.0.10
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
- echo c1oudc0w | sudo -S apt-get -y update
- echo c1oudc0w | sudo -S apt-get -y --fix-missing install libmysqlclient-dev
- echo "Setup MySQL-python-1.2.4b4.tar"
- tar xzvf python/MySQL-python-1.2.4b4.tar.gz
- (
- cd MySQL-python-1.2.4b4
- echo c1oudc0w | sudo -S ${BOSH_INSTALL_TARGET}/bin/python setup.py install
- )
spec:cf-release/packages/dea_python27/spec
- ---
- name: dea_python27
- dependencies:
- files:
- - python/python-2.7.4.tgz
- - python/setuptools-0.6c11.tar.gz
- - python/pip-1.3.1.tar.gz
- - python/MySQL-python-1.2.4b4.tar.gz
- - python/mysql-connector-python-1.0.10.tar.gz
- - python/gunicorn-0.17.4.tar.gz
- - python/Django-1.4.5.tar.gz
blob中添加依赖包: cf-release/config/blob.yml
- ---
- python/setuptools-0.6c11.tar.gz:
- object_id: 636b1c0e-d177-45ed-901f-b06e28485a2b
- sha: 8d1ad6384d358c547c50c60f1bfdb3362c6c4a7d
- size: 256862
- python/pip-1.3.1.tar.gz:
- object_id: d86a4778-82ba-420d-9204-5923a71fe7ed
- sha: 9c70d314e5dea6f41415af814056b0f63c3ffd14
- size: 247594
- python/MySQL-python-1.2.4b4.tar.gz:
- object_id: 8b5cf796-9632-4a33-aed9-4ea64845a4fe
- sha: 1801dba46f45a8596d17424bf07a747c7bac841f
- size: 79704
- python/mysql-connector-python-1.0.10.tar.gz:
- object_id: ba10a05a-ca71-41cf-bf5a-3bc0558bd984
- sha: 31d26132f8089b25aed6255b835c8df60fe61c9a
- size: 234122
- python/gunicorn-0.17.4.tar.gz:
- object_id: ff817558-6c7a-426f-861b-492ef38ea2e2
- sha: ca4c95a236fd90dcf46ffa35c150d9564336e150
- size: 372737
- python/python-2.7.4.tgz:
- object_id: 94ec890f-ae43-455c-932d-49aa9d34e462
- sha: 2283858b832fc391b8e96bb600e0b39e52ae97bd
- size: 14489063
- python/Django-1.4.5.tar.gz:
- object_id: 354c918e-fb75-431b-81e4-dacd1b7cbdf6
- sha: 1bfaa4643c6775fbf394137f1533659be45441e7
- size: 7735582
添加runtime支持: cf-release/jobs/cloud_controller/templates/runtimes.yml
- ---
- python27:
- description: Python
- version: "2.7.4"
- executable: /var/vcap/packages/dea_python27/bin/python
- soft_link_folder: python/bin
- soft_link_targets:
- executable: /var/vcap/packages/dea_python27/bin/python
- gunicorn_django: /var/vcap/packages/dea_python27/bin/gunicorn_django
- django: /var/vcap/packages/dea_python27/bin/django-admin.py
- gunicorn: /var/vcap/packages/dea_python27/bin/gunicorn
- gunicorn_paster: /var/vcap/packages/dea_python27/bin/gunicorn_paster
- soft_links:
- executable: python/bin/python
- gunicorn_django: python/bin/gunicorn_django
- django: python/bin/django
- gunicorn: python/bin/gunicorn
- gunicorn_paster: python/bin/gunicorn_paster
- staging: /var/vcap/packages/ruby/bin/ruby stage
- version_output: 2.7.4
- version_flag: "-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'
- debug_modes:
- - run
- - suspend
- status:
- name: current
- series: python27
- category: python
添加Django支持: cf-release/jobs/cloud_controller/templates/django.yml
- ---
- name: django
- runtimes:
- - python27:
- default: true
- detection:
- - manage.py: true
修改代码:cf-release/src/dea/lib/dea/agent.rb
- def stage_app_dir(bits_file, bits_uri, sha1, tgz_file, instance_dir, runtime)
- ......
- FileUtils.rm_f(tgz_file) unless @disable_dir_cleanup
- add_runtime_soft_links instance_dir,runtime if runtime['soft_link_tagets'] && runtime['soft_links'] && runtime['soft_link_folder']
- bind_local_runtime(instance_dir, runtime)
- @logger.debug("Took #{Time.now - start} to stage the app directory")
- true
- end
- #此方法是额外添加的
- def add_runtime_soft_links instance_dir, runtime
- FileUtils.mkdir_p [instance_dir, runtime['soft_link_folder']].join('/')
- runtime['soft_link_targets'].each{|key| FileUtils.ln_s runtime['soft_link_targets'][key], [instance_dir, runtime['soft_links'][key]].join('/') }
- end