Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add pgcli to postgres container, db-shell recipe (#252)

Madison Swain-Bowden93255a190ee8
diff --git a/README.md b/README.md
index fa2b855c3..e2fe79cca 100644
--- a/README.md
+++ b/README.md
@@ -198,6 +198,12 @@ just logs
To see the Airflow web UI, point your browser to `localhost:9090`. The default user name and password for the airflow UI are both `airflow`.
+To begin an interactive [`pgcli` shell](https://www.pgcli.com/) on the database container, run:
+
+```shell
+just db-shell
+```
+
If you'd like to bring down the containers, run
```shell
diff --git a/docker-compose.override.yml b/docker-compose.override.yml
index f611fefca..a9a84fa8c 100644
--- a/docker-compose.override.yml
+++ b/docker-compose.override.yml
@@ -8,6 +8,8 @@ services:
- POSTGRES_USER=deploy
- POSTGRES_PASSWORD=deploy
- POSTGRES_DB=openledger
+ - PGUSER=deploy
+ - PGDATABASE=openledger
env_file: .env
ports:
- "5434:5432"
diff --git a/docker/local_postgres/Dockerfile b/docker/local_postgres/Dockerfile
index de19e835b..b404fb6ab 100644
--- a/docker/local_postgres/Dockerfile
+++ b/docker/local_postgres/Dockerfile
@@ -1,12 +1,12 @@
FROM postgres:13.2
-ENV POSTGRES_USER=deploy
-ENV POSTGRES_PASSWORD=deploy
-ENV POSTGRES_DB=openledger
-ADD 0001_airflow_user_db.sql /docker-entrypoint-initdb.d
-ADD 0002_aws_s3_mock.sql /docker-entrypoint-initdb.d
-ADD 0003_openledger_image_schema.sql /docker-entrypoint-initdb.d
-ADD 0004_openledger_image_view.sql /docker-entrypoint-initdb.d
-ADD 0005_openledger_old_image_schema.sql /docker-entrypoint-initdb.d
-ADD 0006_openledger_audio_schema.sql /docker-entrypoint-initdb.d
-ADD 0007_openledger_audio_view.sql /docker-entrypoint-initdb.d
-RUN apt-get -y update && apt-get -y install python3-boto3 postgresql-plpython3-13
+ARG PGCLI_VERSION=3.2.0
+RUN apt-get update && apt-get -yqq upgrade && apt-get -yqq install \
+ python3-boto3 \
+ postgresql-plpython3-13 \
+ python3-pip \
+ libpq-dev \
+ && apt-get autoremove -y \
+ && rm -rf /var/lib/apt/lists/* \
+ && pip3 install pgcli==${PGCLI_VERSION}
+
+COPY *.sql /docker-entrypoint-initdb.d/
diff --git a/justfile b/justfile
index c92687704..cd7487fe7 100644
--- a/justfile
+++ b/justfile
@@ -58,3 +58,7 @@ shell: up
# Run a given airflow command using the webserver image
airflow command="": up
docker-compose {{ DEV_DOCKER_FILES }} exec {{ SERVICE }} airflow {{ command }}
+
+# Launch a pgcli shell on the postgres container
+db-shell: up
+ docker-compose {{ DEV_DOCKER_FILES }} exec postgres pgcli