Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vscode|poetry] devcontainers, a poetry setup and basic testing #143

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
################################################################################
# Base
# - a single-version python slim-bullseye image
# Installs
# - poetry in /opt/poetry
# - adds a user called 'zen'
# Size
# - 300MB
################################################################################


ARG PYTHON_VERSION=3.8.15
ARG DEBIAN_VERSION=bullseye

ARG NAME=py-trees-js
ARG POETRY_VERSION=1.3.2

FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION}
# FROM ubuntu:20.04

ENV POETRY_HOME=/opt/poetry
ENV PATH="${POETRY_HOME}/bin:${PATH}"

################################################################################
# Debs
################################################################################

####################
# Core
####################
RUN apt-get update && apt-get install -y --no-install-recommends \
# poetry
curl \
python3-dev \
# pytrees
graphviz \
# development
bash \
bash-completion \
ca-certificates \
git \
less \
make \
ssh \
vim \
wget

####################
# OpenGL
####################
# mesa-utils : glxgears + gl libs (libgl# libglvnd#, libglx#)
# egl: not needed (libegl1, libgles2)
# vulkan: not needed
RUN apt-get install -y --no-install-recommends \
mesa-utils

####################
# Qt5 webengine
####################
# Should just install pyqt5webengine from debs instead?
RUN apt-get install -y --no-install-recommends \
libasound2 \
libdbus-1-dev \
libgl1 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxi6 \
libxkbcommon0 \
libxkbcommon-x11-0 \
libxrandr2 \
libxtst6

################################################################################
# Poetry
################################################################################

# Don't permit virtualenvs for root / ci jobs (this configuration).
# Do permit virtualenvs for user zen (uses the default).
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=${POETRY_VERSION} python3 - && \
poetry config virtualenvs.create false && \
poetry completions bash >> ~/.bash_completion


################################################################################
# NVIDIA
################################################################################

ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all}
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics,display,video,utility,compute

################################################################################
# Login Shells for Debugging & Development
################################################################################

# In a login shell (below), the PATH env doesn't survive, configure it at ground zero
RUN echo "export PATH=${POETRY_HOME}/bin:${PATH}" >> /etc/profile
ENV TERM xterm-256color
ENTRYPOINT ["/bin/bash", "--login", "-i"]

################################################################################
# Development with a user, e.g. for vscode devcontainers
################################################################################

ARG USERNAME=zen
ARG USER_UID=1001
ARG USER_GID=${USER_UID}

RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID -s "/bin/bash" -m $USERNAME && \
apt-get install -y sudo && \
echo "${USERNAME} ALL=NOPASSWD: ALL" > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME}
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 && \
echo "alias ll='ls --color=auto -alFNh'" >> /home/${USERNAME}/.bashrc && \
echo "alias ls='ls --color=auto -Nh'" >> /home/${USERNAME}/.bashrc && \
poetry completions bash >> /home/${USERNAME}/.bash_completion

# touch /home/${USERNAME}/.bash_completion && chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.bash_completion

################################################################################
# Debugging with root
################################################################################

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 && \
echo "alias ll='ls --color=auto -alFNh'" >> ${HOME}/.bashrc && \
echo "alias ls='ls --color=auto -Nh'" >> ${HOME}/.bashrc
103 changes: 103 additions & 0 deletions .devcontainer/Dockerfile copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
################################################################################
# Base
# - a single-version python slim-bullseye image
# Installs
# - poetry in /opt/poetry
# - adds a user called 'zen'
# Size
# - 300MB
################################################################################

# FROM nvidia/opengl:1.2-glvnd-devel-ubuntu20.04 as glvnd

ARG PYTHON_VERSION=3.8.15
ARG DEBIAN_VERSION=bullseye

FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION}

ARG NAME=poetry-zen
ARG POETRY_VERSION=1.3.2
ENV POETRY_HOME=/opt/poetry
ENV PATH="${POETRY_HOME}/bin:${PATH}"

################################################################################
# Poetry
################################################################################

