Skip to content

Commit

Permalink
Dev Container Using MCR
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonykim1 committed Jul 21, 2023
1 parent abcb5ce commit 0dd4db6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
32 changes: 12 additions & 20 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
# This image will serve as a starting point for devcontainer.json.
# Get latest image of Fedora as the base image.
FROM docker.io/library/fedora:latest
FROM mcr.microsoft.com/devcontainers/typescript-node:16-bookworm

# Install supported python versions and nodejs.
RUN dnf -y --nodocs install /usr/bin/{python3.7,python3.8,python3.9,python3.10,python3.11,git,conda,clang} && \
dnf clean all
RUN apt-get install -y wget bzip2

ENV NVM_VERSION=0.39.3
ENV NODE_VERSION=16.17.1
ENV NPM_VERSION=8.19.3

# Installation instructions from https://github.com/nvm-sh/nvm .
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash
RUN export NVM_DIR="$HOME/.nvm" && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" && \
nvm install $NODE_VERSION && \
npm install -g npm@$NPM_VERSION

# For clean open source builds.
ENV DISABLE_TRANSLATIONS=true
# Run in silent mode and save downloaded script as anaconda.sh.
# Run with /bin/bash and run in silent mode to /opt/conda.
# Also get rid of installation script after finishing.
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2023.07-1-Linux-x86_64.sh -O ~/anaconda.sh && \
/bin/bash ~/anaconda.sh -b -p /opt/conda && \
rm ~/anaconda.sh

ENV PATH="/opt/conda/bin:$PATH"

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


5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
},
// Commands to execute on container creation,start.
"postCreateCommand": "bash scripts/postCreateCommand.sh",
// Environment variable placed inside containerEnv following: https://containers.dev/implementors/json_reference/#general-properties
"onCreateCommand": "bash scripts/onCreateCommand.sh",

"containerEnv": {
"CI_PYTHON_PATH": "/workspaces/vscode-python/.venv/bin/python"
"CI_PYTHON_PATH": "python"
}

}
36 changes: 36 additions & 0 deletions scripts/onCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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
# echo 'eval "$(pyenv init -)"' >> ~/.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 Python via pyenv .
pyenv install 3.7:latest 3.8:latest 3.9:latest 3.10:latest 3.11:latest

# Set default Python version to 3.7 .
pyenv global 3.7.17

npm ci

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

# Activate Virtual environment.
source /workspaces/vscode-python/.venv/bin/activate

# Install required Python libraries.
npx gulp installPythonLibs

/workspaces/vscode-python/.venv/bin/python -m pip install -r build/test-requirements.txt
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/smoke-test-requirements.txt
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/functional-test-requirements.txt

# Below will crash codespace
# npm run compile
14 changes: 0 additions & 14 deletions scripts/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
#!/bin/bash
npm ci
# Create Virutal environment.
python3.7 -m venv /workspaces/vscode-python/.venv

# Activate Virtual environment.
source /workspaces/vscode-python/.venv/bin/activate

# Install required Python libraries.
npx gulp installPythonLibs

# Install testing requirement using python in .venv .
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/test-requirements.txt
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/smoke-test-requirements.txt
/workspaces/vscode-python/.venv/bin/python -m pip install -r build/functional-test-requirements.txt

0 comments on commit 0dd4db6

Please sign in to comment.