When building and running the docker image locally the flask app starts successfully and everything works as expected.
However when deployed to Heroku the app crashes and exists right away.
Dockerfile
FROM python:3.9.4
ADD . /blockchain-py
WORKDIR /blockchain-py
RUN pip3 install -r requirements.txt
EXPOSE 5000
ENTRYPOINT [ "python3" ]
CMD ["server.py"]
heroku.yml
build:
docker:
web: Dockerfile
I have also tried adding the Procfile (to no avail)
web: gunicorn --bind 0.0.0.0:${PORT} wsgi server:app --log-file=-
Error Message from heroku logs:
2021-05-27T08:01:39.206659+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-27T08:01:55.599292+00:00 heroku[web.1]: Starting process with command `python3`
2021-05-27T08:01:58.310259+00:00 heroku[web.1]: Process exited with status 0
2021-05-27T08:01:58.390600+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-27T08:01:58.409515+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-27T08:02:18.130426+00:00 heroku[web.1]: Starting process with command `python3`
2021-05-27T08:02:21.371471+00:00 heroku[web.1]: Process exited with status 0
2021-05-27T08:02:21.466571+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-27T08:02:23.139469+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=blockchain-server-py.herokuapp.com request_id=69be5144-0665-4bc6-8616-e15b34ea370f fwd="95.91.235.135" dyno= connect= service= status=503 bytes= protocol=https
2021-05-27T08:02:23.845517+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=blockchain-server-py.herokuapp.com request_id=7262f8a8-264a-47cb-9cfa-f67d27ee4470 fwd="95.91.235.135" dyno= connect= service= status=503 bytes= protocol=https
server.py
import os
from typing import Dict, Union
from server.response import Response
from blockchain import *
from flask import Flask, request, send_from_directory
from flask_cors import CORS
from server.responseHelpers import get_message, get_missing_fields, get_serializable_block, get_serializable_transaction, has_all_required_fields, jsonify_chain
from server.models.statusCodes import HttpStatusCodes
from server.requestHelpers import get_param
from core.blockchainFactory import BlockchainFileStorageFactory
app = Flask(__name__)
CORS(app)
blockchain = Blockchain(BlockchainFileStorageFactory)
host = '0.0.0.0'
port = int(os.environ.get('PORT', 5000))
@app.route('/', methods=[HttpStatusCodes.GET])
def get_ui():
return send_from_directory('ui/templates', 'node.html')
# ... some more routes
print('Starting Server...')
if __name__ == '__main__':
app.run(host, port, debug=True)
Use upper case when accessing env variables ( PORT
)
port = int(os.environ.get("PORT", 5000))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.