Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create container #20

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Create container #20

wants to merge 10 commits into from

Conversation

eduardocorrearaujo
Copy link
Collaborator

This PR aims to solve issue #18.

I also make some changes on the dashboard:

  • Add the Q2 of 2022 in the scatter plot comparing the cases and hospitalizations in Geneva;
  • I change the map plot in the clustering section to a bokeh version, because the bokeh version allows the user to hover over the map and see the name of the canton and the exact value of the correlation. That's the new plot:
    Captura de Tela 2022-10-03 às 15 50 58

About the container: The docker version was taking too long to run on my local machine, and I wasn't able to test it. But, I had the same problem trying to run the streamit-template, so maybe it's a problem in my personal machine. So, please, try to run it on your machine and let me know if you have any problem.

To create the new files, I used as reference the Dockerfile in the streamlit-template repo and this tutorial from docker: https://www.docker.com/blog/how-to-dockerize-your-python-applications/

@fccoelho
Copy link
Contributor

fccoelho commented Oct 4, 2022

Please build the container as indicated in the updated README, @eduardocorrearaujo .

The container should build normally it takes a while the first time due to the downloads.

@eduardocorrearaujo
Copy link
Collaborator Author

eduardocorrearaujo commented Oct 7, 2022

I am receiving this error when trying run the docker compose:

#0 27.99   • Installing xarray-einstats (0.3.0)
#0 29.62 
#0 29.62   CalledProcessError
#0 29.62 
#0 29.62   Command '['/root/.cache/pypoetry/virtualenvs/covid-ch-dashboard-9TtSrW0h-py3.9/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/root/.cache/pypoetry/virtualenvs/covid-ch-dashboard-9TtSrW0h-py3.9', '--no-deps', '/root/.cache/pypoetry/artifacts/9e/56/26/0b583bc07db61e0fc88eb894bb554daa81e2905ddbcda92ff923c5e3fe/Fiona-1.8.21.tar.gz']' returned non-zero exit status 1.
#0 29.62 
#0 29.62   at /usr/local/lib/python3.9/subprocess.py:528 in run
#0 29.68        524│             # We don't call process.wait() as .__exit__ does that for us.
#0 29.68        525│             raise
#0 29.68        526│         retcode = process.poll()
#0 29.68        527│         if check and retcode:
#0 29.68     →  528│             raise CalledProcessError(retcode, process.args,
#0 29.68        529│                                      output=stdout, stderr=stderr)
#0 29.68        530│     return CompletedProcess(process.args, retcode, stdout, stderr)
#0 29.68        531│ 
#0 29.68        532│ 
#0 29.68 
#0 29.68 The following error occurred when trying to handle this error:
#0 29.68 
#0 29.68 
#0 29.68   EnvCommandError
#0 29.68 
#0 29.68   Command ['/root/.cache/pypoetry/virtualenvs/covid-ch-dashboard-9TtSrW0h-py3.9/bin/python', '-m', 'pip', 'install', '--use-pep517', '--disable-pip-version-check', '--prefix', '/root/.cache/pypoetry/virtualenvs/covid-ch-dashboard-9TtSrW0h-py3.9', '--no-deps', '/root/.cache/pypoetry/artifacts/9e/56/26/0b583bc07db61e0fc88eb894bb554daa81e2905ddbcda92ff923c5e3fe/Fiona-1.8.21.tar.gz'] errored with the following return code 1, and output: 
#0 29.68   Processing /root/.cache/pypoetry/artifacts/9e/56/26/0b583bc07db61e0fc88eb894bb554daa81e2905ddbcda92ff923c5e3fe/Fiona-1.8.21.tar.gz
#0 29.68     Installing build dependencies: started
#0 29.68     Installing build dependencies: finished with status 'done'
#0 29.68     Getting requirements to build wheel: started
#0 29.68     Getting requirements to build wheel: finished with status 'error'
#0 29.68     error: subprocess-exited-with-error
#0 29.68     
#0 29.68     × Getting requirements to build wheel did not run successfully.
#0 29.68     │ exit code: 1
#0 29.68     ╰─> [2 lines of output]
#0 29.68         Failed to get options via gdal-config: [Errno 2] No such file or directory: 'gdal-config'
#0 29.68         A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
#0 29.68         [end of output]
#0 29.68     
#0 29.68     note: This error originates from a subprocess, and is likely not a problem with pip.
#0 29.68   error: subprocess-exited-with-error
#0 29.68   
#0 29.68   × Getting requirements to build wheel did not run successfully.
#0 29.68   │ exit code: 1
#0 29.68   ╰─> See above for output.
#0 29.68   
#0 29.68   note: This error originates from a subprocess, and is likely not a problem with pip.
#0 29.68   
#0 29.68 
#0 29.68   at /usr/local/lib/python3.9/site-packages/poetry/utils/env.py:1476 in _run
#0 29.72       1472│                 output = subprocess.check_output(
#0 29.72       1473│                     command, stderr=subprocess.STDOUT, env=env, **kwargs
#0 29.72       1474│                 )
#0 29.72       1475│         except CalledProcessError as e:
#0 29.72     → 1476│             raise EnvCommandError(e, input=input_)
#0 29.72       1477│ 
#0 29.72       1478│         return decode(output)
#0 29.72       1479│ 
#0 29.72       1480│     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
#0 29.72 
#0 29.72 The following error occurred when trying to handle this error:
#0 29.72 
#0 29.72 
#0 29.72   PoetryException
#0 29.72 
#0 29.72   Failed to install /root/.cache/pypoetry/artifacts/9e/56/26/0b583bc07db61e0fc88eb894bb554daa81e2905ddbcda92ff923c5e3fe/Fiona-1.8.21.tar.gz
#0 29.72 
#0 29.72   at /usr/local/lib/python3.9/site-packages/poetry/utils/pip.py:51 in pip_install
#0 29.73        47│ 
#0 29.73        48│     try:
#0 29.73        49│         return environment.run_pip(*args)
#0 29.73        50│     except EnvCommandError as e:
#0 29.73     →  51│         raise PoetryException(f"Failed to install {path.as_posix()}") from e
#0 29.73        52│ 
#0 29.73 
------
failed to solve: executor failed running [/bin/sh -c poetry install]: exit code: 1

