Skip to content

Instantly share code, notes, and snippets.

@stamate
Last active November 30, 2023 16:39
Show Gist options
  • Select an option

  • Save stamate/7bb5c956eafc8bebf2cff1d95a0c9c52 to your computer and use it in GitHub Desktop.

Select an option

Save stamate/7bb5c956eafc8bebf2cff1d95a0c9c52 to your computer and use it in GitHub Desktop.
ccnt
#!/usr/bin/env python3
import os
def write_file(file_name, content):
with open(file_name, 'w') as file:
file.write(content)
def main():
os.makedirs('container')
# Content of each file
docker_compose_content = f"""version: '3'
services:
{os.getcwd().split('/')[-1]}:
build:
context: .
dockerfile: Dockerfile
args:
- BASE=${{BASE}}
- WORKDIR=${{WORKDIR}}
- LAB_PASS=${{LAB_PASS}}
- LAB_PORT=${{LAB_PORT}}
- LAB_FONT_SIZE=${{LAB_FONT_SIZE}}
env_file:
- .env
working_dir: ${{WORKDIR}}
volumes:
- ..:${{WORKDIR}}
- ~/.ssh:/root/.ssh:ro
- ~/.gitconfig:/root/.gitconfig
ports:
- ${{LAB_PORT}}:${{LAB_PORT}}
"""
dockerfile_content = """ARG BASE
FROM ${BASE}
ENV PIP_ROOT_USER_ACTION ignore
ENV DEBIAN_FRONTEND noninteractive
ARG LAB_PORT
ENV LAB_PORT ${LAB_PORT}
ARG LAB_PASS
ENV LAB_PASS ${LAB_PASS}
ARG WORKDIR
ENV WORKDIR ${WORKDIR}
ARG LAB_FONT_SIZE
ENV LAB_FONT_SIZE ${LAB_FONT_SIZE}
## Add required libraries
RUN apt-get update && apt-get install -y \\
curl \\
zsh \\
git \\
nano \\
# tmux \\
build-essential \\
python3-dev \\
python3-pip \\
python3-tk \\
python3-cffi \\
python3-brotli
# libpango-1.0-0 \\
# libpangoft2-1.0-0
# Install jupyter + req stuff
RUN pip install --upgrade pip
RUN pip install jupyterlab
COPY requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
COPY entrypoint.sh /tmp/entrypoint.sh
RUN chmod +x /tmp/entrypoint.sh
# Jupyer configurations
RUN mkdir -p ~/.jupyter
RUN echo "c = get_config()\\n\\
c.ServerApp.ip = '0.0.0.0'\\n\\
c.ServerApp.port = ${LAB_PORT}\\n\\
c.ServerApp.root_dir = '${WORKDIR}'\\n\\
c.ServerApp.allow_remote_access = True\\n\\
c.ServerApp.allow_root = True\\n\\
c.ServerApp.allow_origin = '*'\\n\\
c.ServerApp.open_browser = False\\n\\
c.ServerApp.password = '${LAB_PASS}'\\n\\
c.ServerApp.iopub_msg_rate_limit = 100000000\\n\\
c.ServerApp.iopub_data_rate_limit = 2147483647\\n\\
c.ServerApp.port_retries = 0\\n\\
c.ServerApp.quit_button = False\\n\\
c.ServerApp.disable_check_xsrf = True\\n\\
c.ServerApp.trust_xheaders = True\\n\\
c.MappingKernelManager.buffer_offline_messages = True\\n\\
c.JupyterApp.answer_yes = True\\n\\
c.FileContentsManager.delete_to_trash = False\\n\\
c.IPKernelApp.matplotlib = 'inline'\\n" > ~/.jupyter/jupyter_lab_config.py
RUN mkdir -p ~/.jupyter/lab/user-settings/@jupyterlab/apputils-extension
RUN echo '{\\n\\
"theme": "JupyterLab Dark",\\n\\
"theme-scrollbars": true,\\n\\
"overrides": {\\n\\
"code-font-family": null,\\n\\
"code-font-size": "17px",\\n\\
"content-font-family": null,\\n\\
"content-font-size1": "17px",\\n\\
"ui-font-family": null,\\n\\
"ui-font-size1": "17px"\\n\\
}\\n\\
}\\n' > ~/.jupyter/lab/user-settings/@jupyterlab/apputils-extension/themes.jupyterlab-settings
RUN mkdir -p ~/.jupyter/lab/user-settings/@jupyterlab/terminal-extension
RUN echo '{\\n\\
"fontFamily": "monospace",\\n\\
"fontSize": 17,\\n\\
"lineHeight": 1,\\n\\
"theme": "inherit",\\n\\
"screenReaderMode": false,\\n\\
"scrollback": 1000,\\n\\
"shutdownOnClose": false,\\n\\
"closeOnExit": true,\\n\\
"pasteWithCtrlV": true,\\n\\
"macOptionIsMeta": false\\n\\
}\\n' > ~/.jupyter/lab/user-settings/@jupyterlab/terminal-extension/plugin.jupyterlab-settings
## Add tmux config
RUN curl -fsSL https://gist.githubusercontent.com/stamate/6dc1febded0ffde8816a2daa2c684d9f/raw/51a546868a727131b555bbd6fa6f311028009ff3/.tmux.conf -o ~/.tmux.conf
## Add on-my-zsh
RUN curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | zsh || tru
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
RUN curl -fsSL https://gist.githubusercontent.com/stamate/e50a21ad5663d51e9056f0c5398dfde0/raw -o ~/.zshrc
ENV SHELL /bin/zsh
ENTRYPOINT ["/tmp/entrypoint.sh"]
"""
entrypoint_content = """#!/bin/bash
jupyter lab
"""
requirements_content = """#base
numpy
pandas
scipy
scikit-learn
matplotlib
#jupyterlab
jupyterlab_sublime
jupyterlab-git
jupytext"""
env_content = f"""BASE=ubuntu:22.04
WORKDIR={os.getcwd()}
LAB_PORT=7777
LAB_PASS=sha1:b4e4e0deb244:a8b99d99395ec48ea1d22e0ed3f2773d268cf5c0
LAB_FONT_SIZE=16"""
# Writing each file
write_file('container/docker-compose.yml', docker_compose_content)
write_file('container/Dockerfile', dockerfile_content)
write_file('container/entrypoint.sh', entrypoint_content)
write_file('container/requirements.txt', requirements_content)
write_file('container/.env', env_content)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment