HackerSpace-PESU / Best11-Fantasycricket

Predicting the Best 11 for a fantasy cricket game
GNU Affero General Public License v3.0
24 stars 17 forks source link

Create DOCKERFILE #53

Closed scientes closed 3 years ago

scientes commented 3 years ago

Description

Creates a dockerfile for deployment

Fixes #39

Tick the appropriate choice (Delete the rest):

scientes commented 3 years ago

I tested it locally but i couldnt get the app to work properly, but i dont think thats an docker issue:

2021-01-03T19:55:08.313840645Z Checking for script in /app/prestart.sh
2021-01-03T19:55:08.313884079Z Running script /app/prestart.sh
2021-01-03T19:55:08.313890953Z Running inside /app/prestart.sh, you could add migrations to this file, e.g.:
2021-01-03T19:55:08.313896871Z 
2021-01-03T19:55:08.313901166Z #! /usr/bin/env bash
2021-01-03T19:55:08.313905480Z 
2021-01-03T19:55:08.313909527Z # Let the DB start
2021-01-03T19:55:08.313913646Z sleep 10;
2021-01-03T19:55:08.313917548Z # Run migrations
2021-01-03T19:55:08.313922020Z alembic upgrade head
2021-01-03T19:55:08.313925963Z 
2021-01-03T19:55:08.655198169Z [2021-01-03 19:55:08 +0000] [1] [INFO] Starting gunicorn 20.0.4
2021-01-03T19:55:08.655649192Z [2021-01-03 19:55:08 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
2021-01-03T19:55:08.655657526Z [2021-01-03 19:55:08 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
2021-01-03T19:55:08.657768161Z [2021-01-03 19:55:08 +0000] [8] [INFO] Booting worker with pid: 8
2021-01-03T19:55:15.644557764Z [2021-01-03 19:55:15 +0000] [8] [INFO] Started server process [8]
2021-01-03T19:55:15.644585900Z [2021-01-03 19:55:15 +0000] [8] [INFO] Waiting for application startup.
2021-01-03T19:55:15.644797964Z [2021-01-03 19:55:15 +0000] [8] [INFO] Application startup complete.
2021-01-03T19:55:22.655130514Z {"loglevel": "info", "workers": 1, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120, "keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": 1, "host": "0.0.0.0", "port": "80"}
2021-01-03T19:55:22.655161337Z 10.0.0.2:41112 - "GET / HTTP/1.1" 200
2021-01-03T19:55:29.808990872Z 10.0.0.2:41126 - "POST / HTTP/1.1" 302
2021-01-03T19:55:29.832533708Z 10.0.0.2:41126 - "GET /playing11?team1=New+Zealand&team2=Pakistan HTTP/1.1" 200
2021-01-03T19:55:29.937336204Z 10.0.0.2:41126 - "GET /favicon.ico HTTP/1.1" 404
2021-01-03T19:56:06.910789711Z 10.0.0.2:41140 - "POST /playing11?team1=New%20Zealand&tea2=Pakistan&file=Pakistan%20tour%20of%20New%20Zealand%202020-212nd%20Test&type=TEST HTTP/1.1" 307
2021-01-03T19:56:07.441429362Z Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
2021-01-03T19:56:07.441453274Z BrokenPipeError: [Errno 32] Broken pipe
2021-01-03T19:57:27.009916209Z 10.0.0.2:41140 - "POST /results?file=Pakistan+tour+of+New+Zealand+2020-212nd+Test HTTP/1.1" 500
2021-01-03T19:57:27.014396537Z [2021-01-03 19:57:27 +0000] [8] [ERROR] Exception in ASGI application
2021-01-03T19:57:27.014413045Z Traceback (most recent call last):
2021-01-03T19:57:27.014418822Z   File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
2021-01-03T19:57:27.014424486Z     result = await app(self.scope, self.receive, self.send)
2021-01-3T19:57:27.014429039Z   File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
2021-01-03T19:57:27.014446246Z     return await self.app(scope, receive, send)
2021-01-03T19:57:27.014451232Z   File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 190, in __call__
2021-01-03T19:57:27.014455529Z     await super().__call__(scope, receive, send)
2021-01-03T19:57:27.014459494Z   File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
2021-01-03T19:57:27.014464064Z     await self.middleware_stack(scope, receive, send)
2021-01-03T19:57:27.014468150Z   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
2021-01-03T19:57:27.014473041Z     raise exc from None
2021-01-03T19:57:27.014477547Z   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
2021-01-03T19:57:27.014482413Z     await self.app(scope, receive, _send)
2021-01-03T19:57:27.014486602Z   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
2021-01-03T19:57:27.014491770Z     raise exc from None
2021-01-03T19:57:27.014495977Z   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
2021-01-03T19:57:27.014500250Z     await self.app(scope, receive, sender)
2021-01-03T19:57:27.014504076Z   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
2021-01-03T19:57:27.014508490Z     await route.handle(scope, receive, send)
2021-01-03T19:57:27.014512458Z   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
2021-01-03T19:57:27.014517565Z     await self.app(scope, receive, send)
2021-01-03T19:57:27.014521803Z   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
2021-01-03T19:57:27.014526354Z     response = await func(request)
2021-01-03T19:57:27.014530834Z   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 188, in app
2021-01-03T19:57:27.014535464Z     raw_response = await run_endpoint_function(
2021-01-03T19:57:27.014540328Z   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 137, in run_endpoint_function
2021-01-03T19:57:27.014544784Z     return await run_in_threadpool(dependant.call, **values)
2021-01-03T19:57:27.014549218Z   File "/usr/local/lib/python3.8/site-packages/starlette/concurrency.py", line 34, in run_in_threadpool
2021-01-03T19:57:27.014554712Z     return await loop.run_in_executor(None, func, *args)
2021-01-03T19:57:27.014559280Z   File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
2021-01-03T19:57:27.014563441Z     result = self.fn(*self.args, **self.kwargs)
2021-01-03T19:57:27.014567381Z   File "/app/main.py", line 119, in result
2021-01-03T19:57:27.014571464Z     team_match = t_d.team()
2021-01-03T19:57:27.014580992Z   File "/app/fantasy_cricket/team.py", line 114, in team
2021-01-03T19:57:27.014585500Z     file_handler = open(self.path)
2021-01-03T19:57:27.014589865Z FileNotFoundError: [Errno 2] No such file or directory: 'fantasy_cricket/data/Pakistan tour of New Zealand 2020-212nd Test.json'
roysti10 commented 3 years ago

I tested it locally but i couldnt get the app to work properly, but i dont think thats an docker issue:

Shouldnt the scrapy application have run too? It hasnt run the scrapy background task in your output

If this was tested in the docker container, Then Im guessing scrapy.cfg was not found

There seems to be a error in mine as well, Ill put a commit in some time for this

roysti10 commented 3 years ago

I had built this docker file last night Haven't had the chance to test it yet though

Do check and tell if we can use this?

P.s fantasy_cricket and main.py is inside the app folder (didnt wanna push until tested)

FROM python:3.7 as build

WORKDIR .

COPY ./requirements.txt ./requirements.txt

RUN pip install -r requirements.txt

COPY ./app /app
COPY ./cralwer /cralwer
COPY ./scrapy.cfg /scrapy.cfg

ENTRYPOINT ["uvicorn", "app.main:app"]
roysti10 commented 3 years ago

Could you pull and try again?

scientes commented 3 years ago

ill change my dockerfile, hte reson mine looks a little different is that ill try to optimize for image size and im using the goto production image for fastapi (uvicorn is mostly used in development gunicorn in production, because gunicorn could handle multiple processes and hencforth cores)

scientes commented 3 years ago

Due to breaking changes on the target branch ill close and make a new merge request

scientes commented 3 years ago

I tested it locally but i couldnt get the app to work properly, but i dont think thats an docker issue:

Shouldnt the scrapy application have run too? It hasnt run the scrapy background task in your output

If this was tested in the docker container, Then Im guessing scrapy.cfg was not found

There seems to be a error in mine as well, Ill put a commit in some time for this

yeah gunicorn only logs errors and access related stuff so print commands are not shown in output, because its more thought of for production

scientes commented 3 years ago

new merge #56