Skip to content

Commit c9a8424

Browse files
authored
Dev Container for lsprotocol (#267)
Dev Container support for lsprotocol repository, referencing #234 and adding more things on the way, such as multiple Python versions, cargo, dotnet, venv, requirements, but in a way similar to how dev container is done in the VS Code Python repo: microsoft/vscode-python#21675 - [x] Add devcontainer.json, onCreateCommand.sh, postCreateCommand.sh appropriately - [x] Add installation and append to PATH for Cargo, Rust, Python(s) - [x] Install requirements from postCreateCommand.sh after activating virtual environment
1 parent 3bcc474 commit c9a8424

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/devcontainers/base:bookworm
2+
RUN sudo apt update
3+
4+
# Pyenv installation of Python versions is missing below packages.
5+
RUN sudo apt install libbz2-dev libncurses5-dev libffi-dev libreadline-dev libsqlite3-dev liblzma-dev -y
6+
7+
# Install fish.
8+
RUN sudo apt install fish -y

.devcontainer/devcontainer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
2-
"name": "Python 3",
3-
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
4-
"features": {
2+
"name": "LSP Dev Container",
3+
"build": {
4+
"dockerfile": "./Dockerfile",
5+
"context": ".."
6+
},
7+
"features": {
58
"ghcr.io/devcontainers/features/powershell:1": {
69
"version": "latest"
710
},
@@ -20,5 +23,6 @@
2023
]
2124
}
2225
},
23-
"postCreateCommand": "python -m pip install nox && python -m pip install -r ./packages/python/requirements.txt -r ./requirements.txt"
26+
"onCreateCommand": "bash scripts/onCreateCommand.sh",
27+
"postCreateCommand": "bash scripts/postCreateCommand.sh"
2428
}

scripts/onCreateCommand.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# Install pyenv and Python versions here to avoid using shim.
4+
curl https://pyenv.run | bash
5+
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
6+
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
7+
8+
export PYENV_ROOT="$HOME/.pyenv"
9+
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
10+
# eval "$(pyenv init -)" Comment this out and DO NOT use shim.
11+
source ~/.bashrc
12+
13+
# Install Rust and Cargo
14+
curl https://sh.rustup.rs -sSf | bash -s -- -y
15+
echo 'source $HOME/.cargo/env' >> ~/.bashrc
16+
17+
# Install Python via pyenv .
18+
pyenv install 3.8:latest 3.9:latest 3.10:latest 3.11:latest
19+
20+
# Set default Python version to 3.8 .
21+
pyenv global 3.8.18
22+
23+
# Create Virutal environment.
24+
pyenv exec python3.8 -m venv .venv
25+
26+
# Activate Virtual environment.
27+
source /workspaces/lsprotocol/.venv/bin/activate
28+

scripts/postCreateCommand.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source /workspaces/lsprotocol/.venv/bin/activate
2+
python -m pip install nox
3+
python -m pip install -r ./packages/python/requirements.txt -r ./requirements.txt

0 commit comments

Comments
 (0)