|
| 1 | +################################################################################ |
| 2 | +# Base |
| 3 | +# - a single-version python slim-bullseye image |
| 4 | +# Installs |
| 5 | +# - poetry in /opt/poetry |
| 6 | +# - adds a user called 'zen' |
| 7 | +# Size |
| 8 | +# - 300MB |
| 9 | +################################################################################ |
| 10 | + |
| 11 | +ARG PYTHON_VERSION=3.8.15 |
| 12 | +ARG DEBIAN_VERSION=bullseye |
| 13 | + |
| 14 | +FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} |
| 15 | + |
| 16 | +ARG NAME=poetry-zen |
| 17 | +ARG POETRY_VERSION=1.3.2 |
| 18 | +ENV POETRY_HOME=/opt/poetry |
| 19 | +ENV PATH="${POETRY_HOME}/bin:${PATH}" |
| 20 | + |
| 21 | +################################################################################ |
| 22 | +# Poetry |
| 23 | +################################################################################ |
| 24 | + |
| 25 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 26 | + # For poetry |
| 27 | + curl \ |
| 28 | + # For pytrees |
| 29 | + graphviz \ |
| 30 | + make \ |
| 31 | + # For convenience |
| 32 | + bash \ |
| 33 | + bash-completion \ |
| 34 | + ca-certificates \ |
| 35 | + git \ |
| 36 | + less \ |
| 37 | + ssh \ |
| 38 | + vim \ |
| 39 | + wget \ |
| 40 | + && \ |
| 41 | + curl -sSL https://install.python-poetry.org | POETRY_VERSION=${POETRY_VERSION} python3 - && \ |
| 42 | + poetry config virtualenvs.create false && \ |
| 43 | + poetry completions bash >> ~/.bash_completion |
| 44 | + |
| 45 | +################################################################################ |
| 46 | +# Login Shells for Debugging & Development |
| 47 | +################################################################################ |
| 48 | + |
| 49 | +# In a login shell (below), the PATH env doesn't survive, configure it at ground zero |
| 50 | +RUN echo "export PATH=${POETRY_HOME}/bin:${PATH}" >> /etc/profile |
| 51 | +ENV TERM xterm-256color |
| 52 | +ENTRYPOINT ["/bin/bash", "--login", "-i"] |
| 53 | + |
| 54 | +################################################################################ |
| 55 | +# Development with a user, e.g. for vscode devcontainers |
| 56 | +################################################################################ |
| 57 | + |
| 58 | +ARG USERNAME=zen |
| 59 | +ARG USER_UID=1000 |
| 60 | +ARG USER_GID=${USER_UID} |
| 61 | + |
| 62 | +RUN groupadd --gid $USER_GID $USERNAME && \ |
| 63 | + useradd --uid $USER_UID --gid $USER_GID -s "/bin/bash" -m $USERNAME && \ |
| 64 | + apt-get install -y sudo && \ |
| 65 | + echo "${USERNAME} ALL=NOPASSWD: ALL" > /etc/sudoers.d/${USERNAME} && \ |
| 66 | + chmod 0440 /etc/sudoers.d/${USERNAME} |
| 67 | +RUN echo "export PS1='\[\033[01;36m\](docker)\[\033[00m\] \[\033[01;32m\]\u@${NAME}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >> /home/${USERNAME}/.bashrc && \ |
| 68 | + echo "alias ll='ls --color=auto -alFNh'" >> /home/${USERNAME}/.bashrc && \ |
| 69 | + echo "alias ls='ls --color=auto -Nh'" >> /home/${USERNAME}/.bashrc && \ |
| 70 | + poetry completions bash >> /home/${USERNAME}/.bash_completion |
| 71 | + |
| 72 | +# touch /home/${USERNAME}/.bash_completion && chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.bash_completion |
| 73 | + |
| 74 | +################################################################################ |
| 75 | +# Debugging with root |
| 76 | +################################################################################ |
| 77 | + |
| 78 | +RUN echo "export PS1='\[\033[01;36m\](docker)\[\033[00m\] \[\033[01;32m\]\u@${NAME}\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '" >> ${HOME}/.bashrc && \ |
| 79 | + echo "alias ll='ls --color=auto -alFNh'" >> ${HOME}/.bashrc && \ |
| 80 | + echo "alias ls='ls --color=auto -Nh'" >> ${HOME}/.bashrc |
0 commit comments