Skip to content

Commit

Permalink
✨(project) add notebook service
Browse files Browse the repository at this point in the history
Useful to analyse stored data and draft indicators.
  • Loading branch information
jmaupetit committed Jun 28, 2024
1 parent 22cfa2d commit 63d2fe2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ venv.bak/
# -- Tools
.coverage

# Jupytext: we version converted md files not ipynb sources
*.ipynb

# -- Provisioning
provisioning/.terraform*
provisioning/terraform.tfstate*
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions bin/jupytext
Original file line number Diff line number Diff line change
@@ -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 "$@"
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/notebook/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -- Custom image --
FROM jupyter/base-notebook

# Install base dependencies
RUN mamba install --yes \
duckdb \
geopandas \
jupytext \
matplotlib \
pandas \
seaborn
Empty file added src/notebook/analyses/.keep
Empty file.
Empty file added src/notebook/indicators/.keep
Empty file.

0 comments on commit 63d2fe2

Please sign in to comment.