Skip to content

Commit

Permalink
Add postgres setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JBorrow committed Feb 6, 2024
1 parent f314148 commit d7c880f
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 184 deletions.
2 changes: 2 additions & 0 deletions container/postgres/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alembic/*
alembic.ini
19 changes: 19 additions & 0 deletions container/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.11

RUN pip install --no-cache-dir --upgrade "git+https://github.com/simonsobs/librarian.git@librarian-v2"
RUN pip install --no-cache-dir --upgrade "psycopg[binary,pool]"

COPY ./server_config.json server_config.json
COPY ./background_config.json background_config.json
COPY ./alembic.ini alembic.ini
COPY ./alembic alembic
COPY ./setup_vars.sh setup_vars.sh

RUN mkdir -p /tmp/store/libstore/store
RUN mkdir -p /tmp/store/libstore/staging
RUN mkdir -p /tmp/store/libclone/store
RUN mkdir -p /tmp/store/libclone/staging
RUN mkdir -p /volumes/database

CMD ["librarian-server-start"]

13 changes: 13 additions & 0 deletions container/postgres/background_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"create_local_clone": [
{
"task_name": "Local cloner",
"every": "00:05:00",
"age_in_days": 7,
"clone_from": "store",
"clone_to": "clone"
}
]
}


61 changes: 61 additions & 0 deletions container/postgres/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
version: "3.11"

services:
librarian-database:
image: postgres:16
restart: always
container_name: "librarian-database"
user: postgres
volumes:
- "database:/var/lib/postgresql/data"
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "secret"
POSTGRES_DB: "librarian"
expose:
- 5432
networks:
- "librarian-network"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 3s
timeout: 5s
retries: 5

librarian-server:
hostname: "example-librarian-hostname"
build:
context: "."
dockerfile: "Dockerfile"
container_name: "librarian-postgres"
ports:
- 127.0.0.1:21108:21108
stdin_open: true
tty: true
volumes:
- "database:/volumes/database"
- type: "bind"
source: "/tmp/store"
target: "/tmp/store"
environment:
- LIBRARIAN_CONFIG_PATH=server_config.json
- LIBRARIAN_SERVER_DATABASE_USER=postgres
- LIBRARIAN_SERVER_DATABASE_PASSWORD=secret
- LIBRARIAN_BACKGROUND_CONFIG=background_config.json
- LIBRARIAN_SERVER_DATABASE_DRIVER=sqlite
- LIBRARIAN_SERVER_DATABASE=/volumes/database/database.db
- LIBRARIAN_SERVER_PORT=21108
depends_on:
librarian-database:
condition: service_healthy
networks:
- "librarian-network"

volumes:
database:

networks:
librarian-network:



5 changes: 5 additions & 0 deletions container/postgres/pre_docker_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# We need to copy in the alembic to here, so we can run the
# database migration.

cp -r ../../alembic .
cp ../../alembic.ini .
47 changes: 47 additions & 0 deletions container/postgres/server_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"database_driver": "postgresql+psycopg",
"database_port": "5432",
"database": "librarian",
"database_host": "librarian-database",
"log_level": "DEBUG",
"displayed_site_name": "Docker Example",
"displayed_site_description": "An example docker deployment of the librarian.",
"add_stores": [
{
"store_name": "store",
"store_type": "local",
"ingestable": true,
"store_data": {
"staging_path": "/tmp/store/libstore/staging",
"store_path": "/tmp/store/libstore/store"
},
"transfer_manager_data": {
"local": {
"available": true,
"hostnames": [
"borrowj-adapter.physics.upenn.edu",
"example-librarian-hostname"
]
}
}
},
{
"store_name": "clone",
"store_type": "local",
"ingestable": false,
"store_data": {
"staging_path": "/tmp/store/libclone/staging",
"store_path": "/tmp/store/libclone/store"
},
"transfer_manager_data": {
"local": {
"available": true,
"hostnames": [
"borrowj-adapter.physics.upenn.edu",
"example-librarian-hostname"
]
}
}
}
]
}
2 changes: 2 additions & 0 deletions container/postgres/setup_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export LIBRARIAN_SERVER_DATABASE_USER="postgres"
export LIBRARIAN_SERVER_DATABASE_PASSWORD="secret"
15 changes: 15 additions & 0 deletions container/sqlite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is a very simple setup for the librarian, using a local SQLite database
as the core librarian database. Production setups may want to use the
postgres container.

A few things to keep in mind when deploying the librarian:

- This is inherently not secure by default; you will need to change the administrator
password for the librarian and potentially provision further accounts.

- You will need to mark both the hostname of the docker container and of your
local machine as available for local transfers.

- You will need to make sure that the local store locations are mounted
transparently by the docker container (i.e. you should have /path/to/store
the same inside and outside of the container).
183 changes: 0 additions & 183 deletions container/wait-for-it.sh

This file was deleted.

2 changes: 1 addition & 1 deletion librarian_server_scripts/librarian_server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def main():
try:
conn.execute(
text(
f"CREATE USER {args.librarian_db_user} WITH PASSWORD '{args.librarian_db_password}'"
f"CREATE USER {args.librarian_db_user} WITH PASSWORD {args.librarian_db_password}"
)
)
conn.execute(text(f"GRANT libserver TO {args.librarian_db_user}"))
Expand Down

0 comments on commit d7c880f

Please sign in to comment.