Skip to content

Commit cc1f95c

Browse files
authored
Merge pull request #12 from mjyc/devcontainer
Support devcontainer & codespace
2 parents 0950153 + 6bb4f91 commit cc1f95c

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

‎.devcontainer/Dockerfile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM mcr.microsoft.com/devcontainers/cpp:1.0.0-debian-11
2+
3+
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"
4+
COPY ./reinstall-cmake.sh /tmp/
5+
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
6+
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
7+
fi \
8+
&& rm -f /tmp/reinstall-cmake.sh
9+
10+
# Install Eigen 3
11+
RUN apt-get update
12+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends libeigen3-dev
13+
14+
# Install OpenCV 3.3
15+
RUN DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
16+
RUN git clone https://github.com/opencv/opencv.git /tmp/opencv && \
17+
cd /tmp/opencv && \
18+
git checkout 3.3.0 && \
19+
mkdir build && \
20+
cd build && \
21+
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. -D BUILD_opencv_dnn=OFF -D BUILD_opencv_videoio=OFF && \
22+
make -j$(nproc) && \
23+
sudo make install

‎.devcontainer/devcontainer.json‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "CppRobotics",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
"REINSTALL_CMAKE_VERSION_FROM_SOURCE": "3.25.2"
7+
}
8+
},
9+
"features": {
10+
"ghcr.io/devcontainers/features/common-utils:2": {
11+
"username": "vscode",
12+
"userUid": "1000",
13+
"userGid": "1000"
14+
},
15+
// For default password, see https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/desktop-lite.md
16+
"ghcr.io/devcontainers/features/desktop-lite:1": {
17+
"webPort": 6080
18+
}
19+
},
20+
"customizations": {
21+
"vscode": {
22+
"settings": {},
23+
"extensions": [
24+
"streetsidesoftware.code-spell-checker"
25+
]
26+
}
27+
},
28+
"remoteUser": "vscode"
29+
}

‎.devcontainer/reinstall-cmake.sh‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
CMAKE_VERSION=${1:-"none"}
5+
6+
if [ "${CMAKE_VERSION}" = "none" ]; then
7+
echo "No CMake version specified, skipping CMake reinstallation"
8+
exit 0
9+
fi
10+
11+
# Cleanup temporary directory and associated files when exiting the script.
12+
cleanup() {
13+
EXIT_CODE=$?
14+
set +e
15+
if [[ -n "${TMP_DIR}" ]]; then
16+
echo "Executing cleanup of tmp files"
17+
rm -Rf "${TMP_DIR}"
18+
fi
19+
exit $EXIT_CODE
20+
}
21+
trap cleanup EXIT
22+
23+
24+
echo "Installing CMake..."
25+
apt-get -y purge --auto-remove cmake
26+
mkdir -p /opt/cmake
27+
28+
architecture=$(dpkg --print-architecture)
29+
case "${architecture}" in
30+
arm64)
31+
ARCH=aarch64 ;;
32+
amd64)
33+
ARCH=x86_64 ;;
34+
*)
35+
echo "Unsupported architecture ${architecture}."
36+
exit 1
37+
;;
38+
esac
39+
40+
CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh"
41+
CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt"
42+
TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX)
43+
44+
echo "${TMP_DIR}"
45+
cd "${TMP_DIR}"
46+
47+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O
48+
curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O
49+
50+
sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}"
51+
sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license
52+
53+
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake

0 commit comments

Comments
 (0)