在Minishift V1.28.0中运行Django2:创建模板和s2i源代码
首先
根据之前的文章「在minishift V1.28.0上运行Django2①」中观察到的结果,以及根据「在Win10环境下尝试Django2的REST API」创建的项目,我们将开始制作s2i镜像。
-
- Win10環境でDjango2のREST APIを試してみる
-
- minishift V1.28.0でDjango2を動かす①:テンプレート確認
-
- minishift V1.28.0でDjango2を動かす②:テンプレート&s2iソースの作成
-
- minishift V1.28.0でDjango2を動かす③:s2iソースの修正&ビルド
-
- minishift V1.28.0でDjango2を動かす④:残課題
-
- minishift V1.28.0でnginx+gunicorn+Django2を動かす
-
- minishift V1.28.0でnginx+gunicorn+Django2を動かす。あっcreatesuperuser忘れてた(笑)
- openshiftに対応するためのDjango2コーディング時に気を付けるべき点
查看 OpenShift 上 django-ex.git 的源代码
首先,您可以克隆GitHub上的示例存储库(https://github.com/openshift/django-ex.git),将其带到本地。尽管我已经简化了一部分内容,但大致是这个结构。
├─conf
├─openshift
│ ├─scripts
│ └─templates
├─project
│ ├─__init__.py
│ ├─database.py
│ ├─settings.py
│ └─urls.py
├─welcome
│ ├─migrations
│ └─templates
│ └─welcome
├─manage.py
├─requirements.txt
└─wsgi.py
conf的内容是查看提交时的注释,因为是为Gunicorn进行配置的,所以保持不变。
openshift内部是一个在创建openshift模板时使用的json,因此保持不变。
在项目目录中包含了Django的源代码等内容,
例如welcome等是包含静态模板的。
准备 Django2的s2i git。
因此,將project和welcome完全刪除,並使用在”在Win10環境下嘗試Django2的REST API”中創建的Django2項目進行調整,感覺上應該可以進行微調。
├─conf
├─openshift
│ ├─scripts
│ └─templates
├─restapi
│ ├─migrations
│ ├─__init__.py
│ ├─admin.py
│ ├─apps.py
│ ├─models.py
│ ├─tests.py
│ └─views.py
├─sample
│ ├─__init__.py
│ ├─settings.py
│ ├─urls.py
│ └─wsgi.py
├─manage.py
└─requirements.txt
哎呀,原来 wsgi.py 不在根目录下。我会把它从 sample 目录下复制到根目录下。
├─conf
├─openshift
│ ├─scripts
│ └─templates
├─restapi
│ ├─migrations
│ ├─__init__.py
│ ├─admin.py
│ ├─apps.py
│ ├─models.py
│ ├─tests.py
│ └─views.py
├─sample
│ ├─__init__.py
│ ├─settings.py
│ ├─urls.py
│ └─wsgi.py
├─manage.py
├─requirements.txt
└─wsgi.py ※sample配下のをCopy
requirements.txt的结构简单地如下所示。
django==2.1.4
djangorestframework
django-filter
gunicorn
将此推送至GitLab。
在Minishift上挑战Django2
変数初期値設定値Namedjango-examplesampleGit Repository URLhttps://github.com/sclorg/django-ex.githttps://gitlab.com/imp555/django2.gittemplatedjango-exampledjango2-exampleappdjango-exampledjango2-example
创建
探寻Pod的构建过程
点击Builds选项,然后再点击最新构建的#1,接着点击Logs标签页。
Cloning "https://gitlab.com/imp555/django2.git " ...
Commit: 0cef8fa6301a3308127066fa5b6198781ff0fa2a (update README.md)
Author: imp555 <imp555@nethome.ne.jp>
Date: Sat Dec 29 00:19:30 2018 +0900
Using 172.30.1.1:5000/openshift/python@sha256:091d56e3ab03d52ef0ffac4b88e7e1fa24ea0243bfd05297882c12ff8a0ba1df as the s2i builder image
---> Installing application source ...
---> Installing dependencies ...
Collecting django==2.1.4 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/fd/9a/0c028ea0fe4f5803dda1a7afabeed958d0c8b79b0fe762ffbf728db3b90d/Django-2.1.4-py3-none-any.whl (7.3MB)
Collecting djangorestframework (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/99/0b/d37a5a96c5d301e23adcabcc2f3fa659fb34e6308590f95ebb50cdbe98a1/djangorestframework-3.9.0-py2.py3-none-any.whl (924kB)
Collecting django-filter (from -r requirements.txt (line 3))
Downloading https://files.pythonhosted.org/packages/6a/8b/8517167a0adc45ce94d0873efb9487dd4cdeff7e10f96e837ad3d58f5837/django_filter-2.0.0-py3-none-any.whl (69kB)
Collecting gunicorn (from -r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/8c/da/b8dd8deb741bff556db53902d4706774c8e1e67265f69528c14c003644e6/gunicorn-19.9.0-py2.py3-none-any.whl (112kB)
Collecting pytz (from django==2.1.4->-r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB)
Installing collected packages: pytz, django, djangorestframework, django-filter, gunicorn
Successfully installed django-2.1.4 django-filter-2.0.0 djangorestframework-3.9.0 gunicorn-19.9.0 pytz-2018.7
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
---> Collecting Django static files ...
WARNING: could not run 'manage.py collectstatic'. To debug, run:
$ python ./manage.py collectstatic --noinput
Ignore this warning if you're not serving static files with Django.
Running post commit hook ...
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.
----------------------------------------------------------------------
Ran 1 test in 0.188s
OK
Destroying test database for alias 'default'...
Pushing image 172.30.1.1:5000/django2/sample:latest ...
Pushed 0/10 layers, 1% complete
Pushed 1/10 layers, 10% complete
Push successful
点击应用程序>Pods,然后点击正在运行的Pods,再点击日志选项卡。
---> Migrating database ...
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
---> Serving application with gunicorn (wsgi) ...
[2018-12-28 15:27:15 +0000] [1] [INFO] Starting gunicorn 19.9.0
[2018-12-28 15:27:15 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-12-28 15:27:15 +0000] [1] [INFO] Using worker: sync
[2018-12-28 15:27:15 +0000] [35] [INFO] Booting worker with pid: 35
[2018-12-28 15:27:15 +0000] [36] [INFO] Booting worker with pid: 36
[2018-12-28 15:27:15 +0000] [37] [INFO] Booting worker with pid: 37
[2018-12-28 15:27:15 +0000] [38] [INFO] Booting worker with pid: 38
172.17.0.1 - - [29/Dec/2018:00:27:21 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+" Not Found: /
172.17.0.1 - - [29/Dec/2018:00:27:31 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
Not Found: /
172.17.0.1 - - [29/Dec/2018:00:27:41 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
172.17.0.1 - - [29/Dec/2018:00:27:49 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
172.17.0.1 - - [29/Dec/2018:00:27:51 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
172.17.0.1 - - [29/Dec/2018:00:27:59 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
172.17.0.1 - - [29/Dec/2018:00:28:01 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
172.17.0.1 - - [29/Dec/2018:00:28:09 +0900] "GET / HTTP/1.1" 404 2048 "-" "kube-probe/1.11+"
Not Found: /
[2018-12-28 15:28:09 +0000] [1] [INFO] Handling signal: term
[2018-12-29 00:28:09 +0900] [37] [INFO] Worker exiting (pid: 37)
[2018-12-29 00:28:09 +0900] [35] [INFO] Worker exiting (pid: 35)
[2018-12-29 00:28:09 +0900] [38] [INFO] Worker exiting (pid: 38)
[2018-12-29 00:28:09 +0900] [36] [INFO] Worker exiting (pid: 36)
[2018-12-28 15:28:11 +0000] [1] [INFO] Shutting down: Master
看起来似乎是在进行健康检查……。
奔溃循环回退(´・ω・`) : 崩溃循环回退
进入应用程序 > Pods,点击运行中的Pod,然后点击事件选项卡。
如果不返回200 OK作为对此的响应,看起来 readinessProbe 或 livenessProbe 的检查未通过将导致处于 Unhealthy 状态哦 (´・ω・`)