Skip to content

Commit 005555f

Browse files
authored
Add .devcontainer (#243)
1 parent a5c7a6a commit 005555f

File tree

3 files changed

+186
-0
lines changed

3 files changed

+186
-0
lines changed

.devcontainer/Dockerfile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
ARG BASE_IMAGE=git-515d637-jammy
2+
FROM ghcr.io/mamba-org/micromamba-devcontainer:$BASE_IMAGE
3+
4+
# Ensure that all users have read-write access to all files created in the subsequent commands.
5+
ARG DOCKERFILE_UMASK=0000
6+
7+
# Install the fix-permissions script
8+
ADD --chmod=755 https://raw.githubusercontent.com/jupyter/docker-stacks/d8c60bc42cad227c5a35214a43a29c157c0a345e/images/docker-stacks-foundation/fix-permissions /usr/local/bin/fix-permissions
9+
10+
# Create a fixed group for /opt/conda in case the user GID changes
11+
RUN sudo groupadd --gid 46328 mamba-admin && sudo usermod -aG mamba-admin "${MAMBA_USER}"
12+
13+
# Install the Conda packages.
14+
ARG ENVIRONMENT_YAML=environment.yml
15+
COPY --chown=$MAMBA_USER:$MAMBA_USER ${ENVIRONMENT_YAML} /tmp/environment.yml
16+
RUN echo "use_lockfiles: false" >> ~/.mambarc && \
17+
micromamba config append channels conda-forge && \
18+
micromamba install --yes --name base --file /tmp/environment.yml && \
19+
micromamba clean --all --force-pkgs-dirs --yes && \
20+
sudo -E "NB_GID=mamba-admin" fix-permissions "${MAMBA_ROOT_PREFIX}"
21+
22+
ARG MAMBA_DOCKERFILE_ACTIVATE=1
23+
24+
# Create and set the workspace folder
25+
ARG CONTAINER_WORKSPACE_FOLDER=/workspaces/default-workspace-folder
26+
RUN mkdir -p "${CONTAINER_WORKSPACE_FOLDER}"
27+
WORKDIR "${CONTAINER_WORKSPACE_FOLDER}"
28+
29+
# On WSL the repo is mounted with permissions 1000:1000, but the mambauser inside the container has a different UID.
30+
# So we change the UID of the mambauser inside the container to match the UID of the user on the host.
31+
USER root
32+
ARG USER_UID=1000
33+
ARG USER_GID=$USER_UID
34+
RUN groupmod --gid $USER_GID $MAMBA_USER \
35+
&& usermod --uid $USER_UID --gid $USER_GID $MAMBA_USER \
36+
&& chown -R $USER_UID:$USER_GID /home/$MAMBA_USER
37+
38+
# Install SLURM and Munge
39+
RUN apt-get update && apt-get install -y \
40+
slurm-wlm \
41+
munge \
42+
&& apt-get clean \
43+
&& rm -rf /var/lib/apt/lists/*
44+
45+
# Set up SLURM configuration
46+
COPY .devcontainer/slurm.conf /etc/slurm/slurm.conf
47+
RUN chmod 644 /etc/slurm/slurm.conf && \
48+
mkdir -p /var/spool/slurmd && \
49+
mkdir -p /var/run/slurm && \
50+
mkdir -p /var/log/slurm && \
51+
mkdir -p /var/lock/slurm && \
52+
mkdir -p /var/spool/slurm && \
53+
chown -R slurm:slurm /var/spool/slurmd /var/run/slurm /var/log/slurm /var/lock/slurm /var/spool/slurm
54+
55+
# Create a startup script to ensure SLURM services are running
56+
RUN echo '#!/bin/bash' > /usr/local/bin/startup.sh && \
57+
echo 'service munge start' >> /usr/local/bin/startup.sh && \
58+
echo 'service slurmd start' >> /usr/local/bin/startup.sh && \
59+
echo 'service slurmctld start' >> /usr/local/bin/startup.sh && \
60+
echo 'exec "$@"' >> /usr/local/bin/startup.sh && \
61+
chmod +x /usr/local/bin/startup.sh
62+
63+
USER root
64+
65+
CMD ["/bin/bash"]

.devcontainer/devcontainer.json

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "micromamba",
3+
"runArgs": [
4+
"--hostname",
5+
"devcontainer",
6+
"--name",
7+
"${localEnv:USER}_devcontainer_micromamba",
8+
"--privileged" // Add this to allow SLURM to manage processes
9+
],
10+
"containerEnv": {
11+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
12+
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}"
13+
},
14+
"build": {
15+
"dockerfile": "Dockerfile",
16+
"context": "..",
17+
"args": {
18+
"CONTAINER_WORKSPACE_FOLDER": "${containerWorkspaceFolder}",
19+
"BASE_IMAGE": "git-515d637-jammy",
20+
"ENVIRONMENT_YAML": "environment.yml"
21+
}
22+
},
23+
"overrideCommand": true, // allow the entrypoint to run
24+
"mounts": [
25+
"source=pre-commit-cache-${localEnv:USER},target=/home/mambauser/.cache/pre-commit,type=volume",
26+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind,consistency=cached",
27+
"source=${localWorkspaceFolder}/.devcontainer/slurm.conf,target=/etc/slurm-llnl/slurm.conf,type=bind"
28+
],
29+
"remoteUser": "mambauser",
30+
"customizations": {
31+
"vscode": {
32+
"extensions": [
33+
"ms-python.python",
34+
"ms-python.mypy-type-checker",
35+
"charliermarsh.ruff",
36+
"ms-toolsai.jupyter",
37+
"ms-azuretools.vscode-docker",
38+
"donjayamanne.githistory",
39+
"eamodio.gitlens",
40+
"mutantdino.resourcemonitor",
41+
"github.copilot",
42+
"davidanson.vscode-markdownlint"
43+
],
44+
"settings": {
45+
// Files to completely exclude from view
46+
// (see also search.exclude and files.watcherExclude)
47+
"files.exclude": {
48+
// Ignore cached files
49+
"**/__pycache__": true,
50+
// Ignore files created for development installs
51+
"**/*.egg-info": true,
52+
// Ignore Jupyter checkpoint files
53+
"**/.ipynb_checkpoints": true,
54+
// Ignore cache directory, except for files which start with . (e.g. .gitignore)
55+
".devcontainer/cache/*/[!\\.]*": true
56+
},
57+
"[python]": {
58+
"editor.defaultFormatter": "charliermarsh.ruff"
59+
},
60+
"ruff.path": [
61+
"/opt/conda/bin/ruff"
62+
],
63+
"ruff.interpreter": [
64+
"/opt/conda/bin/python"
65+
],
66+
// Ruler for "black"-formatted line widths
67+
"editor.rulers": [
68+
88
69+
],
70+
// Disable barely usable scrollbar
71+
"workbench.editor.wrapTabs": true,
72+
// Turn on autosave
73+
"files.autoSave": "afterDelay",
74+
// Show whitespace as tiny grey dots
75+
"editor.renderWhitespace": "boundary",
76+
// Use Pylance
77+
"python.languageServer": "Pylance",
78+
"python.analysis.typeCheckingMode": "basic",
79+
// Interpret lines beginning with "# !%" as ipython magic commands
80+
"jupyter.interactiveWindow.textEditor.magicCommandsAsComments": true,
81+
// Path of the default Python environment
82+
"python.defaultInterpreterPath": "/opt/conda/bin/python",
83+
// Disable the "conda activate base" command when opening a new terminal
84+
"python.terminal.activateEnvironment": false,
85+
// Automatically keep Git up-to-date with remotes
86+
"git.autofetch": "all",
87+
// Make sure that key combos like Ctrl+K are not intercepted by VS Code
88+
// when using the terminal
89+
"terminal.integrated.allowChords": false,
90+
"extensions.verifySignature": false
91+
}
92+
}
93+
},
94+
"postCreateCommand": "sudo /usr/local/bin/startup.sh && sudo scontrol show config && sudo scontrol show nodes && sudo scontrol show partitions",
95+
"postStartCommand": "pip install -e ."
96+
}

.devcontainer/slurm.conf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ClusterName=devcluster
2+
SlurmctldHost=localhost
3+
MpiDefault=none
4+
ProctrackType=proctrack/linuxproc
5+
ReturnToService=1
6+
SlurmctldPidFile=/var/run/slurmctld.pid
7+
SlurmdPidFile=/var/run/slurmd.pid
8+
SlurmdSpoolDir=/var/spool/slurmd
9+
SlurmUser=slurm
10+
StateSaveLocation=/var/spool/slurm
11+
SwitchType=switch/none
12+
TaskPlugin=task/affinity
13+
InactiveLimit=0
14+
KillWait=30
15+
MinJobAge=300
16+
SlurmctldTimeout=120
17+
SlurmdTimeout=300
18+
Waittime=0
19+
SchedulerType=sched/backfill
20+
SelectType=select/cons_res
21+
SelectTypeParameters=CR_Core
22+
23+
# COMPUTE NODES
24+
NodeName=localhost NodeAddr=127.0.0.1 CPUs=1 State=UNKNOWN
25+
PartitionName=debug Nodes=localhost Default=YES MaxTime=INFINITE State=UP

0 commit comments

Comments
 (0)