我已经在Heroku服务器上部署了Django应用程序。我已经通过Heroku CLI手动推送了没有迁移和数据库的项目。然后,通过Gitlab ci进行推送(在推送之前进行迁移)会在Heroku端给我应用崩溃的错误。我之前遇到过许多“应用程序崩溃”错误,可以通过检查日志来解决。但是这次我不明白是什么问题。 我确定文件已完全推送,并且该应用程序已发布。
这是我的Procfile:
web: gunicorn --pythonpath Code Code.wsgi --log-file -
我的项目位于“代码”文件夹中,而我的Django项目名称为Code。
heroku日志的错误部分:
2019-06-08T08:02:50.549319+00:00 app[api]: Deployed web (c1f5c903bedb) by user arminbehnamnia@gmail.com
2019-06-08T08:02:50.549319+00:00 app[api]: Release v6 created by user arminbehnamnia@gmail.com
2019-06-08T08:02:51.268875+00:00 heroku[web.1]: Restarting
2019-06-08T08:02:51.277247+00:00 heroku[web.1]: State changed from up to starting
2019-06-08T08:02:52.494158+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-06-08T08:02:52.517991+00:00 app[web.1]: [2019-06-08 08:02:52 +0000] [4] [INFO] Handling signal: term
2019-06-08T08:02:52.519983+00:00 app[web.1]: [2019-06-08 08:02:52 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-06-08T08:02:52.529529+00:00 app[web.1]: [2019-06-08 08:02:52 +0000] [10] [INFO] Worker exiting (pid: 10)
2019-06-08T08:02:52.823141+00:00 app[web.1]: [2019-06-08 08:02:52 +0000] [4] [INFO] Shutting down: Master
2019-06-08T08:02:52.958760+00:00 heroku[web.1]: Process exited with status 0
2019-06-08T08:03:09.777009+00:00 heroku[web.1]: Starting process with command `python3`
2019-06-08T08:03:11.647048+00:00 heroku[web.1]: State changed from starting to crashed
2019-06-08T08:03:11.654524+00:00 heroku[web.1]: State changed from crashed to starting
2019-06-08T08:03:11.625687+00:00 heroku[web.1]: Process exited with status 0
.
.
.
2019-06-08T08:17:16.898569+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=makan-system.herokuapp.com request_id=de4fbb8e-cd14-4263-bb6f-a8d0f956a519 fwd="69.55.54.121" dyno= connect= service= status=503 bytes= protocol=https
我的.gitlab-ci.yml文件:
stages:
- test
- build
- push
tests:
image: docker:latest
services:
- docker:dind
stage: test
before_script:
- docker login -u armin_gm -p $PASSWORD registry.gitlab.com
script:
- docker build . -t test_django
- docker ps
- docker run --name=testDjango test_django python /makanapp/Code/manage.py test registration
when: on_success
build:
image: docker:latest
services:
- docker:dind
stage: build
before_script:
- docker login -u armin_gm -p $PASSWORD registry.gitlab.com
script:
- docker build -t registry.gitlab.com/armin_gm/asd_project_98_6 .
- docker push registry.gitlab.com/armin_gm/asd_project_98_6
push_to_heroku:
image: docker:latest
stage: push
services:
- docker:dind
script:
# This is for gitlab
- docker login -u armin_gm -p $PASSWORD registry.gitlab.com
#- docker pull registry.gitlab.com/armin_gm/asd_project_98_6:latest
- docker build . -t push_to_django
- docker ps
# This is for heroku
- docker login --username=arminbehnamnia@gmail.com --password=$AUTH_TOKEN registry.heroku.com
- docker tag push_to_django:latest registry.heroku.com/makan-system/web:latest
- docker push registry.heroku.com/makan-system/web:latest
- docker run --rm -e HEROKU_API_KEY=$AUTH_TOKEN wingrunr21/alpine-heroku-cli container:release web --app makan-system
我的Dockerfile:
# Official Python image
FROM python:latest
ENV PYTHONUNBUFFERED 1
# create root directory for project, set the working directory and move all files
RUN mkdir /makanapp
WORKDIR /makanapp
ADD . /makanapp/
# Web server will listen to this port
EXPOSE 8000
# Install all libraries we saved to requirements.txt file
#RUN apt-get -y update
#RUN apt-get -y install python3-dev python3-setuptools
RUN pip install -r requirements.txt
RUN python ./Code/manage.py makemigrations
RUN python ./Code/manage.py migrate --run-syncdb