Skip to content

Commit

Permalink
fix multiplatform build,
Browse files Browse the repository at this point in the history
clean-up compose file
clean-up entrypoint
update README
On branch dev
Changes to be committed:
	modified:   .env-dist
	modified:   .github/workflows/docker-build-n-test.yml
	modified:   .gitignore
	modified:   Dockerfile
	modified:   README.md
	modified:   docker-compose.yml
	new file:   docker-compose.yml-dist
	modified:   entrypoint.sh
  • Loading branch information
gnzsnz committed Aug 26, 2023
1 parent 5c48ce3 commit 3efc4bc
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .env-dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ USER_GID=1000
APT_PROXY=
IMAGE_VERSION=2308.05
LISTEN_PORT=8888
#BYODF=/home/gordon/Notebooks/etc/dotfiles
BYODF=
3 changes: 2 additions & 1 deletion .github/workflows/docker-build-n-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ jobs:
uses: docker/build-push-action@v4
with:
push: false
load: true
load: false
context: .
platforms: ${{ env.PLATFORMS }}
build-args: |
USER=${{ env.USER }}
USER_ID=${{ env.USER_ID }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
./Notebooks/
docker-compose.yml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ RUN if [ -n "$APT_PROXY" ]; then \
;fi && \
groupadd --gid ${USER_GID} ${USER} && \
useradd -ms /bin/bash --uid ${USER_ID} --gid ${USER_GID} ${USER} && \
echo "${USER} ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers
echo "${USER} ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers

USER $USER_ID:$USER_GID

Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ A dockerized Jupyter quant research enviroment.
- Optimized for size, it's a 2GB image vs 4GB for jupyter/scipy-notebook
- Includes all major python packages for data and timeseries analysis, see [requirements](https://github.com/gnzsnz/jupyter-quant/blob/master/requirements.txt)
- Includes jedi language server
- It does NOT include conda/mamba. All packages are installed wit pip under ~/.local/lib/python
- It does NOT include conda/mamba. All packages are installed with pip under ~/.local/lib/python. Which should be mounted in a dedicated volume to preserver your enviroment.
- Includes Cython, Numba, bottleneck and numexpr to speed up things
- The usual suspects are included, numpy, pandas, sci-py, scikit-learn
- Includes tools for quant analysis, statsmodels, pymc, arch, py_vollib, zipline-reloaded, PyPortfolioOpt, etc.
- ib_insync for Interactive Broker connectivity. Works well with [IB Gateway](https://github.com/gnzsnz/ib-gateway-docker)
- sudo, so you can install new packages if needed
- bash and stow, so you can BYODF (bring your own dot files)
- Support for [apt cache](https://github.com/gnzsnz/apt-cacher-ng). If you have other linux boxes using you can leverage your cache. apt cache support major linux distributions not only debian/ubuntu.

- It does not include a build environment. If you need to install a package that does not provide wheels you can build your wheels, as explained in [common tasks](#common-tasks)

## Volumes

The image is designed to work with 3 volumes:

1. `quant_data`` - volume for `~/.local`` folder. It contains caches and all python packages. This enables to add additional packages through pip.
1. `quant_conf` - volume for `~/.config``, all config goes here. This includes jupyter, ipython, matplotlib, etc
1. Bind mount (but you could use a named volume) - volume for all notebooks, under `~/Notebooks``.
1. `quant_data` - volume for ~/.local folder. It contains caches and all python packages. This enables to add additional packages through pip.
1. `quant_conf` - volume for ~/.config, all config goes here. This includes jupyter, ipython, matplotlib, etc
1. Bind mount (but you could use a named volume) - volume for all notebooks, under `~/Notebooks`.

This allows to have ephemeral containers and to keep your notebooks (3), your config (2) and your additional packages (1). Eventually you would need to update the image, in this case your notebooks (3) can move without issues, your config (2) should still work but no warranty, and your packages could still be used. Eventually you would need to refresh (1) and less frecuently (2)

Expand All @@ -37,6 +37,7 @@ services:
image: gnzsnz/jupyter-quant:${IMAGE_VERSION}
environment:
APT_PROXY: ${APT_PROXY:-}
BYODF: ${BYODF:-}
restart: unless-stopped
ports:
- ${LISTEN_PORT}:8888
Expand Down Expand Up @@ -101,3 +102,13 @@ docker run -it --rm gnzsnz/jupyter-quant --show-config-json
```bash
docker run -it --rm gnzsnz/jupyter-quant bash
```

- build wheels outside the container and import wheels to container

```bash
# make sure python version match .env-dist
docker run -it --rm -v $PWD/wheels:/wheels python:3.11 bash
pip wheel --no-cache-dir --wheel-dir /wheels numpy
```

This will build wheels for numpy (ot any other package that you need) and save the file in $PWD/wheels. Then you can copy the wheels in your notebooks mount (3 above) and install it within the container. You can even drag and drop into jupyter.
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ services:
platforms:
- "linux/amd64"
#- "linux/arm64"
#- linux/arm32v7"
#- linux/arm64v8"
args:
USER: ${USER}
USER_ID: ${USER_ID}
Expand All @@ -16,9 +14,8 @@ services:
APT_PROXY: ${APT_PROXY}
image: gnzsnz/jupyter-quant:${IMAGE_VERSION}
environment:
APT_PROXY: ${APT_PROXY}
QB_CONF: ${QB_CONF}
QB_STORAGE: ${QB_STORAGE}
APT_PROXY: ${APT_PROXY:-}
BYODF: ${BYODF:-}
restart: unless-stopped
ports:
- ${LISTEN_PORT}:8888
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.6"
services:
jupyter-quant:
build:
context: .
platforms:
- "linux/amd64"
#- "linux/arm64"
args:
USER: ${USER}
USER_ID: ${USER_ID}
USER_GID: ${USER_GID}
PYTHON_VERSION: ${PYTHON_VERSION}
APT_PROXY: ${APT_PROXY}
image: gnzsnz/jupyter-quant:${IMAGE_VERSION}
environment:
APT_PROXY: ${APT_PROXY}
BYODF: ${BYODF:-}
restart: unless-stopped
ports:
- ${LISTEN_PORT}:8888
volumes:
- quant_conf:/home/gordon/.config
- quant_data:/home/gordon/.local
- ${PWD}/Notebooks:/home/gordon/Notebooks

volumes:
quant_conf:
quant_data:

7 changes: 3 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
set -e

DAEMON=jupyter-lab
#JUPYTER_OPT=''

# jupyterlab-lsp
JUPYTER_OPT='--ContentsManager.allow_hidden=True'

# APT Proxy Cache
if [ -n "${APT_PROXY}" ]; then
Expand All @@ -30,6 +26,9 @@ if [ -d "$BYODF" ]; then
git -C "$BYODF" reset --hard
fi;

# jupyterlab-lsp
JUPYTER_OPT='--ContentsManager.allow_hidden=True'

# language server symlink
if [ ! -L "${JUPYTER_SERVER_ROOT}"/.lsp_symlink ]; then
ln -s / .lsp_symlink
Expand Down

0 comments on commit 3efc4bc

Please sign in to comment.