RUN apt-get update && apt-get install -y --no-install-recommends \
# For poetry
curl \
# For pytrees
graphviz \
make \
# For the qt5 viewer
libasound2 \
libdbus-1-dev \
libgl1 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libxi6 \
libxkbcommon0 \
libxkbcommon-x11-0 \
libxrandr2 \
libxtst6 \
# For convenience
bash \
bash-completion \
ca-certificates \
git \
less \
ssh \
vim \
wget \
&& \
rm -rf /var/lib/apt/lists/* && \
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${POETRY_VERSION} python3 - && \
poetry config virtualenvs.create false && \
poetry completions bash >> ~/.bash_completion

################################################################################
# NVIDIA
################################################################################

# COPY --from=glvnd /usr/share/glvnd/egl_vendor.d/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
# ENV NVIDIA_VISIBLE_DEVICES ${NVIDIA_VISIBLE_DEVICES:-all}
# ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics

################################################################################
# Login Shells for Debugging & Development
################################################################################

# In a login shell (below), the PATH env doesn't survive, configure it at ground zero
RUN echo "export PATH=${POETRY_HOME}/bin:${PATH}" >> /etc/profile
ENV TERM xterm-256color
ENTRYPOINT ["/bin/bash", "--login", "-i"]

################################################################################
# Development with a user, e.g. for vscode devcontainers
################################################################################

ARG USERNAME=zen
ARG USER_UID=1000
ARG USER_GID=${USER_UID}

RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID -s "/bin/bash" -m $USERNAME && \
apt-get install -y sudo && \
echo "${USERNAME} ALL=NOPASSWD: ALL" > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME}
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 && \
echo "alias ll='ls --color=auto -alFNh'" >> /home/${USERNAME}/.bashrc && \
echo "alias ls='ls --color=auto -Nh'" >> /home/${USERNAME}/.bashrc && \
poetry completions bash >> /home/${USERNAME}/.bash_completion

# touch /home/${USERNAME}/.bash_completion && chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.bash_completion

################################################################################
# Debugging with root
################################################################################

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 && \
echo "alias ll='ls --color=auto -alFNh'" >> ${HOME}/.bashrc && \
echo "alias ls='ls --color=auto -Nh'" >> ${HOME}/.bashrc
36 changes: 36 additions & 0 deletions .devcontainer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
TAG=original
REPO=devel

help:
@echo "Usage:"
@echo ""
@echo " image : build an image"
@echo " container : create a container that persists"
@echo " start : execute from the container"
@echo " clean : clean up container"
@echo " pristine : clean image and container"
@echo ""
@echo "Be Froody."

image:
docker build \
--build-arg POETRY_VERSION=1.3.2 \
--build-arg PYTHON_VERSION=3.8.16 \
--build-arg DEBIAN_VERSION=bullseye \
--build-arg NAME=${TAG} \
-t ${REPO}:${TAG} .

container:
docker container create --tty --network host -i --gpus all -v /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY --name=${TAG} ${REPO}:${TAG}

run: clean
docker run -it --mount type=bind,source=/mnt/mervin/workspaces/foo,target=/mnt/foo --name=${TAG} --network host --gpus all --volume /tmp/.X11-unix:/tmp/.X11-unix:ro --env DISPLAY --env NVIDIA_VISIBLE_DEVICES=all --env NVIDIA_DRIVER_CAPABILITIES=graphics,display,video,utility,compute --user zen ${REPO}:${TAG} -i

start:
docker container start -i ${TAG}

clean:
-docker container rm ${TAG}

pristine: clean
docker image rm ${REPO}:${TAG}
20 changes: 20 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Development Environment

These VSCode devcontainers setup multiple environments for testing against
different python versins.

## Setup

```
$ git clone git@github.com:splintered-reality/py_trees.git
$ code ./py_trees
```

## VSCode DevContainer

At this point you can either "Re-open project in container" to develop against
the default python version.

Alternatively "Open Folder in Container" and point it at one of the
`py<MAJOR><MINOR>` subfolders in this directory to develop against a different
python version.
53 changes: 53 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "py_trees-js-38",

"build": {
"dockerfile": "./Dockerfile",
"args": {
"NAME": "py_trees_js",
"POETRY_VERSION": "1.3.2",
"PYTHON_VERSION": "3.8.16",
"DEBIAN_VERSION": "bullseye"
},
"context": ".."
},
"containerEnv": {
"POETRY_HTTP_BASIC_PYPI_USERNAME": "${localEnv:POETRY_HTTP_BASIC_PYPI_USERNAME}",
"POETRY_HTTP_BASIC_PYPI_PASSWORD": "${localEnv:POETRY_HTTP_BASIC_PYPI_PASSWORD}",
"QT_DEBUG_PLUGINS": "1"
},
"remoteUser": "zen",
"customizations": {
"vscode": {
"extensions": [
"bierner.github-markdown-preview",
"bierner.markdown-preview-github-styles",
"bungcip.better-toml",
"streetsidesoftware.code-spell-checker",
"ms-python.python",
"omnilib.ufmt",
"tht13.rst-vscode"
]
}
},
"postCreateCommand": "poetry install --all-extras",
"mounts": [
{
"source": "/tmp/.X11-unix",
"target": "/tmp/.X11-unix:ro",
"type": "bind"
}
],
"runArgs": [
"--runtime=nvidia",
"--gpus",
"all",
"--env",
"DISPLAY",
"--network",
"host"
]
// Breaks codespaces
// "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind",
// "workspaceFolder": "/workspaces"
}
16 changes: 16 additions & 0 deletions .devcontainer/opengl_experiments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## XAuth

Read some articles that were using XAuth to help remotely forward across ssh connections
with different `DISPLAY` values.

What hasn't worked:

* Install `xauth` in the `Dockerfile` / mount `.Xauthority` in the `devcontainer.json`:

```
{
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.Xauthority",
"target": "/home/zen/.Xauthority",
"type": "bind"
},
```
Loading