diff --git a/.gitignore b/.gitignore index 101e7cf5..c8b92581 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,9 @@ venv.bak/ # -- Tools .coverage +# Jupytext: we version converted md files not ipynb sources +*.ipynb + # -- Provisioning provisioning/.terraform* provisioning/terraform.tfstate* diff --git a/Makefile b/Makefile index f7fad6be..b8537fd1 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,8 @@ bootstrap: \ create-metabase-db \ seed-metabase \ seed-oidc \ - create-superuser + create-superuser \ + jupytext--to-ipynb .PHONY: bootstrap build: ## build services image @@ -55,6 +56,10 @@ build-client: ## build the client image $(COMPOSE) build client .PHONY: build-client +build-notebook: ## build custom jupyter notebook image + @$(COMPOSE) build notebook +.PHONY: build-notebook + down: ## stop and remove all containers @$(COMPOSE) down .PHONY: down @@ -67,14 +72,22 @@ logs-api: ## display API server logs (follow mode) @$(COMPOSE) logs -f api .PHONY: logs-api +logs-notebook: ## display notebook logs (follow mode) + @$(COMPOSE) logs -f notebook +.PHONY: logs-notebook + run: ## run the api server (and dependencies) $(COMPOSE) up -d api .PHONY: run run-all: ## run the whole stack - $(COMPOSE) up -d api keycloak metabase + $(COMPOSE) up -d api keycloak metabase notebook .PHONY: run-all +run-notebook: ## run the notebook service + $(COMPOSE) up -d notebook +.PHONY: run-notebook + status: ## an alias for "docker compose ps" @$(COMPOSE) ps .PHONY: status @@ -132,6 +145,14 @@ create-superuser: ## create super user --force .PHONY: create-superuser +jupytext--to-md: ## convert local ipynb files into md + bin/jupytext --to md work/src/notebook/**/*.ipynb +.PHONY: jupytext--to-md + +jupytext--to-ipynb: ## convert remote md files into ipynb + bin/jupytext --to ipynb work/src/notebook/**/*.md +.PHONY: jupytext--to-ipynb + seed-metabase: ## seed the Metabase server @echo "Running metabase service …" @$(COMPOSE) up -d --wait metabase diff --git a/bin/jupytext b/bin/jupytext new file mode 100755 index 00000000..3ed7c45b --- /dev/null +++ b/bin/jupytext @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +declare DOCKER_USER +DOCKER_USER="$(id -u):$(id -g)" + +DOCKER_USER=${DOCKER_USER} docker compose run --rm notebook jupytext "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 07a2aca1..6bc6f86a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -70,6 +70,23 @@ services: depends_on: - postgresql + notebook: + build: + context: . + dockerfile: src/notebook/Dockerfile + user: ${DOCKER_USER:-1000} + environment: + NB_UID: ${DOCKER_UID:-1000} + NB_GID: ${DOCKER_GID:-1000} + CHOWN_HOME: 'yes' + CHOWN_HOME_OPTS: -R + ports: + - 8888:8888 + volumes: + - .:/home/jovyan/work + depends_on: + - postgresql + # -- tools curl: image: curlimages/curl:8.8.0 diff --git a/src/notebook/Dockerfile b/src/notebook/Dockerfile new file mode 100644 index 00000000..e6f1091d --- /dev/null +++ b/src/notebook/Dockerfile @@ -0,0 +1,11 @@ +# -- Custom image -- +FROM jupyter/base-notebook + +# Install base dependencies +RUN mamba install --yes \ + duckdb \ + geopandas \ + jupytext \ + matplotlib \ + pandas \ + seaborn diff --git a/src/notebook/analyses/.keep b/src/notebook/analyses/.keep new file mode 100644 index 00000000..e69de29b diff --git a/src/notebook/indicators/.keep b/src/notebook/indicators/.keep new file mode 100644 index 00000000..e69de29b