karlicoss / promnesia

Another piece of your extended mind
https://beepb00p.xyz/promnesia.html
MIT License
1.74k stars 74 forks source link

Backend in docker container? #55

Open garyng opened 4 years ago

garyng commented 4 years ago

From hackernews!

Is there a docker image for running the backend?

karlicoss commented 4 years ago

Hey! Thanks for creating the issue!

Not yet, but it was in my plans!

etopeter commented 4 years ago

Thanks for merging this feature. I call it initial commit because it could and should be extended. Current feature allows build for "local" testing/running. To further streamline docker as viable deployment method I would like to have a lightweight image available in DockerHub. I'm proposing creating docker/alpine/Dockerfile and have that automatically build tags. There is one more improvement that could be made and that is python dependencies. Right now Dockerfile has hardcoded pip install ... instead it could be using setup.py from the root repo. Flavors that could be developed:

  1. Docker shell image that mounts volume on top of src directory to have python dependencies environment and ability to edit code with favorite local editor (emacs).
  2. Docker image that installs master branch and volumes are only used to store promnesia.sqlite database.
  3. Docker image that installs python latest python module. Bonus add args during build to control version installed as well as dependencies.

In any case the merge gives us some start to build other features.

karlicoss commented 4 years ago

BTW, I played a bit more with docker and docker-compose lately, and managed to pack in most of Promnesia along with dependencies.. I'll share it soon-ish!

koo5 commented 3 years ago

@etopeter

Flavors that could be developed: ... oh wow that'd be next level

karlicoss commented 3 years ago

Snippet from my personal compose file, ideally I'd like the one some thing like this

version: "3.7"

# define volume mappings (so it's possible to reuse them later)
x-cache: &cache
  { source: /tmp/promnesia-cache,
    target: /tmp/promnesia-cache,
    type: bind }

# keep paths mapping as intact as possible; makes it simpler to setup & debug
x-backups: &backups
  { source: /path/to/backups,
    target: /path/to/backups,
    type: bind, read_only: True }

# .... other volumes

# define as much as possible here to avoid duplication
x-promnesia-base: &promnesia-base
    build: { dockerfile: promnesia.Dockerfile, context: . }
    user: '1000:1000'
    volumes: [*setup, *promnesia-env,
              *hpi-cfg,
              *cache,
              *backups, *polar,
              *logs, *notes, *zim,
              { source: /code/promnesia,
                target: /code/promnesia,
                type: bind, read_only: True },
             ]

services:
  promnesia_setup:
     <<: *promnesia-base
     entrypoint: /code/promnesia/docker-setup.sh

  promnesia_index:
     <<: *promnesia-base
     environment:
       - PROMNESIA_CORES=8
       - PROMNESIA_FD_EXTRA_ARGS=--ignore-file /code/promnesia/ignored
     entrypoint: /code/promnesia/scripts/promnesia index

  promnesia_index_quick:
     <<: *promnesia-base
     environment:
       # I fucking hate yaml, can't reuse parts of arrays...
       - PROMNESIA_CORES=8
       - PROMNESIA_FD_EXTRA_ARGS=--ignore-file /code/promnesia/ignored
       - PROMNESIA_INDEX_POLICY=update
     entrypoint: /code/promnesia/scripts/promnesia index --config /.config/promnesia/quick_config.py

  promnesia_serve:
     <<: *promnesia-base
     restart: unless-stopped
     entrypoint: /code/promnesia/scripts/promnesia serve 
     ports: ["13131:13131"]
garyng commented 3 years ago

# I fucking hate yaml, can't reuse parts of arrays...

I agree!

Normally what I did for environment variables is to create a shared .env file, and put the service-specific overrides into <service>.env file. Then include them with env_file (https://docs.docker.com/compose/compose-file/#env_file):

env_file: 
    - .env
    - <service>.env

It does require you to checkin your .env file though...

infogulch commented 3 years ago

I prefer:

docker-compose.yml

env_file: 
    - default.env
    - private.env
...

.gitignore

private.env

Name private.env however you like of course.

AnweshGangula commented 10 months ago

Are there instructions anywhere on how to build the docker container and how to use it with my local knowledge base (either obsidian, logseq etc...)?

Can Docker refer to my notes which are outside the container?