Skip to content

Commit 039ffcd

Browse files
authored
Update template, add features and image metadata info (#21)
1 parent 1ba423a commit 039ffcd

File tree

4 files changed

+98
-26
lines changed

4 files changed

+98
-26
lines changed

.devcontainer/Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp/.devcontainer/base.Dockerfile
2-
# [Choice] Debian / Ubuntu version (use Debian 11/9, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
3-
ARG VARIANT=debian-11
4-
FROM mcr.microsoft.com/devcontainers/cpp:0-${VARIANT}
1+
FROM mcr.microsoft.com/devcontainers/cpp:0-debian-11
2+
3+
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"
4+
5+
# Optionally install the cmake for vcpkg
6+
COPY ./reinstall-cmake.sh /tmp/
7+
8+
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
9+
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
10+
fi \
11+
&& rm -f /tmp/reinstall-cmake.sh
12+
13+
# [Optional] Uncomment this section to install additional vcpkg ports.
14+
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"
515

616
# [Optional] Uncomment this section to install additional packages.
717
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \

.devcontainer/devcontainer.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
33
{
44
"name": "C++",
55
"build": {
6-
"dockerfile": "Dockerfile",
7-
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
8-
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
9-
"args": { "VARIANT": "debian-11" }
6+
"dockerfile": "Dockerfile"
107
},
11-
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
12-
8+
9+
// Features to add to the dev container. More info: https://containers.dev/features.
10+
// "features": {},
11+
1312
// Configure tool-specific properties.
1413
"customizations": {
1514
// Configure properties specific to VS Code.
1615
"vscode": {
17-
// Set *default* container specific settings.json values on container create.
1816
"settings": {},
19-
20-
// Add the IDs of extensions you want installed when the container is created.
2117
"extensions": [
22-
"ms-vscode.cpptools"
18+
"streetsidesoftware.code-spell-checker"
2319
]
2420
}
25-
},
21+
}
2622

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

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

33-
// Comment out this line to run as root instead.
34-
"remoteUser": "vscode"
35-
29+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
30+
// "remoteUser": "root"
3631
}

.devcontainer/reinstall-cmake.sh

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

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-cpp)
44

5-
A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Dev Containers](https://aka.ms/vscode-remote/containers)**.
5+
A **development container** is a running container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Dev Containers](https://aka.ms/vscode-remote/containers)**.
66

77
This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too.
88

@@ -12,8 +12,9 @@ This is a sample project that lets you try out either option in a few easy steps
1212

1313
### GitHub Codespaces
1414
Follow these steps to open this sample in a Codespace:
15-
1. Click the Code drop-down menu and select the **Open with Codespaces** option.
16-
1. Select **+ New codespace** at the bottom on the pane.
15+
1. Click the **Code** drop-down menu.
16+
2. Click on the **Codespaces** tab.
17+
3. Click **Create codespace on main** .
1718

1819
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
1920

@@ -41,21 +42,29 @@ Follow these steps to open this sample in a container using the VS Code Dev Cont
4142

4243
Once you have this sample opened, you'll be able to work with it like you would locally.
4344

44-
> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root.
45-
4645
Some things to try:
4746

4847
1. **Edit:**
4948
- Open `main.cpp`
5049
- Try adding some code and check out the language features.
51-
- Notice that the C++ extension is already installed in the container since the `.devcontainer/devcontainer.json` lists `"ms-vscode.cpptools"` as an extension to install automatically when the container is created.
50+
- Make a spelling mistake and notice it is detected. The [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) extension was automatically installed because it is referenced in `.devcontainer/devcontainer.json`.
51+
- Also notice that utilities like `Vcpkg` and the [C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension are installed. Tools are installed in the `mcr.microsoft.com/devcontainers/cpp` image and Dev Container settings and metadata are automatically picked up from [image labels](https://containers.dev/implementors/reference/#labels).
52+
5253
1. **Terminal:** Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> and type `uname` and other Linux commands from the terminal window.
54+
5355
1. **Build, Run, and Debug:**
5456
- Open `main.cpp`
5557
- Add a breakpoint (e.g. on line 7).
5658
- Press <kbd>F5</kbd> to launch the app in the container.
5759
- Once the breakpoint is hit, try hovering over variables, examining locals, and more.
5860

61+
1. **Install the GitHub CLI using a Dev Container Feature:**
62+
- Press <kbd>F1</kbd> and select the **Dev Containers: Configure Container Features...** or **Codespaces: Configure Container Features...** command.
63+
- Type "github" in the text box at the top.
64+
- Check check box next to "GitHub CLI" (published by devcontainers)
65+
- Click OK
66+
- Press <kbd>F1</kbd> and select the **Dev Containers: Rebuild Container** or **Codespaces: Rebuild Container** command so the modifications are picked up.
67+
5968
## Contributing
6069

6170
This project welcomes contributions and suggestions. Most contributions require you to agree to a

0 commit comments

Comments
 (0)