Skip to content

Commit

Permalink
Add working devcontainer and empty jupyter notebook.
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronrutherford committed Nov 9, 2023
1 parent 1e63e8d commit 835651a
Show file tree
Hide file tree
Showing 9 changed files with 2,564 additions and 280 deletions.
39 changes: 35 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN mkdir /opt/spack-environment \
&& echo ' - [email protected]+coinhsl~mumps+metis' \
&& echo ' - [email protected]+blas' \
&& echo ' - py-jupyterlab' \
&& echo ' - py-ipyparallel' \
&& echo ' concretizer:' \
&& echo ' unify: true' \
&& echo ' reuse: true' \
Expand All @@ -28,15 +29,32 @@ RUN mkdir /opt/spack-environment \
&& echo ' - openmpi' \
&& echo ' zlib-api:' \
&& echo ' - zlib' \
&& echo ' zlib-ng:' \
&& echo ' buildable: false' \
&& echo ' config:' \
&& echo ' install_tree: /opt/software' \
&& echo ' view: /opt/views/view') > /opt/spack-environment/spack.yaml

# This is manual, and required to build Ipopt
COPY coinhsl-archive-2019.05.21.tar.gz /opt/spack-environment/coinhsl-archive-2019.05.21.tar.gz

# Find external packages
RUN cd /opt/spack-environment && spack env activate . && spack external find --all

# Do this separate of install to cache keys...
RUN spack mirror add develop https://binaries.spack.io/develop && spack buildcache keys --install --trust
RUN cd /opt/spack-environment && spack env activate . && spack mirror add develop https://binaries.spack.io/develop && spack buildcache keys --install --trust && spack concretize -f && spack mirror create -a

# Install Ipopt w/ CoinHSL (and other deps) in stages to cache builds
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast ipopt

# Install PETSc
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast petsc

# Install py-jupyterlab
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast py-jupyterlab

# Install py-ipyparallel
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast py-ipyparallel

# Install the software, remove unnecessary deps
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast && spack gc -y
Expand Down Expand Up @@ -72,7 +90,7 @@ RUN { \


RUN apt-get -yqq update && apt-get -yqq upgrade \
&& apt-get -yqq install gfortran \
&& apt-get -yqq install gfortran nodejs npm \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]
Expand All @@ -83,6 +101,19 @@ RUN echo "source /entrypoint.sh" >> /home/vscode/.bashrc
# Install the Jupyter kernel
RUN . /entrypoint.sh && \
python3 -m ipykernel install \
--name py311-exago\
--display-name ExaGO \
--name py311-exago \
--display-name "ExaGO" \
--prefix=

# Install the mpi4py Jupyter kernel
RUN . /entrypoint.sh && \
python3 -m ipykernel install \
--name py311-mpi4py-exago \
--display-name "ExaGO w/ MPI" \
--prefix=

# Make modifications that are necessary to run mpi4py in kernelspec
RUN sed -i 's/\"\/opt\/views\/view\/bin\/python3\"/\"mpiexec\", \"-n\", \"1\", \"\/opt\/views\/view\/bin\/python3\"/g' /usr/local/share/jupyter/kernels/py311-mpi4py-exago/kernel.json

# Configure user for container
USER vscode
125 changes: 125 additions & 0 deletions .devcontainer/create_dockerfile_devcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/bash
# Generates Dockerfile for use as Devcontainer...

# Only necessary for HTTPS operations on PNNL VPN
# export HTTPS_PROXY=http://proxy01.pnl.gov:3128 &&
# export https_proxy=http://proxy01.pnl.gov:3128 &&

# Get CoinHSL tarball if not present
if [ ! -f "./coinhsl-archive-2019.05.21.tar.gz" ]; then
echo "No coinhsl-archive-2019.05.21.tar.gz found - make sure to get your own license and copy it to this directory"
echo "Note that the tarball must be named coinhsl-archive-2019.05.21.tar.gz"
exit 1
fi

# Add read/execute permissions to CoinHSL tarball
chmod +rx ./coinhsl-archive-2019.05.21.tar.gz &&

# If "-f" flag passed, force rebuild
if [ "$1" == "-f" ]; then
echo "Forcing rebuild" &&
rm -rf ~/.spack &&
rm -rf ./spack &&
rm -rf ./spack-env
fi

# or no ./spack dir, force a rebuild
if [ ! -d "./tpl/spack/share" ]; then
echo "No spack submodule directory found, downloading spack"
git submodule update --init --recursive
fi

export SPACK_PYTHON=$(which python3) &&
# Setup spack
source ./tpl/spack/share/spack/setup-env.sh &&