@fccoelho
Copy link
Contributor

fccoelho commented Oct 7, 2022

Installation of the GDAL library must be added to the Dockerfile. @esloch , could help here? I think it is just a matter of installing GDAL either via apt or mamba.

@eduardocorrearaujo
Copy link
Collaborator Author

I tried poetry add gdal but it returns an error too.

@xmnlab
Copy link
Member

xmnlab commented Oct 10, 2022

Gdal is a very special one. I would install it via mamba if possible. Btw, what is the error when you installed that via poetry?

@eduardocorrearaujo
Copy link
Collaborator Author

eduardocorrearaujo commented Oct 10, 2022

The error is: Updating idna (3.3 -> 3.4): Failed

To add the gdal in the Dockerfile I should add the line:
RUN mamba install gdal
?

@fccoelho
Copy link
Contributor

GDAL is a c++ library and thus can't be pip installed. mamba shoul be able to do it.

@esloch
Copy link

esloch commented Oct 10, 2022

I suggest you pass requirements.txt to a .yaml environment file and use conda/mamba to resolve GDAL dependencies.
Example

@xmnlab
Copy link
Member

xmnlab commented Oct 10, 2022

you also can install libgdal fom conda-forge and install gdal from pypi. but probably the recommended way would be install ing everything from conda-forge as mentioned by @fccoelho

and as this dashboard is not a library, it makes sense to use the approach pointed by @esloch

@eduardocorrearaujo
Copy link
Collaborator Author

Thank you. I will work on that today.

@eduardocorrearaujo
Copy link
Collaborator Author

eduardocorrearaujo commented Oct 12, 2022

I am facing this error to run the app in the container:


OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address Is the server running on that host and accepting TCP/IP connections? (Background on this error at: https://sqlalche.me/e/14/e3q8)

I found this issue discussing it, but I would like to ask you what is the common workflow in this case:
https://stackoverflow.com/questions/31249112/allow-docker-container-to-connect-to-a-local-host-postgres-database

@esloch
Copy link

esloch commented Oct 12, 2022

@eduardocorrearaujo. Are you trying to connect to your local database from the container?
I think you need to set psql_host and psql_port in the environment to be able to access outside the docker network.

@eduardocorrearaujo
Copy link
Collaborator Author

@eduardocorrearaujo. Are you trying to connect to your local database from the container? I think you need to set psql_host and psql_port in the environment to be able to access outside the docker network.

No, I am trying to connect to the epigraphhub database.

@esloch
Copy link

esloch commented Oct 13, 2022

Eduardo, vi que usas repetidas vezes a URI de conexão chumbada nos módulos:
engine = create_engine("postgresql://epigraph:epigraph@localhost:5432/epigraphhub")
Talvez centralizar uma função para a conexão na base de dados em um arquivo settings.py, ou usar um arquivo ".env" com as variáveis de conexão na base de dados, assim evitas chumbar as credenciais dentro dos módulos.
Nesse caso, se conectas a um host externo ao contêiner necessitarás informar para o container a porta e o ip de conexão ao qual queres acessar por meio do environment no docker-compose, que permite você adicionar "env variables" ao seu contêiner.

from dotenv import load_dotenv
load_dotenv('../.env')

engine = create_engine(f'postgresql://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@{os.getenv("POSTGRES_HOST")}:{os.getenv("POSTGRES_PORT")}/{os.getenv("POSTGRES_DB")}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can use the same approach here...
Creating config.py, to avoid calling connection variables more than once.

from dotenv import load_dotenv
load_dotenv('../.env')

engine = create_engine(f'postgresql://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@{os.getenv("POSTGRES_HOST")}:{os.getenv("POSTGRES_PORT")}/{os.getenv("POSTGRES_DB")}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same config.py here.

from dotenv import load_dotenv
load_dotenv('../.env')

engine = create_engine(f'postgresql://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@{os.getenv("POSTGRES_HOST")}:{os.getenv("POSTGRES_PORT")}/{os.getenv("POSTGRES_DB")}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same config.py here.

app/forecast.py Outdated

engine = create_engine(f'postgresql://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@{os.getenv("POSTGRES_HOST")}:{os.getenv("POSTGRES_PORT")}/{os.getenv("POSTGRES_DB")}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same config.py here.

app/get_data.py Outdated

engine_public = create_engine("postgresql://epigraph:epigraph@localhost:5432/epigraphhub")
engine = create_engine(f'postgresql://{os.getenv("POSTGRES_USER")}:{os.getenv("POSTGRES_PASSWORD")}@{os.getenv("POSTGRES_HOST")}:{os.getenv("POSTGRES_PORT")}/{os.getenv("POSTGRES_DB")}')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same config.py here.

app/config.py Outdated
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
POSTGRES_HOST = os.getenv("POSTGRES_HOST")
POSTGRES_PORT = os.getenv("POSTGRES_PORT")
POSTGRES_DB = os.getenv("POSTGRES_DB")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea would be to keep the call of all variables just inside that config file with like this:

DB_URI = (
     f"postgresql://{DB_USER}:{DB_PASSWORD}"
     f"@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)

and in the modules use like this:

engine = create_engine(config.DB_URI)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants