Skip to content

Commit

Permalink
Add VSC dev container config files (#425)
Browse files Browse the repository at this point in the history
* Add devcontainer and update dockerfiles

* Update documentation

* Update VSC settings
  • Loading branch information
mlund authored Feb 27, 2023
1 parent 8915462 commit 3e2d67a
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/devcontainers/cpp:0-ubuntu-22.04

ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.25.2"

# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/

RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
fi \
&& rm -f /tmp/reinstall-cmake.sh

# [Optional] Uncomment this section to install additional vcpkg ports.
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/rocker-org/devcontainer-features/miniforge:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
58 changes: 58 additions & 0 deletions .devcontainer/reinstall-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
set -e

CMAKE_VERSION=${1:-"none"}

if [ "${CMAKE_VERSION}" = "none" ]; then
echo "No CMake version specified, skipping CMake reinstallation"
exit 0
fi

# Cleanup temporary directory and associated files when exiting the script.
cleanup() {
EXIT_CODE=$?
set +e
if [[ -n "${TMP_DIR}" ]]; then
echo "Executing cleanup of tmp files"
rm -Rf "${TMP_DIR}"
fi
exit $EXIT_CODE
}
trap cleanup EXIT


echo "Installing CMake..."
apt-get -y purge --auto-remove cmake
mkdir -p /opt/cmake

architecture=$(dpkg --print-architecture)
case "${architecture}" in
arm64)
ARCH=aarch64 ;;
amd64)
ARCH=x86_64 ;;
*)
echo "Unsupported architecture ${architecture}."
exit 1
;;
esac

CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)

echo "${TMP_DIR}"
cd "${TMP_DIR}"

curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O

sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license

ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cmake.configureOnOpen": false,
"cmake.preferredGenerators": [ "Unix Makefiles" ]
}
17 changes: 14 additions & 3 deletions docs/_docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ alias faunus='docker exec --interactive -u 1000 faunuslab faunus'
faunus < input.json # piping input to docker
~~~

For development using VSC, we also provide a `devcontainer` configuration for setting
up a Linux development environment, see description below.


## Build from source code

Expand Down Expand Up @@ -166,10 +169,18 @@ where `{tbb-root}` is the installation directory of TBB, _e.g._

# Development

The development of Faunus is done mainly in Jetbrain's [CLion](https://www.jetbrains.com/clion)
(free academic license) but any other IDE or merely a text editor can be used.
We recommend to use tools that respect the provided `.clang-format` which will ease merging
We recommend to use an IDE or text editor that respect the provided `.clang-format` which will ease merging
changes into the codebase, see below.
For Visual Studio Code (VSC) users, it is very easy to setup a development environment using Docker and
[Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers):

~~~ bash
cd faunus
code .
~~~

(when asked, select "open in devcontainer", assuming you have Docker running)


## Code Style

Expand Down
15 changes: 7 additions & 8 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# - clone of mlund/chemistry-notebooks
#
ARG OWNER=jupyter
ARG BASE_CONTAINER=jupyter/scipy-notebook:lab-3.3.2
ARG BASE_CONTAINER=jupyter/scipy-notebook:lab-3.6.1
FROM $BASE_CONTAINER

LABEL maintainer="the faun"
Expand All @@ -26,19 +26,18 @@ RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
software-properties-common

RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update --yes && \
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
cmake \
gcc-11 \
g++-11 \
gcc \
g++ \
libopenmpi-dev openmpi-bin openmpi-common \
zlib1g-dev && \
apt autoremove --yes && \
apt-get clean && rm -rf /var/lib/apt/lists/*

USER ${NB_UID}
RUN mamba install --quiet --yes \
'cmake' \
'jsonschema' \
'jinja2' \
'pypandoc' \
Expand All @@ -54,8 +53,8 @@ RUN git clone https://github.com/mlund/chemistry-notebooks.git

USER root
RUN git clone https://github.com/mlund/faunus.git && \
export CXX=g++-11 && \
export CC=gcc-11 && \
export CXX=g++ && \
export CC=gcc && \
cd faunus && \
cmake -DENABLE_PYTHON=on -DENABLE_OPENMP=on -DENABLE_MPI=on -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPYBIND11_FINDPYTHON=on . && \
make faunus && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ channels:
dependencies:
- clangdev
- libcxx
- cmake>=3.16
- cmake>=3.25
- python=3
- pandoc=2
- pypandoc=1
Expand Down

0 comments on commit 3e2d67a

Please sign in to comment.