Skip to content

Commit bd5b622

Browse files
authored
Dev Container for VS Code Python Extension (#21435)
Contains dockerfile, devcontainer.json, post run script needed to create dev container. Base image used is the latest version of Fedora, and the docker file contains installation for: python version(s), node, npm, conda. --------- authored-by: Anthony Kim <[email protected]>
1 parent 304dffa commit bd5b622

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This image will serve as a starting point for devcontainer.json.
2+
# Get latest image of Fedora as the base image.
3+
FROM docker.io/library/fedora:latest
4+
5+
# Install supported python versions and nodejs.
6+
RUN dnf -y --nodocs install /usr/bin/{python3.7,python3.8,python3.9,python3.10,python3.11,git,conda,clang} && \
7+
dnf clean all
8+
9+
ENV NVM_VERSION=0.39.3
10+
ENV NODE_VERSION=16.17.1
11+
ENV NPM_VERSION=8.19.3
12+
13+
# Installation instructions from https://github.com/nvm-sh/nvm .
14+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash
15+
RUN export NVM_DIR="$HOME/.nvm" && \
16+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
17+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
18+
nvm install $NODE_VERSION && \
19+
npm install -g npm@$NPM_VERSION
20+
21+
# For clean open source builds.
22+
ENV DISABLE_TRANSLATIONS=true
23+
24+
25+
26+

.devcontainer/devcontainer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// For format details, see https://aka.ms/devcontainer.json.
2+
{
3+
"name": "VS Code Python Dev Container",
4+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
5+
"build": {
6+
"dockerfile": "./Dockerfile",
7+
"context": ".."
8+
},
9+
"customizations": {
10+
"vscode": {
11+
"extensions": [
12+
"editorconfig.editorconfig",
13+
"esbenp.prettier-vscode",
14+
"dbaeumer.vscode-eslint",
15+
"ms-python.python",
16+
"ms-python.black-formatter",
17+
"ms-python.vscode-pylance",
18+
"charliermarsh.ruff"
19+
]
20+
}
21+
},
22+
// Commands to execute on container creation,start.
23+
"postCreateCommand": "bash scripts/postCreateCommand.sh",
24+
// Environment variable placed inside containerEnv following: https://containers.dev/implementors/json_reference/#general-properties
25+
"containerEnv": {
26+
"CI_PYTHON_PATH": "/workspaces/vscode-python/.venv/bin/python"
27+
}
28+
29+
}

scripts/postCreateCommand.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
npm ci
3+
# Create Virutal environment.
4+
python3.7 -m venv /workspaces/vscode-python/.venv
5+
6+
# Activate Virtual environment.
7+
source /workspaces/vscode-python/.venv/bin/activate
8+
9+
# Install required Python libraries.
10+
npx gulp installPythonLibs
11+
12+
# Install testing requirement using python in .venv .
13+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/test-requirements.txt
14+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/smoke-test-requirements.txt
15+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/functional-test-requirements.txt

0 commit comments

Comments
 (0)