From 4f188ae2c46dde2e965d505f49820e5abadec909 Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 27 Feb 2024 22:13:50 -0500 Subject: [PATCH 1/9] added basics for conda --- devcontainers/conda-jupyter-node/README.md | 10 +++ .../conda-jupyter-node/docker/Dockerfile | 29 ++++++ .../docker/docker-compose.yml | 20 +++++ .../docker/entrypoints/smoke-tests.sh | 6 ++ .../docs_readme_conda_jupyter_node.md | 88 +++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 devcontainers/conda-jupyter-node/README.md create mode 100644 devcontainers/conda-jupyter-node/docker/Dockerfile create mode 100644 devcontainers/conda-jupyter-node/docker/docker-compose.yml create mode 100644 devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh create mode 100644 devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md diff --git a/devcontainers/conda-jupyter-node/README.md b/devcontainers/conda-jupyter-node/README.md new file mode 100644 index 0000000..8070ae5 --- /dev/null +++ b/devcontainers/conda-jupyter-node/README.md @@ -0,0 +1,10 @@ +# Conda Juptyer Node +* +```bash +cd devcontainers/conda-jupyter-node +code devcontainers/conda-jupyter-node +``` +```bash +docker build -t jchan48h/conda-jupyter-node ./docker +docker run -it --rm --name conda-jupyter-node --hostname cjn jchan48h/conda-jupyter-node /bin/zsh +``` \ No newline at end of file diff --git a/devcontainers/conda-jupyter-node/docker/Dockerfile b/devcontainers/conda-jupyter-node/docker/Dockerfile new file mode 100644 index 0000000..bc308bd --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/Dockerfile @@ -0,0 +1,29 @@ +FROM debian:bookworm-slim +# https://docs.docker.com/reference/dockerfile/ + +# known dependencies: curl +# dev dependencies: zsh tree tldr git wget +RUN apt-get update && apt-get install -y \ + curl \ + zsh tree wget git \ + && rm -rf /var/lib/apt/lists/* +# rm -rf /var/lib/apt/lists/* is to clean up after apt-get +# maybe add tmux etc. only + +# assume mounted docker to /webapp using compose +WORKDIR /webapp +# COPY . /webapp +# using compose to mount + +# default port for jupterlab +EXPOSE 8888 +# Entrypoint for smoke testing / health check +# might sneakily use it to run conda though? +RUN tree `pwd` -f +HEALTHCHECK --interval=5m --timeout=3s \ + CMD curl -f http://localhost:8888/ || exit 1 +# RUN ls -l chmod +rx ./entrypoints/smoke-test.sh +# ENTRYPOINT [ "./entrypoints/smoke-test.sh" ] +CMD /bin/zsh + + diff --git a/devcontainers/conda-jupyter-node/docker/docker-compose.yml b/devcontainers/conda-jupyter-node/docker/docker-compose.yml new file mode 100644 index 0000000..457492e --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/docker-compose.yml @@ -0,0 +1,20 @@ +# Docker Compose for mounting volumes during build +version: "3.8" +name: conda-jupyter-node +# i guess proper name would be conda-node-jupyter so +# compose would auto append +services: + webapp: + # comment out to skip build + # called docker-webapp for some reason + container_name: jupyter-webapp + # for dev: maybe should add a dev env file + stdin_open: true # docker run -i. needed until a service is running + tty: true # docker run -t. instead of bash... cuz bash is not a service + + build: + context: . + dockerfile: ./Dockerfile + # image: jchan48h/conda-jupyter-node + volumes: + - .:/webapp diff --git a/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh b/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh new file mode 100644 index 0000000..8e4f22e --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -euxo pipefail +echo /etc/os-release +printenv | grep -i home +# doesn't need to be bash even +# using healthcheck as well \ No newline at end of file diff --git a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md new file mode 100644 index 0000000..465c14f --- /dev/null +++ b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md @@ -0,0 +1,88 @@ +# Conda jupyter Node +## Goal +* Use notebook like +* https://streamlit.io/ +* juypterlab +* docker seems much faster than packer and devcontainer when creating the initial image + + + +## Tasks +* docker debian bookworm minimal +* Install conda (micromamba) +* Install JupyterLab Notebook + * Check iKernels + * Check Configurations +* [ ] Add nice to haves +## Validation Criteria +* [ ] conda is installed +* [ ] python is installed + * (micromamba doesnt install python right away) +* [ ] jupyterlab is installed +* [ ] jupyterlab is running +* [ ] jupyterlab is accessible from the host +* [ ] jupyterlab is accessible from the browser +* [ ] jupyterlab is accessible w/o token + +### Nice to haves +* [ ] Save conda environment.env +* [ ] Save jupyterlab configurations +* [ ] Nice Tutorial + + +# Dev note +* Using docker to streamline the speed +* and/or packer + +## Docker +* Entry Point to smoke test + +```bash +# Docker +# assuming pwd is conda-jupyter-node/ +# docker build -t jchan48h/conda-jupyter-node ./docker +docker image prune -f +docker container prune -f +exit +docker compose -f ./docker/docker-compose.yml rm --force --volumes +docker compose -f ./docker/docker-compose.yml down --remove-orphans --volumes +docker compose -f ./docker/docker-compose.yml up +docker compose -f ./docker/docker-compose.yml up --build +# docker compose -f ./docker/docker-compose.yml +# docker run attaches to the terminal +docker run -it --rm --name conda-jupyter-node --hostname cfn conda-jupyter-node:latest /bin/zsh +# smoke tests +pwd |grep webapp +tree `pwd` +exit + +# health check - in another terminal +docker container ls | grep conda-jupyter-node |grep health +docker image ls +``` + + +# docker run --entrypoint /new/entrypoint your_image +``` + +# Backlog +* node / npm +* zsh +* tree +* oh-my-zsh + * https://github.com/devcontainers-contrib/features/tree/main/src/zsh-plugins +* tmux +* https://codeforwings.github.io/vite-press-docs/posix/docs_readme_bash.html#install-oh-my-zsh + +# Not Planned +* ssh +* git ocnfig +* packer +* voila +* network etc. +* [ ] Add vscode snippets +* [ ] vscode extention +* jetbrains... +* migrate / check the codespace sample +* squid / apt-cacher-ng + * just ignore for now.. docker is fast enough From 21780bbad02f7430ed021998be972097ff33d8fb Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 27 Feb 2024 22:22:23 -0500 Subject: [PATCH 2/9] Update docs_readme_conda_jupyter_node.md --- .../conda-jupyter-node/docs_readme_conda_jupyter_node.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md index 465c14f..5e65403 100644 --- a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md +++ b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md @@ -46,8 +46,8 @@ docker container prune -f exit docker compose -f ./docker/docker-compose.yml rm --force --volumes docker compose -f ./docker/docker-compose.yml down --remove-orphans --volumes -docker compose -f ./docker/docker-compose.yml up docker compose -f ./docker/docker-compose.yml up --build +docker compose -f ./docker/docker-compose.yml up -d # detached # docker compose -f ./docker/docker-compose.yml # docker run attaches to the terminal docker run -it --rm --name conda-jupyter-node --hostname cfn conda-jupyter-node:latest /bin/zsh From a3e327d22e9d0d51dd8cb6cbfad159b832d81c03 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 28 Feb 2024 00:43:39 -0500 Subject: [PATCH 3/9] added omz making the script more robust --- devcontainers/conda-jupyter-node/README.md | 8 +- .../conda-jupyter-node/docker/Dockerfile | 28 +++-- .../docker/docker-compose.yml | 3 + .../docker/entrypoints/smoke-tests.sh | 15 ++- .../docker/lib/readme_zsh_plugin_copy.md | 99 +++++++++++++++ .../docker/lib/readme_zsh_plugin_copy.md.sh | 115 ++++++++++++++++++ .../docker/lib/zsh-plugins-install.copy.sh | 68 +++++++++++ .../docs_readme_conda_jupyter_node.md | 10 +- 8 files changed, 330 insertions(+), 16 deletions(-) create mode 100644 devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md create mode 100644 devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh create mode 100644 devcontainers/conda-jupyter-node/docker/lib/zsh-plugins-install.copy.sh diff --git a/devcontainers/conda-jupyter-node/README.md b/devcontainers/conda-jupyter-node/README.md index 8070ae5..bb4837b 100644 --- a/devcontainers/conda-jupyter-node/README.md +++ b/devcontainers/conda-jupyter-node/README.md @@ -5,6 +5,10 @@ cd devcontainers/conda-jupyter-node code devcontainers/conda-jupyter-node ``` ```bash -docker build -t jchan48h/conda-jupyter-node ./docker -docker run -it --rm --name conda-jupyter-node --hostname cjn jchan48h/conda-jupyter-node /bin/zsh +docker compose -f ./docker/docker-compose.yml up -d # detached + +docker compose -f ./docker/docker-compose.yml start +docker compose -f ./docker/docker-compose.yml attach webapp # will kill if exit + +docker compose -f ./docker/docker-compose.yml exec webapp /bin/zsh ``` \ No newline at end of file diff --git a/devcontainers/conda-jupyter-node/docker/Dockerfile b/devcontainers/conda-jupyter-node/docker/Dockerfile index bc308bd..867163d 100644 --- a/devcontainers/conda-jupyter-node/docker/Dockerfile +++ b/devcontainers/conda-jupyter-node/docker/Dockerfile @@ -3,27 +3,35 @@ FROM debian:bookworm-slim # known dependencies: curl # dev dependencies: zsh tree tldr git wget +# omz: git ca-certificates procps (ps) RUN apt-get update && apt-get install -y \ curl \ - zsh tree wget git \ + zsh tree wget git ca-certificates procps \ && rm -rf /var/lib/apt/lists/* # rm -rf /var/lib/apt/lists/* is to clean up after apt-get # maybe add tmux etc. only # assume mounted docker to /webapp using compose +SHELL ["/bin/bash", "-c"] + +# won't actually mount anything. it's for documentation +VOLUME ["/webapp"] WORKDIR /webapp # COPY . /webapp # using compose to mount - +# copy lib over for zsh? or nah # default port for jupterlab EXPOSE 8888 -# Entrypoint for smoke testing / health check -# might sneakily use it to run conda though? -RUN tree `pwd` -f -HEALTHCHECK --interval=5m --timeout=3s \ - CMD curl -f http://localhost:8888/ || exit 1 -# RUN ls -l chmod +rx ./entrypoints/smoke-test.sh -# ENTRYPOINT [ "./entrypoints/smoke-test.sh" ] -CMD /bin/zsh +HEALTHCHECK --interval=5m --timeout=3s \ + CMD set -euxo pipefail; printenv SHELL | grep -i zsh ; \ + curl -f http://localhost:8888/ || exit 1 +# entrypoint if mounting using compose has to be in compose +# ENTRYPOINT [ "./entrypoints/smoke-tests.sh" ] +# cmd is also overided by compose since entrypoint was declared there +SHELL ["/bin/zsh", "-c"] +ENV SHELL=/usr/bin/zsh +COPY ./lib/*.sh ./lib/ +RUN set -x ; chsh -s $(which zsh) && ./lib/readme_zsh_plugin_copy.md.sh +CMD /bin/zsh diff --git a/devcontainers/conda-jupyter-node/docker/docker-compose.yml b/devcontainers/conda-jupyter-node/docker/docker-compose.yml index 457492e..1b21d12 100644 --- a/devcontainers/conda-jupyter-node/docker/docker-compose.yml +++ b/devcontainers/conda-jupyter-node/docker/docker-compose.yml @@ -8,6 +8,7 @@ services: # comment out to skip build # called docker-webapp for some reason container_name: jupyter-webapp + hostname: jupyter-webapp # for dev: maybe should add a dev env file stdin_open: true # docker run -i. needed until a service is running tty: true # docker run -t. instead of bash... cuz bash is not a service @@ -15,6 +16,8 @@ services: build: context: . dockerfile: ./Dockerfile + entrypoint: ./entrypoints/smoke-tests.sh # defn worked + command: /bin/zsh # since entrypoint is defined # image: jchan48h/conda-jupyter-node volumes: - .:/webapp diff --git a/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh b/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh index 8e4f22e..a059609 100644 --- a/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh +++ b/devcontainers/conda-jupyter-node/docker/entrypoints/smoke-tests.sh @@ -1,6 +1,17 @@ #!/usr/bin/env bash +## note entry points run everytime the container starts set -euxo pipefail -echo /etc/os-release +# LOGNAME=root +# USER=${USERNAME:LOGNAME:-root} +USER=${USERNAME:-root} +# USER=${LOGNAM:-root} +cat /etc/os-release | grep ID # ID=debian printenv | grep -i home +getent passwd $USER | head -n 1 | cut -d: -f7 # check which is the default shell +getent passwd $USER | head -n 1 | cut -d: -f7 | grep -i zsh +printenv SHELL | grep -i zsh # doesn't need to be bash even -# using healthcheck as well \ No newline at end of file +# using healthcheck as well +# lib/readme_zsh_plugin_copy.md.sh + +exec "$@" diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md new file mode 100644 index 0000000..c794d49 --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md @@ -0,0 +1,99 @@ +# Useful stuff +* should have the command to download these two files +* and run +* `check_packages` + * it's legit + * it checks the lists before doing apt update + * but it should probably clean up after itself being inside of a docker + +## zsh plugins +* https://github.com/zsh-users?q=&type=all&language=&sort= + * omz plugins are here +* plugins are the official ones? + * https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins + +# Check Shell +```bash +cat /etc/shells +printenv SHELL +echo $SHELL +getent passwd $USER | cut -d: -f7 +getent passwd $USER | cut -d: -f7 | head -n 1 # probably most accurate one +getent passwd $USER |grep -i zsh #aaaa +getent passwd $USER | head -n 1 | cut -d: -f7 # this ? unless it's different shoudl try +# after set +SHELL=/usr/bin/zsh +chsh -s $(which zsh) +chsh -s /usr/bin/zsh +# set -x is to print each command. set +x +set +x +echo chsh -s $(which zsh) +set -x ; chsh -s $(which zsh) +ps -p $$ # +# interesting +# install ps +apt install procps +sudo apt-get update && apt-get install -y procps + +# optional installs +# or i should have slim and non slim? +# feels more liek a packer thing here +``` + +# Schema here +```jsonc +{ + "name": "ZSH Plugins", + "id": "zsh-plugins", + "version": "0.0.4", + "description": "Install (Oh-My-)ZSH plugins", + "documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/zsh-plugins", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/devcontainers/features/git" + ], + "options": { + "plugins": { + "type": "string", + "default": "", + "proposals": [ + "ssh-agent npm" + ], + "description": "Space separated list of ZSH plugin names that will be added to .zshrc" + }, + "omzPlugins": { + "type": "string", + "default": "", + "proposals": [ + "https://github.com/zsh-users/zsh-autosuggestions" + ], + "description": "Space separated list of Oh-My-ZSH custom plugin Git URLs that will be cloned" + }, + "username": { + "type": "string", + "default": "", + "proposals": [ + "root", + "node", + "vscode" + ], + "description": "For which user to setup ZSH plugins, by default uses 'remoteUser' or 'containerUser' from config" + } + } +} +``` +```bash +#!/usr/bin/env bash +# my install and experiment +# check envs +printenv USERNAME +printenv $_REMOTE_USER +printenv _REMOTE_USER +printenv USER +echo $USER + +export USERNAME=${USERNAME:-root} +printenv USERNAME +unset USERNAME + +``` \ No newline at end of file diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh new file mode 100644 index 0000000..8cfce6c --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# https://github.com/devcontainers-contrib/features/blob/main/src/zsh-plugins/install.sh +# https://github.com/devcontainers-contrib/features/tree/main/src/zsh-plugins +# using their plugin's sh... interesting +# isn't it user? +# or use $HOME? lol +# LOGNAME=root +# hardcodign root for now as default +# author is using it for finding home directory.. w/e +export USERNAME=${USERNAME:-root} +# space seperated ones to add to ~/.zshrc +# export PLUGINS="ssh-agent npm" +## the plugins didnt get added... as expected... +# https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins +# git is defaulted +export PLUGINS="ssh-agent npm zsh-autosuggestions zsh-syntax-highlighting zsh-completions python docker docker-compose gh yarn node" +# export PLUGINS="${PLUGINS} rsync dotenv" +# if ID is debian append debian to plugins +if [ -f /etc/os-release ]; then + if cat /etc/os-release | grep ID | grep debian; then + export PLUGINS="${PLUGINS} debian" + elif cat /etc/os-release | grep ID | grep ubuntu; then + export PLUGINS="${PLUGINS} ubuntu" + fi +fi +# export PLUGINS="${PLUGINS} rsync " + +# https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/composer +# might be useful +# need to add rsync +# ones to git clone into ~/.oh-my-zsh/custom/plugins +# https://github.com/zsh-users?q=&type=all&language=&sort= +# should write a quick parser for this +export OMZPLUGINS="https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-completions" +# wonder if they they need to be repeated? +# get current script directory +current_script_path="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" +script_directory="$(dirname "$current_script_path")" +# test if ~/.ssh exists and if not create it +if [ ! -d ~/.ssh ]; then + # for the ssh-agent plugin + mkdir -p ~/.ssh + chmod 700 ~/.ssh +fi +# should check zsh / chsh before continue +chsh -s /usr/bin/zsh +# Run +$script_directory/zsh-plugins-install.copy.sh + +# source again +# https://codeforwings.github.io/vite-press-docs/posix/docs_readme_bash.html#zshrc +echo 'PROMPT="$USERNAME@`hostname`%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} "' >> ~/.zshrc + +if [ $(tput colors) == "256" ]; then + # maybe i should check before doing so. and add my own little snippet + echo 'export TERM=xterm-256color' >> ~/.zshrc +fi +source ~/.zshrc +exit 0 +##### +lib/readme_zsh_plugin_copy.md.sh + +# debug plugins +cat ~/.zshrc | grep plugins + + +### +pwd +./lib/readme_zsh_plugin_copy.md.sh +bash ./lib/readme_zsh_plugin_copy.md.sh +tree -A ./lib +chmod +x ./lib/readme_zsh_plugin_copy.md.sh +git update-index --chmod=+x ./lib/readme_zsh_plugin_copy.md.sh +# Schema here +: +{ + "name": "ZSH Plugins", + "id": "zsh-plugins", + "version": "0.0.4", + "description": "Install (Oh-My-)ZSH plugins", + "documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/zsh-plugins", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/devcontainers/features/git" + ], + "options": { + "plugins": { + "type": "string", + "default": "", + "proposals": [ + "ssh-agent npm" + ], + "description": "Space separated list of ZSH plugin names that will be added to .zshrc" + }, + "omzPlugins": { + "type": "string", + "default": "", + "proposals": [ + "https://github.com/zsh-users/zsh-autosuggestions" + ], + "description": "Space separated list of Oh-My-ZSH custom plugin Git URLs that will be cloned" + }, + "username": { + "type": "string", + "default": "", + "proposals": [ + "root", + "node", + "vscode" + ], + "description": "For which user to setup ZSH plugins, by default uses 'remoteUser' or 'containerUser' from config" + } + } +} +# end diff --git a/devcontainers/conda-jupyter-node/docker/lib/zsh-plugins-install.copy.sh b/devcontainers/conda-jupyter-node/docker/lib/zsh-plugins-install.copy.sh new file mode 100644 index 0000000..e73cab0 --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/lib/zsh-plugins-install.copy.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +## raw file from this +# https://raw.githubusercontent.com/devcontainers-contrib/features/main/src/zsh-plugins/install.sh +## main source +# https://github.com/devcontainers-contrib/features/blob/main/src/zsh-plugins/install.sh +## tests source +# https://github.com/devcontainers-contrib/features/tree/main/test/zsh-plugins +set -x +PLUGINS=${PLUGINS:-""} +OMZSH_PLUGINS=${OMZPLUGINS:-""} +USERNAME=${USERNAME:-$_REMOTE_USER} + + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + + +check_packages git ca-certificates + +# ensure zsh is installed +if ! type zsh >/dev/null 2>&1; then + check_packages zsh +fi + +if [ "$USERNAME" = "root" ]; then + USER_LOCATION="/root" +else + USER_LOCATION="/home/$USERNAME" +fi + +# ensure oh-my-zsh installed +if ! [ -d $USER_LOCATION/.oh-my-zsh ]; then + check_packages wget + sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" +fi + +ZSH_CONFIG="$USER_LOCATION/.zshrc" +OMZSH_PLUGINS_LOCATION="$USER_LOCATION/.oh-my-zsh/custom/plugins" + +# Install custom oh-my-zsh plugins from OMZSH_PLUGINS +currdir=$(pwd) +mkdir -p "$OMZSH_PLUGINS_LOCATION" +cd "$OMZSH_PLUGINS_LOCATION" || exit + +IFS=' ' read -ra plugins <<< "${OMZSH_PLUGINS}" + +for plugin in "${plugins[@]}" +do + git clone --depth 1 $plugin +done + +cd "$currdir" || exit + +# create configuration file if not exists +if ! [ -f "$ZSH_CONFIG" ]; then + mkdir -p "$(dirname "$ZSH_CONFIG")" && touch "$ZSH_CONFIG" +fi + +# Activate zsh plugins from PLUGINS +sed -i -e "s/plugins=.*/plugins=(git ${PLUGINS})/g" "$ZSH_CONFIG" diff --git a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md index 5e65403..2403a87 100644 --- a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md +++ b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md @@ -46,11 +46,17 @@ docker container prune -f exit docker compose -f ./docker/docker-compose.yml rm --force --volumes docker compose -f ./docker/docker-compose.yml down --remove-orphans --volumes +docker compose -f ./docker/docker-compose.yml down docker compose -f ./docker/docker-compose.yml up --build +docker compose -f ./docker/docker-compose.yml up --build -d docker compose -f ./docker/docker-compose.yml up -d # detached +docker compose -f ./docker/docker-compose.yml up # to see the logs +docker compose -f ./docker/docker-compose.yml start +docker compose -f ./docker/docker-compose.yml attach webapp # will kill if exit +docker compose -f ./docker/docker-compose.yml exec webapp /bin/zsh # docker compose -f ./docker/docker-compose.yml # docker run attaches to the terminal -docker run -it --rm --name conda-jupyter-node --hostname cfn conda-jupyter-node:latest /bin/zsh +# docker run -it --rm --name conda-jupyter-node --hostname cfn conda-jupyter-node /bin/zsh # smoke tests pwd |grep webapp tree `pwd` @@ -59,7 +65,7 @@ exit # health check - in another terminal docker container ls | grep conda-jupyter-node |grep health docker image ls -``` +```fac # docker run --entrypoint /new/entrypoint your_image From 2e3bbf5e52ff6f120feac6b057a1d3568fa5343d Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 28 Feb 2024 01:21:30 -0500 Subject: [PATCH 4/9] added configurations --- .../conda-jupyter-node/docker/Dockerfile | 2 + .../docker/lib/readme_zsh_plugin_copy.md | 4 ++ .../docker/lib/readme_zsh_plugin_copy.md.sh | 22 ++++++++++- .../docker/tests/smoke-test-0.sh | 38 +++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh diff --git a/devcontainers/conda-jupyter-node/docker/Dockerfile b/devcontainers/conda-jupyter-node/docker/Dockerfile index 867163d..23df96e 100644 --- a/devcontainers/conda-jupyter-node/docker/Dockerfile +++ b/devcontainers/conda-jupyter-node/docker/Dockerfile @@ -32,6 +32,8 @@ HEALTHCHECK --interval=5m --timeout=3s \ # cmd is also overided by compose since entrypoint was declared there SHELL ["/bin/zsh", "-c"] ENV SHELL=/usr/bin/zsh +ENV LANG=en_CA.UTF-8 +ENV TERM=xterm-256color COPY ./lib/*.sh ./lib/ RUN set -x ; chsh -s $(which zsh) && ./lib/readme_zsh_plugin_copy.md.sh CMD /bin/zsh diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md index c794d49..b2326b9 100644 --- a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md @@ -40,6 +40,10 @@ sudo apt-get update && apt-get install -y procps # feels more liek a packer thing here ``` +# todo +* [ ] add sudo +* [ ] rsync? + # Schema here ```jsonc { diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh index 8cfce6c..41e2abf 100644 --- a/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_zsh_plugin_copy.md.sh @@ -51,8 +51,9 @@ $script_directory/zsh-plugins-install.copy.sh # https://codeforwings.github.io/vite-press-docs/posix/docs_readme_bash.html#zshrc echo 'PROMPT="$USERNAME@`hostname`%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} "' >> ~/.zshrc -if [ $(tput colors) == "256" ]; then +if [ $(tput colors -T xterm-256color) == "256" ]; then # maybe i should check before doing so. and add my own little snippet + # tput colors -T xterm-256color echo 'export TERM=xterm-256color' >> ~/.zshrc fi source ~/.zshrc @@ -63,6 +64,25 @@ lib/readme_zsh_plugin_copy.md.sh # debug plugins cat ~/.zshrc | grep plugins +# interesting i can install xterm +# but i think that's a gui app +# debug term +echo $TERM +# tree looks funny +pstree -s $$ +ps -o comm= -p $(ps -o ppid= -p $$) + +# encoding +# empty... +echo $LC_CTYPE +echo $LANG +printenv LC_CTYPE +printenv LANG +echo -e '\xe2\x82\xac' +echo -e '\xe2\x82\xac' | grep '€' # doesnt work lol +echo -e '\xe2\x82\xac' | grep -P '\xe2\x82\xac' +iconv -f utf-8 -t utf-8 <<< '\xe2\x82\xac' # € +luit -encoding utf-8 echo -e '\xe2\x82\xac' # € ### pwd diff --git a/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh b/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh new file mode 100644 index 0000000..fe20df3 --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# set -euxo pipefail +# set -x + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + +# Check Packages +log_packages() { + echo "Checking for packages: $@" + for package in "$@"; do + # if not in whence which command type? + if which "$package" > /dev/null 2>&1 ; then + # echo green text to stdout + echo -e "Package \e[32m$package\e[0m is in path" "\xE2\x9C\x94""\xE2\x9C\x94" + elif ! dpkg -s "$package" >/dev/null 2>&1; then + # echo red text to stdout + echo -e "Package \e[31m$package\e[0m is not installed" + # echo -e "Package \e[31m$package\e[0m is not installed" >&2 + # echo "Package $package is not installed" + else + echo -e "Package \e[32m$package\e[0m is installed" "\xE2\x9C\x94" + fi + done +} + +log_packages git ca-certificates zsh wget +exit 0 +./tests/smoke-test-0.sh + From 8f0b7b3c7665701a3a9888fb18dacc63e5c7e4b3 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 28 Feb 2024 02:07:38 -0500 Subject: [PATCH 5/9] updated notes on jupter lab and conda --- devcontainers/conda-jupyter-node/README.md | 1 + .../conda-jupyter-node/docker/Dockerfile | 2 +- .../docker/docker-compose.yml | 3 + .../readme_micromamba_conda_install.md.zsh | 71 +++++++++++++++++++ .../docker/tests/smoke-test-0.sh | 6 +- .../docs_readme_conda_jupyter_node.md | 44 +++++++++--- 6 files changed, 113 insertions(+), 14 deletions(-) create mode 100644 devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh diff --git a/devcontainers/conda-jupyter-node/README.md b/devcontainers/conda-jupyter-node/README.md index bb4837b..3409485 100644 --- a/devcontainers/conda-jupyter-node/README.md +++ b/devcontainers/conda-jupyter-node/README.md @@ -6,6 +6,7 @@ code devcontainers/conda-jupyter-node ``` ```bash docker compose -f ./docker/docker-compose.yml up -d # detached +docker compose -f ./docker/docker-compose.yml up -d --build # docker compose -f ./docker/docker-compose.yml start docker compose -f ./docker/docker-compose.yml attach webapp # will kill if exit diff --git a/devcontainers/conda-jupyter-node/docker/Dockerfile b/devcontainers/conda-jupyter-node/docker/Dockerfile index 23df96e..617b374 100644 --- a/devcontainers/conda-jupyter-node/docker/Dockerfile +++ b/devcontainers/conda-jupyter-node/docker/Dockerfile @@ -6,7 +6,7 @@ FROM debian:bookworm-slim # omz: git ca-certificates procps (ps) RUN apt-get update && apt-get install -y \ curl \ - zsh tree wget git ca-certificates procps \ + zsh tree wget git ca-certificates procps tar bzip2 \ && rm -rf /var/lib/apt/lists/* # rm -rf /var/lib/apt/lists/* is to clean up after apt-get # maybe add tmux etc. only diff --git a/devcontainers/conda-jupyter-node/docker/docker-compose.yml b/devcontainers/conda-jupyter-node/docker/docker-compose.yml index 1b21d12..a5744c7 100644 --- a/devcontainers/conda-jupyter-node/docker/docker-compose.yml +++ b/devcontainers/conda-jupyter-node/docker/docker-compose.yml @@ -21,3 +21,6 @@ services: # image: jchan48h/conda-jupyter-node volumes: - .:/webapp + + ports: + - "8888:8888" diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh b/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh new file mode 100644 index 0000000..bf153a9 --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh @@ -0,0 +1,71 @@ +#!/usr/bin/env zsh +set -euxo pipefail + +# copied +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + +cd $HOME +# mkdir -p $HOME/bin +# curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest +# https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html#linux-and-macos +# apt update # needed bzip2 +# apt install -y bzip2 +curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba +# curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C bin/micromamba +eval "$(./bin/micromamba shell hook -s posix)" +# assuming zsh... should maybe should change that +./bin/micromamba shell init -s zsh -p ~/micromamba +source ~/.zshrc +alias conda=micromamba + +# set default +micromamba config append channels conda-forge +micromamba config set channel_priority strict + +# this might not work... because it might create a new shell +# right... that's why i think the instructions told us to use the bin +micromamba activate # this activates the base environment +micromamba create -y --name 311 python=3.11 pipx poetry +micromamba activate 311 + +conda install -y jupyterlab nodejs + +# conda env export --no-prefix > environment.yml +# conda env export > environment.yml +# conda env export +conda env export --from-history +# node --version +# this is going to take a bit of time to try... + +# should check if it set +exit 0 +/webapp/tests/smoke-test-0.sh +./lib/readme_micromamba_conda_install.md.zsh +###### jupyter lab --no-browser +jupyter lab +jupyter lab --no-browser +jupyter lab --no-browser --allow-root + + +# figure out later +# jupyter lab --no-browser --allow-root --no-token +jupyter lab --help-all |grep -i token +jupyter lab --help-all |grep -i no +jupyter lab --help-all |grep -i pass +jupyter lab --help-all |grep -i auth + +### conda aliased +conda env list +# use port forward +# localhost:8888 +# by attaching if forgot +file:///root/.local/share/jupyter/runtime/jpserver-4201-open.html \ No newline at end of file diff --git a/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh b/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh index fe20df3..d28233d 100644 --- a/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh +++ b/devcontainers/conda-jupyter-node/docker/tests/smoke-test-0.sh @@ -31,8 +31,10 @@ log_packages() { fi done } - -log_packages git ca-certificates zsh wget +log_packages tar curl bzip2 micromamba python pip pipx jupyter node exit 0 +######### ./tests/smoke-test-0.sh +# debug works well: +log_packages git ca-certificates zsh wget diff --git a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md index 2403a87..0d3382b 100644 --- a/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md +++ b/devcontainers/conda-jupyter-node/docs_readme_conda_jupyter_node.md @@ -2,7 +2,7 @@ ## Goal * Use notebook like * https://streamlit.io/ -* juypterlab +* jupyterLab Notebook * docker seems much faster than packer and devcontainer when creating the initial image @@ -15,13 +15,13 @@ * Check Configurations * [ ] Add nice to haves ## Validation Criteria -* [ ] conda is installed -* [ ] python is installed +* [x] conda is installed +* [x] python is installed * (micromamba doesnt install python right away) -* [ ] jupyterlab is installed +* [x] jupyterlab is installed * [ ] jupyterlab is running * [ ] jupyterlab is accessible from the host -* [ ] jupyterlab is accessible from the browser +* [x] jupyterlab is accessible from the browser * [ ] jupyterlab is accessible w/o token ### Nice to haves @@ -72,17 +72,18 @@ docker image ls ``` # Backlog -* node / npm -* zsh -* tree -* oh-my-zsh +* https://codeforwings.github.io/vite-press-docs/posix/docs_readme_bash.html#install-oh-my-zsh + +* [x] node / npm +* [x] zsh +* [x] tree +* [x] oh-my-zsh * https://github.com/devcontainers-contrib/features/tree/main/src/zsh-plugins * tmux -* https://codeforwings.github.io/vite-press-docs/posix/docs_readme_bash.html#install-oh-my-zsh # Not Planned * ssh -* git ocnfig +* git config * packer * voila * network etc. @@ -92,3 +93,24 @@ docker image ls * migrate / check the codespace sample * squid / apt-cacher-ng * just ignore for now.. docker is fast enough + + + +# JuptyerLab +```bash +jupyter notebook --generate-config +jupyter notebook password +jupyter lab list +jupyter lab --help +jupyter lab --ip=0.0.0.0 +jupyter lab --no-browser +jupyter lab --notebook-dir=/path/to/notebook/directory +# right... need to default th theme etc +``` + +# Other kernels +* https://docs.jupyter.org/en/latest/projects/kernels.html +* https://github.com/jupyter/jupyter/wiki/Jupyter-kernels + +* https://github.com/n-riesco/ijavascript + * ijavascript \ No newline at end of file From f8c965e7f44aa2bbf511e72fdc1ea27c128faff3 Mon Sep 17 00:00:00 2001 From: JC Date: Wed, 28 Feb 2024 15:36:40 -0500 Subject: [PATCH 6/9] updated docker notes --- .../docker/docker-compose.override.yml | 11 +++++++++++ .../docker/entrypoints/labs/conda-micromamba.sh | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 devcontainers/conda-jupyter-node/docker/docker-compose.override.yml create mode 100644 devcontainers/conda-jupyter-node/docker/entrypoints/labs/conda-micromamba.sh diff --git a/devcontainers/conda-jupyter-node/docker/docker-compose.override.yml b/devcontainers/conda-jupyter-node/docker/docker-compose.override.yml new file mode 100644 index 0000000..e80751d --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/docker-compose.override.yml @@ -0,0 +1,11 @@ +# Docker Compose for mounting volumes during build +version: "3.8" +services: + webapp: + # entrypoint: ./entrypoints/smoke-tests.sh # defn worked + entrypoint: ./entrypoints/labs/conda-micromamba.sh + + + # ports is it annray... gest appendd + # ports: + # - "8888:8888" diff --git a/devcontainers/conda-jupyter-node/docker/entrypoints/labs/conda-micromamba.sh b/devcontainers/conda-jupyter-node/docker/entrypoints/labs/conda-micromamba.sh new file mode 100644 index 0000000..c231d17 --- /dev/null +++ b/devcontainers/conda-jupyter-node/docker/entrypoints/labs/conda-micromamba.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +## note entry points run everytime the container starts +set -euxo pipefail +USER=${USERNAME:-root} +cat /etc/os-release | grep ID # ID=debian +printenv | grep -i home +getent passwd $USER | head -n 1 | cut -d: -f7 # check which is the default shell +getent passwd $USER | head -n 1 | cut -d: -f7 | grep -i zsh +printenv SHELL | grep -i zsh + + +exec "$@" From 8ac4e4e570537596bcdab19498a67b0536fda9f3 Mon Sep 17 00:00:00 2001 From: JC Date: Sat, 2 Mar 2024 19:35:15 -0500 Subject: [PATCH 7/9] updated gitmodules --- .gitmodules | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitmodules b/.gitmodules index b7efcb4..a852e75 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,13 @@ [submodule "test/bats"] path = test/bats url = https://github.com/bats-core/bats-core.git + branch = master [submodule "test/test_helper/bats-support"] path = test/test_helper/bats-support url = https://github.com/bats-core/bats-support.git + branch = master [submodule "test/test_helper/bats-assert"] path = test/test_helper/bats-assert url = https://github.com/bats-core/bats-assert.git + branch = master + From c654e8e33ea54fa0d687b15e3003c2bf701da450 Mon Sep 17 00:00:00 2001 From: JC Date: Sat, 2 Mar 2024 19:37:44 -0500 Subject: [PATCH 8/9] commit was updated --- test/bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bats b/test/bats index 18eca24..ab2a86e 160000 --- a/test/bats +++ b/test/bats @@ -1 +1 @@ -Subproject commit 18eca2496cbd80ac97c73a70002e7ab4fb2179cf +Subproject commit ab2a86edc669c3344ea023a5c055ce96a5d05634 From 5b8303baf063135a8a3f927beb31738093656c9b Mon Sep 17 00:00:00 2001 From: JC Date: Fri, 24 May 2024 09:11:52 -0400 Subject: [PATCH 9/9] Update readme_micromamba_conda_install.md.zsh --- .../docker/lib/readme_micromamba_conda_install.md.zsh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh b/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh index bf153a9..1fc1d86 100644 --- a/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh +++ b/devcontainers/conda-jupyter-node/docker/lib/readme_micromamba_conda_install.md.zsh @@ -36,6 +36,12 @@ micromamba config set channel_priority strict micromamba activate # this activates the base environment micromamba create -y --name 311 python=3.11 pipx poetry micromamba activate 311 +micromamba create -y --name 312 python=3.12 pipx poetry +micromamba activate 312 + +pipx install pipx +pipx ensurepath +pipx completion conda install -y jupyterlab nodejs @@ -68,4 +74,4 @@ conda env list # use port forward # localhost:8888 # by attaching if forgot -file:///root/.local/share/jupyter/runtime/jpserver-4201-open.html \ No newline at end of file +# file:///root/.local/share/jupyter/runtime/jpserver-4201-open.html \ No newline at end of file