# Create heredoc for spack.yaml with environment
cat > $(pwd)/spack.yaml <<EOF
spack:
specs:
- [email protected]+ipopt+python+mpi
- petsc~fortran~hdf5~hypre+metis
- [email protected]+coinhsl~mumps+metis
- [email protected]+blas
- py-jupyterlab
- py-ipyparallel
concretizer:
unify: true
reuse: true
mirrors:
spack: https://binaries.spack.io/develop
container:
format: docker
images:
build: spack/ubuntu-jammy
final: mcr.microsoft.com/devcontainers/python:3.11-bookworm
os_packages:
command: apt
build:
- autoconf
final:
- gfortran
- nodejs
- npm
packages:
all:
providers:
mpi:
- openmpi
zlib-api:
- zlib
zlib-ng:
buildable: false
EOF

# Containerize into a Dockerfile
# Eventually put this straight into ExaGO repo...
spack containerize > ./.devcontainer/Dockerfile

# THIS ONLY WORKS ON MAC!!! - maybe get gsed wit brew working...
# Add Docker command before "# Install" that copies CoinHSL into image
sed -i "" "s|# Install the software|# This is manual, and required to build Ipopt\nCOPY coinhsl-archive-2019.05.21.tar.gz /opt/spack-environment/coinhsl-archive-2019.05.21.tar.gz\n\n# Install the software|" ./.devcontainer/Dockerfile

# Find external packages
sed -i "" "s|# Install the software|# Find external packages\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack external find --all\n\n# Install the software|" ./.devcontainer/Dockerfile

# Also trusts the build cache and create source mirror
sed -i "" "s|# Install the software|# Do this separate of install to cache keys...\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack mirror add develop https://binaries.spack.io/develop \&\& spack buildcache keys --install --trust \&\& spack concretize -f \&\& spack mirror create -a\n\n# Install the software|" ./.devcontainer/Dockerfile

# Install Ipopt and packages in separate stages to cache builds
sed -i "" "s|# Install the software|# Install Ipopt w/ CoinHSL (and other deps) in stages to cache builds\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast ipopt\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install PETSc \nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast petsc\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install py-jupyterlab\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast py-jupyterlab\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install py-ipyparallel\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast py-ipyparallel\n\n# Install the software|" ./.devcontainer/Dockerfile

# Configure environment for VSCode User in devcontainer
echo "# Make sure devcontainer user gets spack packages" >> ./.devcontainer/Dockerfile
echo "RUN echo \"source /entrypoint.sh\" >> /home/vscode/.bashrc" >> ./.devcontainer/Dockerfile

# Finally install the Jupyter kernel
echo "" >> ./.devcontainer/Dockerfile
echo "# Install the Jupyter kernel" >> ./.devcontainer/Dockerfile
echo "RUN . /entrypoint.sh && \\" >> ./.devcontainer/Dockerfile
echo " python3 -m ipykernel install \\" >> ./.devcontainer/Dockerfile
echo " --name py311-exago \\" >> ./.devcontainer/Dockerfile
echo " --display-name \"ExaGO\" \\" >> ./.devcontainer/Dockerfile
echo " --prefix=$(which jupyter)" >> ./.devcontainer/Dockerfile

# Install the mpi4py Jupyter kernel
echo "" >> ./.devcontainer/Dockerfile
echo "# Install the mpi4py Jupyter kernel" >> ./.devcontainer/Dockerfile
echo "RUN . /entrypoint.sh && \\" >> ./.devcontainer/Dockerfile
echo " python3 -m ipykernel install \\" >> ./.devcontainer/Dockerfile
echo " --name py311-mpi4py-exago \\" >> ./.devcontainer/Dockerfile
echo " --display-name \"ExaGO w/ MPI\" \\" >> ./.devcontainer/Dockerfile
echo " --prefix=$(which jupyter)" >> ./.devcontainer/Dockerfile

# Modify mpi4py kernel to actually launch process with mpiexec
echo "" >> ./.devcontainer/Dockerfile
echo "# Make modifications that are necessary to run mpi4py in kernelspec" >> ./.devcontainer/Dockerfile
echo "RUN sed -i 's/\\\"\/opt\/views\/view\/bin\/python3\\\"/\\\"mpiexec\\\", \\\"-n\\\", \\\"1\\\", \\\"\/opt\/views\/view\/bin\/python3\\\"/g' /usr/local/share/jupyter/kernels/py311-mpi4py-exago/kernel.json" >> ./.devcontainer/Dockerfile

# Make sure vscode user is correct
echo "" >> ./.devcontainer/Dockerfile
echo "# Configure user for container" >> ./.devcontainer/Dockerfile
echo "USER vscode" >> ./.devcontainer/Dockerfile
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"ms-toolsai.jupyter",
"GitHub.copilot"
"GitHub.copilot",
"ms-vsliveshare.vsliveshare"
]
}
},
"workspaceFolder": "/home/app/",
"postCreateCommand": "cd /home/app/viz && export CXX=$(which gcc) && npm install",
"workspaceMount": "source=${localWorkspaceFolder},target=/home/app/,type=bind,consistency=cached"
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install/*
.ubuild.json
*__pycache__*
*nvblas.conf
spack-*
spack*
.vscode/
coinhsl-*
node_modules
Expand Down
Loading

0 comments on commit 835651a

Please sign in to comment.