Skip to content

Commit

Permalink
Dev Container for lsprotocol (#267)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anthonykim1 authored Sep 7, 2023
1 parent 3bcc474 commit c9a8424
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mcr.microsoft.com/devcontainers/base:bookworm
RUN sudo apt update

# Pyenv installation of Python versions is missing below packages.
RUN sudo apt install libbz2-dev libncurses5-dev libffi-dev libreadline-dev libsqlite3-dev liblzma-dev -y

# Install fish.
RUN sudo apt install fish -y
12 changes: 8 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"name": "LSP Dev Container",
"build": {
"dockerfile": "./Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/devcontainers/features/powershell:1": {
"version": "latest"
},
Expand All @@ -20,5 +23,6 @@
]
}
},
"postCreateCommand": "python -m pip install nox && python -m pip install -r ./packages/python/requirements.txt -r ./requirements.txt"
"onCreateCommand": "bash scripts/onCreateCommand.sh",
"postCreateCommand": "bash scripts/postCreateCommand.sh"
}
28 changes: 28 additions & 0 deletions scripts/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Install pyenv and Python versions here to avoid using shim.
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# eval "$(pyenv init -)" Comment this out and DO NOT use shim.
source ~/.bashrc

# Install Rust and Cargo
curl https://sh.rustup.rs -sSf | bash -s -- -y
echo 'source $HOME/.cargo/env' >> ~/.bashrc

# Install Python via pyenv .
pyenv install 3.8:latest 3.9:latest 3.10:latest 3.11:latest

# Set default Python version to 3.8 .
pyenv global 3.8.18

# Create Virutal environment.
pyenv exec python3.8 -m venv .venv

# Activate Virtual environment.
source /workspaces/lsprotocol/.venv/bin/activate

3 changes: 3 additions & 0 deletions scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source /workspaces/lsprotocol/.venv/bin/activate
python -m pip install nox
python -m pip install -r ./packages/python/requirements.txt -r ./requirements.txt

0 comments on commit c9a8424

Please sign in to comment.