From f96ed4efb1e6f087dccf78c2442da92ccf1ea6a6 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Tue, 24 Sep 2024 15:17:06 -0400 Subject: [PATCH] Fix docker --- docs/install.rst | 17 ++++++++--------- docs/postgres.rst | 4 ++-- examples/postgres.py | 2 +- postgres/Dockerfile | 10 +++++++++- postgres/docker-compose.yml | 5 +++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/install.rst b/docs/install.rst index 5265bc03..d4d49d8e 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -14,18 +14,17 @@ You also need to install optional dependencies, depending on the adapter you wan .. code-block:: bash - $ pip install 'shillelagh[console]' # to use the CLI - $ pip install 'shillelagh[genericjsonapi]' # for Generic JSON - $ pip install 'shillelagh[genericxmlapi]' # for Generic XML - $ pip install 'shillelagh[githubapi]' # for GitHub - $ pip install 'shillelagh[gsheetsapi]' # for GSheets - $ pip install 'shillelagh[htmltableapi]' # for HTML tables - $ pip install 'shillelagh[pandasmemory]' # for Pandas in memory - $ pip install 'shillelagh[s3selectapi]' # for S3 files - $ pip install 'shillelagh[systemapi]' # for CPU information + $ pip install 'shillelagh[console]' # to use the CLI + $ pip install 'shillelagh[githubapi]' # for GitHub + $ pip install 'shillelagh[gsheetsapi]' # for GSheets + $ pip install 'shillelagh[htmltableapi]' # for HTML tables + $ pip install 'shillelagh[pandasmemory]' # for Pandas in memory + $ pip install 'shillelagh[s3selectapi]' # for S3 files + $ pip install 'shillelagh[systemapi]' # for CPU information Alternatively, you can install everything with: .. code-block:: bash $ pip install 'shillelagh[all]' +~ diff --git a/docs/postgres.rst b/docs/postgres.rst index c72880ae..d76d57eb 100644 --- a/docs/postgres.rst +++ b/docs/postgres.rst @@ -14,10 +14,10 @@ To use the backend you need to: Note that you need to install Python packages in a way that they are available to the process running Postgres. You can either install them globally, or install them in a virtual environment and have it activated in the process that starts Postgres. -The ``postgres/`` directory has a Docker configuration that can be used to test the backend, or as a basis for installation. To run it, enter the directory and execute: +The ``postgres/`` directory has a Docker configuration that can be used to test the backend, or as a basis for installation. To run it, execute: .. code-block:: bash - docker compose up --build -d + docker compose -f postgres/docker-compose.yml up You should then be able to run the example script in `examples/postgres.py`_ to test that everything works. diff --git a/examples/postgres.py b/examples/postgres.py index de61b65c..534b5484 100644 --- a/examples/postgres.py +++ b/examples/postgres.py @@ -19,7 +19,7 @@ # the backend uses psycopg2 under the hood, so any valid connection string for it will # work; just replace the scheme with `shillelagh+multicorn2` engine = create_engine( - "shillelagh+multicorn2://shillelagh:shillelagh123@localhost:12345/shillelagh", + "shillelagh+multicorn2://shillelagh:shillelagh123@localhost:5432/shillelagh", ) connection = engine.connect() diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 5d45189b..267c7786 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -10,10 +10,12 @@ USER root # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ + git \ postgresql-server-dev-13 \ python3 \ python3-dev \ python3-pip \ + python3-venv \ wget # Download, build, and install multicorn2 @@ -24,7 +26,13 @@ RUN wget https://github.com/pgsql-io/multicorn2/archive/refs/tags/v2.5.tar.gz && make install -RUN pip install -e '.[all]' +# Create a virtual environment and install dependencies +RUN python3 -m venv /code/venv && \ + /code/venv/bin/pip install --upgrade pip && \ + /code/venv/bin/pip install -e '.[all]' + +# Set environment variable for PostgreSQL to use the virtual environment +ENV PATH="/code/venv/bin:$PATH" # Switch back to the default postgres user USER postgres diff --git a/postgres/docker-compose.yml b/postgres/docker-compose.yml index 6b2e1e15..5d905388 100644 --- a/postgres/docker-compose.yml +++ b/postgres/docker-compose.yml @@ -2,7 +2,9 @@ version: '3.8' services: postgres: - build: . + build: + context: .. + dockerfile: postgres/Dockerfile environment: POSTGRES_PASSWORD: shillelagh123 POSTGRES_USER: shillelagh @@ -10,7 +12,6 @@ services: volumes: - db_data:/var/lib/postgresql/data - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro - - ..:/src ports: - "5432:5432"