Skip to content

Commit a35f207

Browse files
committed
Add devcontainer setup
1 parent 7a6fce2 commit a35f207

File tree

7 files changed

+150
-2
lines changed

7 files changed

+150
-2
lines changed

.devcontainer/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM mcr.microsoft.com/devcontainers/python:3.11
2+
3+
4+
RUN apt-get update && apt-get install -y \
5+
gettext appstream pkg-config libcairo2-dev gir1.2-gtk-3.0 \
6+
libgirepository1.0-dev libicu-dev libopencv-dev tesseract-ocr \
7+
tesseract-ocr-all gir1.2-pango-1.0 \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
RUN pip install opencv-python
11+
RUN pip install gramps==6.0.1
12+
13+
ENV LANGUAGE=en
14+
ENV OMP_NUM_THREADS=1
15+
ENV GRAMPSWEB_USER_DB_URI=sqlite:////workspaces/web-api/data/users.sqlite
16+
ENV GRAMPSWEB_MEDIA_BASE_DIR=/workspaces/web-api/data/media
17+
ENV GRAMPSWEB_SEARCH_INDEX_DB_URI=sqlite:////workspaces/web-api/data/indexdir/search_index.db
18+
ENV GRAMPSWEB_STATIC_PATH=/workspaces/web-api/data/static
19+
ENV GRAMPSWEB_THUMBNAIL_CACHE_CONFIG__CACHE_DIR=/workspaces/web-api/data/thumbnail_cache
20+
ENV GRAMPSWEB_REPORT_DIR=/workspaces/web-api/data/reports_cache
21+
ENV GRAMPSWEB_EXPORT_DIR=/workspaces/web-api/data/export_cache
22+
ENV GRAMPSHOME=/workspaces/web-api/data/
23+
ENV GRAMPS_DATABASE_PATH=/workspaces/web-api/data/grampsdb
24+
ENV GRAMPSWEB_TREE=Gramps\ Web
25+
# Do not use this value in production!!
26+
ENV GRAMPSWEB_SECRET_KEY=QAVoeYDzkQves9iDZ5PkxfdUoVElVMVYPqz-QXha6yE
27+
ENV GRAMPSWEB_CORS_ORIGINS="*"
28+
ENV GRAMPSWEB_VECTOR_EMBEDDING_MODEL=sentence-transformers/distiluse-base-multilingual-cased-v2
29+
ENV GRAMPSWEB_CELERY_CONFIG__broker_url=redis://redis:6379/0
30+
ENV GRAMPSWEB_CELERY_CONFIG__result_backend=redis://redis:6379/0
31+
32+
# CPU-only version of PyTorch
33+
RUN pip install torch --index-url https://download.pytorch.org/whl/cpu
34+
RUN pip install sentence-transformers
35+
36+
# download and cache sentence transformer model
37+
RUN python3 -c "from sentence_transformers import SentenceTransformer; \
38+
model = SentenceTransformer('sentence-transformers/distiluse-base-multilingual-cased-v2')";
39+

.devcontainer/devcontainer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Gramps Web API Dev",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "devcontainer",
5+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
6+
"postCreateCommand": "scripts/start_dev_container.sh",
7+
"postStartCommand": "pip install -e .[ai]",
8+
"appPort": ["5555:5555"],
9+
"customizations": {
10+
"vscode": {
11+
"extensions": [
12+
"ms-python.pylint",
13+
"ms-python.vscode-pylance",
14+
"ms-python.black-formatter",
15+
"GitHub.vscode-pull-request-github",
16+
"GitHub.copilot"
17+
],
18+
"settings": {
19+
"python.experiments.optOutFrom": ["pythonTestAdapter"],
20+
"editor.formatOnSave": true,
21+
"files.trimTrailingWhitespace": true,
22+
"[python]": {
23+
"editor.defaultFormatter": "ms-python.black-formatter"
24+
}
25+
}
26+
}
27+
}
28+
}

.devcontainer/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "3.8"
2+
services:
3+
devcontainer:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
volumes:
8+
- ../..:/workspaces:cached
9+
command: sleep infinity
10+
11+
redis:
12+
image: valkey/valkey:alpine
13+
restart: unless-stopped
14+
ports:
15+
- "6379:6379"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Pipfile.lock
77
.venv
88
*.ipynb
99

10+
data/
1011
indexdir/
1112
indexdir_empty/
1213
thumbnail_cache/

.vscode/tasks.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Serve Web API",
6+
"type": "shell",
7+
"command": "python3 -O -m gramps_webapi run --port 5555 --host 0.0.0.0",
8+
"isBackground": true,
9+
"group": {
10+
"kind": "build",
11+
"isDefault": true
12+
},
13+
"runOptions": {
14+
"instanceLimit": 1
15+
}
16+
},
17+
{
18+
"label": "Start Celery Worker",
19+
"type": "shell",
20+
"command": "celery -A gramps_webapi.celery worker --loglevel=INFO --concurrency=1",
21+
"isBackground": true,
22+
"group": {
23+
"kind": "build",
24+
"isDefault": true
25+
},
26+
"runOptions": {
27+
"instanceLimit": 1
28+
}
29+
}
30+
]
31+
}

gramps_webapi/__main__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ def cli(ctx, config):
8989
@click.option("--use-wsgi", is_flag=True, help="Add a WSGI wrapper around the server")
9090
@click.pass_context
9191
def run(
92-
ctx, port, tree, host, open_browser, debug_level, log_file, max_workers, use_wsgi
92+
ctx,
93+
port,
94+
tree,
95+
host,
96+
open_browser,
97+
debug_level,
98+
log_file,
99+
max_workers,
100+
use_wsgi,
93101
):
94102
"""Run the app."""
95103
app = ctx.obj["app"]
@@ -133,7 +141,7 @@ def open_webbrowser_after_start():
133141
threads=max_workers,
134142
)
135143
else:
136-
app.run(port=port, threaded=True)
144+
app.run(port=port, threaded=True, host=host)
137145
print()
138146
print("Stopping Gramps Web API server...")
139147

scripts/start_dev_container.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Dev Container startup script
4+
set -e
5+
6+
# Install dependencies
7+
pip install -r requirements-dev.txt
8+
pip install -e .[ai]
9+
10+
mkdir -p /workspaces/web-api/data/grampsdb
11+
# Check if the grampsdb directory is empty
12+
if [ -z "$(ls -A /workspaces/web-api/data/grampsdb)" ]; then
13+
echo "Database directory is empty, initializing..."
14+
# Create necessary directories if they don't exist
15+
mkdir -p /workspaces/web-api/data/grampsdb
16+
gramps -C Gramps\ Web -i /usr/local/share/doc/gramps/example/gramps/example.gramps --config=database.backend:sqlite --config=database.path:/workspaces/web-api/data/grampsdb
17+
mkdir -p /workspaces/web-api/data/media
18+
cp -a /usr/local/share/doc/gramps/example/gramps/. /workspaces/web-api/data/media/
19+
else
20+
echo "Database directory already contains data, skipping initialization"
21+
fi
22+
23+
python3 -m gramps_webapi user add owner owner --fullname Owner --role 4 \
24+
&& python3 -m gramps_webapi user add editor editor --fullname Editor --role 3 \
25+
&& python3 -m gramps_webapi user add contributor contributor --fullname Contributor --role 2 \
26+
&& python3 -m gramps_webapi user add member member --fullname Member --role 1

0 commit comments

Comments
 (0)