From 4df23a991f214f22022167f5f0987e6020832496 Mon Sep 17 00:00:00 2001 From: w3lld1 Date: Thu, 9 Jul 2026 18:38:36 +0000 Subject: [PATCH] infra: add VS Code devcontainer --- .devcontainer/Dockerfile | 59 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 21 ++++++++++++ atest/README.rst | 17 ++++++++++ 3 files changed, 97 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..05b1f5634 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,59 @@ +FROM ubuntu:22.04 + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + bash-completion \ + ca-certificates \ + gcc \ + git \ + language-pack-en \ + libffi-dev \ + locales \ + make \ + musl-dev \ + net-tools \ + openssh-client \ + openssh-server \ + python3 \ + python3-pip \ + python3-venv \ + sudo \ + && rm -rf /var/lib/apt/lists/* + +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \ + && locale-gen + +ENV LANG=en_US.UTF-8 \ + LANGUAGE=en_US:en \ + LC_ALL=en_US.UTF-8 + +RUN python3 -m venv /opt/venv +ENV PATH="/opt/venv/bin:${PATH}" + +RUN mkdir -p /run/sshd \ + && useradd --create-home --shell /bin/bash test-nopasswd \ + && passwd --delete test-nopasswd \ + && echo "PermitEmptyPasswords yes" >> /etc/ssh/sshd_config \ + && useradd --create-home --shell /bin/bash test \ + && (echo 'test'; echo 'test') | passwd test \ + && adduser test sudo \ + && echo 'test ALL=(ALL:ALL) PASSWD:ALL' > /etc/sudoers.d/passworded \ + && chmod 0440 /etc/sudoers.d/passworded \ + && useradd --create-home --shell /bin/bash testkey \ + && echo "export PS1='\\u@\\h \\W \\$ '" >> /home/test/.bashrc \ + && echo "export PS1='\\u@\\h \\W \\$ '" >> /home/testkey/.bashrc \ + && sudo -u testkey mkdir -p /home/testkey/.ssh \ + && sudo -u testkey ssh-keygen -f /home/testkey/.ssh/id_rsa -t rsa -N '' \ + && sudo -u testkey cp /home/testkey/.ssh/id_rsa.pub /home/testkey/.ssh/authorized_keys \ + && chmod 700 /home/testkey/.ssh \ + && chmod 600 /home/testkey/.ssh/authorized_keys \ + && chmod 644 /home/testkey/.ssh/id_rsa \ + && echo 'Testing pre-login banner' > /etc/ssh/sshd-banner \ + && echo 'Banner /etc/ssh/sshd-banner' >> /etc/ssh/sshd_config \ + && echo 'Subsystem subsys echo "Subsystem invoked."' >> /etc/ssh/sshd_config \ + && mkdir -p /root/.ssh \ + && printf 'Host test_hostname\n Hostname localhost\n' >> /root/.ssh/config + +CMD ["sleep", "infinity"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..f4fda6518 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "SSHLibrary development", + "build": { + "dockerfile": "Dockerfile" + }, + "workspaceFolder": "/SSHLibrary", + "workspaceMount": "source=${localWorkspaceFolder},target=/SSHLibrary,type=bind,consistency=cached", + "postCreateCommand": "python -m pip install --upgrade pip && python -m pip install -e . -r requirements-dev.txt && cp /home/testkey/.ssh/id_rsa atest/testdata/keyfiles/id_rsa", + "postStartCommand": "service ssh start", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "robocorp.robotframework-lsp" + ], + "settings": { + "python.defaultInterpreterPath": "/opt/venv/bin/python" + } + } + } +} diff --git a/atest/README.rst b/atest/README.rst index fdef5b6ff..d74eecd66 100644 --- a/atest/README.rst +++ b/atest/README.rst @@ -155,6 +155,23 @@ Additional OpenSSH configuration echo $'Host test_proxy_hostname\n Hostname localhost\n User test\n Port 22\n ProxyCommand ssh -W %h:%p testkey_hostname\n' >> ~/.ssh/config +Setup for VS Code Dev Containers +================================ + +The repository includes a Dev Container configuration for contributors who want +an out-of-box Linux development environment in VS Code. Open the repository in +VS Code and run ``Dev Containers: Reopen in Container``. The container installs +SSHLibrary in editable mode, starts an OpenSSH server when the container starts, +and prepares the ``test``, ``test-nopasswd``, and ``testkey`` accounts used by +the acceptance tests. + +After the container has started, acceptance tests can be run from the repository +root with: + +:: + + python3 atest/run.py . + Setup for Docker ================ First go into the ``docker`` folder and build a SSHLibrary image that will be based on your repository: