Mobile Applicaiton development with IBM Bluemix Kinetise (3)

Continuing from Last time, I will explain how to deploy Bluemix to the Python runtime. Basically, I refer to the [Article] of DeveloperWorks (https://www.ibm.com/developerworks/jp/cloud/library/cl-worldbank-charting-app/).

** 4. Deploy Bluemix to Python runtime ** 4.1. Install the cf command and connect to Bluemix. The procedure is here.

cf api https://api.ng.bluemix.net
cf login -u account-o Organization-s space

4.2. To create a package to push, copy C: \ Users \ hoge \ workspace_env3 \ kinetise to the same directory as bmaakinetaise, and copy the Lib \ site-packages \ rf_alter_api folder of the virtual environment (env3) to the bmaakinetaise folder. I will. This is because rf_alter_api is not available on github. Then create the following files. All work in SJIS.

4.2.1. Requirements.txt describes the modules to be included when deploying the Python runtime. In this file, describe the execution result of Python and pip freeze -l in the virtual environment (env3) whose operation has been confirmed. Then make sure that the version of Python you've used so far is included in python-buildpack / builds / runtimes / on github.

requirements.txt


Python==2.7.10
Django==1.9
django-filter==0.11.0
djangorestframework==3.3.2
drf-extensions==0.2.8
Markdown==2.6.5
wheel==0.24.0
yattag==1.5.2

(Supplement) You can identify the version of Python that is actually used on the console when deploying cf push. If you are having trouble deploying successfully, install the included version and start over from the beginning to avoid complicating problem isolation. For the work in this article, I was initially working with Python 2.7.11, but the buildpack only included 2.7.10, so I'm starting over (as of December 2015). Also, if the file name is incorrect (requirements instead of requirements, that is, the trailing s is missing) such as requirement.txt, the cf command will work, but an error (Directory'.' Is not installable. Please note that it will be File'setup.py' not found.). In addition, it will be deployed normally even if there is no description of Python == 2.7.10. It is simply written as a memo.

4.2.2. bluemix will be charged in GB hours. In manifest.yml, specify the amount of memory to allocate to the python runtime to deploy and the python buildpack.

manifest.yml


---
applications:
- name: bmaakinetise
  memory: 512M
  command: bash run.sh
  buildpack:  https://github.com/cloudfoundry/python-buildpack

(Supplement) Since run.sh is described in bash shell, it is command: bash run.sh. command: sh run.sh also works because it is declared as #! / Bin / bash inside run.sh, but I think that it is better to unify with bash if it is bash.

4.2.3. In run.sh, specify PORT and describe the shell to be executed at the time of deployment. In this case, the rf_alter_api provided by kinetise is explicitly included in the PYTHONPATH to prevent the deployment from terminating in error. The path you are adding is based on the deployment error (module not found) message. I think it will be helpful as a way to use custom modules that cannot be installed with pip.

run.sh


#!/bin/bash
PYTHONPATH="/home/vcap/app/kinetise/:$PYTHONPATH"
export PYTHONPATH
if [ -z "$VCAP_APP_PORT" ];
then SERVER_PORT=5000;
else SERVER_PORT="$VCAP_APP_PORT";
fi
echo port is $SERVER_PORT
python manage.py runserver --noreload 0.0.0.0:$SERVER_PORT

(Supplement) The Python runtime may work normally even if there is no description of PYTHONPATH, but it is explicitly described to isolate the problem.

4.2.4 The bmaakinetise folder looks like this:

Command log


 C:\Users\hoge\workspace_env3\bmaakinetise directory

2015/12/18  19:06    <DIR>          .
2015/12/18  19:06    <DIR>          ..
2015/12/18  15:23               436 .project
2015/12/18  15:23               604 .pydevproject
2015/12/18  18:25    <DIR>          .settings
2015/12/18  18:25    <DIR>          comments
2015/12/18  17:31            38,912 db.sqlite3
2015/12/18  18:25    <DIR>          kinetise
2015/12/18  15:23               251 manage.py
2015/11/23  22:19               137 manifest.yml
2015/12/18  18:56               151 requirement.txt
2015/11/23  19:41               186 run.sh

4.3. Deploy with the cf command.

Command log


(env3) C:\Users\hoge\workspace_env3\bmaakinetise>cf push  --no-start
Using manifest file C:\Users\hoge\workspace_env3\bmaakinetise\manifest.yml

Creating app bmaakinetise in org [email protected] / space dev as [email protected]...
OK

Creating route bmaakinetise.mybluemix.net...
OK

Binding bmaakinetise.mybluemix.net to bmaakinetise...
OK

Uploading bmaakinetise...
Uploading app files from: C:\Users\hoge\workspace_env3\bmaakinetise
Uploading 60.7K, 32 files
Done uploading
OK

4.4. Launch the deployed python runtime on the bluemix dashboard and do the same with POSTMAN using the URL assigned by bluemix, as in Last time I will confirm.

That concludes our discussion of deploying Bluemix to the Python runtime. Next, we will explain the development and build of Mobile Application in Kinetise.

Recommended Posts

Mobile Applicaiton development with IBM Bluemix Kinetise (3)
Mobile Applicaiton development with IBM Bluemix Kinetise (2)
Mobile Applicaiton development with IBM Bluemix Kinetise (1)
Virtualize (isolate) IBM i python development environment with chroot
Development digest with Django
Bluemix Python Microservices Development