Skip to content

Commit 6af959d

Browse files
authored
Dev Container Using MCR (#21675)
Dev container rewrite using MCR. Pyenv for installing and managing python versions. Fish also installed as optional (able to view as shell option in codespaces). Also fixing conda error. Takes care of: #21591 rewrite from: #21435 to adhere to company policy.
1 parent 73a0e9d commit 6af959d

File tree

7 files changed

+58
-43
lines changed

7 files changed

+58
-43
lines changed

.devcontainer/Dockerfile

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
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
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:16-bookworm
42

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
3+
RUN apt-get install -y wget bzip2
84

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
5+
# Run in silent mode and save downloaded script as anaconda.sh.
6+
# Run with /bin/bash and run in silent mode to /opt/conda.
7+
# Also get rid of installation script after finishing.
8+
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2023.07-1-Linux-x86_64.sh -O ~/anaconda.sh && \
9+
/bin/bash ~/anaconda.sh -b -p /opt/conda && \
10+
rm ~/anaconda.sh
2311

12+
ENV PATH="/opt/conda/bin:$PATH"
2413

14+
# Sudo apt update needs to run in order for installation of fish to work .
15+
RUN sudo apt update && \
16+
sudo apt install fish -y
2517

2618

.devcontainer/devcontainer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
},
2222
// Commands to execute on container creation,start.
2323
"postCreateCommand": "bash scripts/postCreateCommand.sh",
24-
// Environment variable placed inside containerEnv following: https://containers.dev/implementors/json_reference/#general-properties
24+
"onCreateCommand": "bash scripts/onCreateCommand.sh",
25+
2526
"containerEnv": {
2627
"CI_PYTHON_PATH": "/workspaces/vscode-python/.venv/bin/python"
2728
}

scripts/onCreateCommand.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
# echo 'eval "$(pyenv init -)"' >> ~/.bashrc
8+
9+
export PYENV_ROOT="$HOME/.pyenv"
10+
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
11+
# eval "$(pyenv init -)" Comment this out and DO NOT use shim.
12+
source ~/.bashrc
13+
14+
# Install Python via pyenv .
15+
pyenv install 3.7:latest 3.8:latest 3.9:latest 3.10:latest 3.11:latest
16+
17+
# Set default Python version to 3.7 .
18+
pyenv global 3.7.17
19+
20+
npm ci
21+
22+
# Create Virutal environment.
23+
pyenv exec python3.7 -m venv .venv
24+
25+
# Activate Virtual environment.
26+
source /workspaces/vscode-python/.venv/bin/activate
27+
28+
# Install required Python libraries.
29+
npx gulp installPythonLibs
30+
31+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/test-requirements.txt
32+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/smoke-test-requirements.txt
33+
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/functional-test-requirements.txt
34+
35+
# Below will crash codespace
36+
# npm run compile

scripts/postCreateCommand.sh

-15
This file was deleted.

src/client/common/interpreterPathService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const isRemoteGlobalSettingCopiedKey = 'isRemoteGlobalSettingCopiedKey';
3030
export const defaultInterpreterPathSetting: keyof IPythonSettings = 'defaultInterpreterPath';
3131
const CI_PYTHON_PATH = getCIPythonPath();
3232

33-
function getCIPythonPath(): string {
33+
export function getCIPythonPath(): string {
3434
if (process.env.CI_PYTHON_PATH && fs.existsSync(process.env.CI_PYTHON_PATH)) {
3535
return process.env.CI_PYTHON_PATH;
3636
}

src/test/common/interpreterPathService.unit.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
WorkspaceConfiguration,
1616
} from 'vscode';
1717
import { IApplicationEnvironment, IWorkspaceService } from '../../client/common/application/types';
18-
import { defaultInterpreterPathSetting, InterpreterPathService } from '../../client/common/interpreterPathService';
18+
import {
19+
defaultInterpreterPathSetting,
20+
getCIPythonPath,
21+
InterpreterPathService,
22+
} from '../../client/common/interpreterPathService';
1923
import { FileSystemPaths } from '../../client/common/platform/fs-paths';
2024
import { InterpreterConfigurationScope, IPersistentState, IPersistentStateFactory } from '../../client/common/types';
2125
import { createDeferred, sleep } from '../../client/common/utils/async';
@@ -447,7 +451,8 @@ suite('Interpreter Path Service', async () => {
447451
workspaceValue: undefined,
448452
});
449453
const settingValue = interpreterPathService.get(resource);
450-
expect(settingValue).to.equal('python');
454+
455+
expect(settingValue).to.equal(getCIPythonPath());
451456
});
452457

453458
test('If defaultInterpreterPathSetting is changed, an event is fired', async () => {

src/test/pythonEnvironments/common/commonUtils.functional.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ suite('pyenvs common utils - finding Python executables', () => {
8686
<python3.8>
8787
python3 -> sub2/sub2.2/python3
8888
python3.7 -> sub2/sub2.1/sub2.1.1/python
89-
python2.7 -> does-not-exist
9089
`);
9190
}
9291
});
@@ -106,7 +105,6 @@ suite('pyenvs common utils - finding Python executables', () => {
106105
// These will match.
107106
'python',
108107
'python2',
109-
'python2.7',
110108
'python3',
111109
'python3.7',
112110
'python3.8',
@@ -137,7 +135,6 @@ suite('pyenvs common utils - finding Python executables', () => {
137135
// These will match.
138136
'python',
139137
'python2',
140-
'python2.7',
141138
'python3',
142139
'python3.7',
143140
'python3.8',
@@ -167,7 +164,6 @@ suite('pyenvs common utils - finding Python executables', () => {
167164
// These will match.
168165
'python',
169166
'python2',
170-
'python2.7',
171167
'python3',
172168
'python3.7',
173169
'python3.8',

0 commit comments

Comments
 (0)