Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 45d6be1

Browse files
authored
Add vcpkg context from base cpp image to the cpp-mariadb container (#1322)
1 parent fd04f3e commit 45d6be1

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

containers/cpp-mariadb/.devcontainer/Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,23 @@ FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
77
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
88
&& apt-get -y install curl
99

10-
COPY ./install-mariadb.sh /
11-
RUN chmod +x /install-mariadb.sh && ./install-mariadb.sh
10+
COPY ./install-mariadb.sh /tmp/
11+
RUN chmod +x /tmp/install-mariadb.sh && /tmp/install-mariadb.sh && rm -f /tmp/install-mariadb.sh
12+
13+
# [Optional] Install CMake version different from what base image has already installed.
14+
# CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/
15+
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none"
16+
17+
# Optionally install the cmake for vcpkg
18+
COPY ./reinstall-cmake.sh /tmp/
19+
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
20+
/tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
21+
fi \
22+
&& rm -f /tmp/reinstall-cmake.sh
23+
24+
# [Optional] Uncomment this section to install additional vcpkg ports.
25+
# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install <your-port-name-here>"
26+
27+
# [Optional] Uncomment this section to install additional packages.
28+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
29+
# && apt-get -y install --no-install-recommends <your-package-list-here>

containers/cpp-mariadb/.devcontainer/install-mariadb.sh

100644100755
File mode changed.
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

containers/cpp-mariadb/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| *Categories* | Core, Languages |
1111
| *Definition type* | Docker Compose |
1212
| *Available image variants* | [See cpp definition](../cpp). |
13-
| *Supported architecture(s)* | x86-64, aarch64/arm64 for `bullseye`, `stretch`, `bionic`, and `hirsute` variants |
13+
| *Supported architecture(s)* | x86-64 for `bullseye`, `stretch`, `bionic`, and `hirsute` variants |
1414
| *Works in Codespaces* | Yes |
1515
| *Container host OS support* | Linux, macOS, Windows |
1616
| *Container OS* | Debian, Ubuntu |
@@ -32,7 +32,29 @@ build:
3232
VARIANT: debian-11
3333
```
3434
35-
Beyond `git`, this image / `Dockerfile` includes `zsh`, [Oh My Zsh!](https://ohmyz.sh/), a non-root `vscode` user with `sudo` access, and a set of common dependencies for development.
35+
Beyond `git`, this image / `Dockerfile` includes `zsh`, [Oh My Zsh!](https://ohmyz.sh/), a non-root `vscode` user with `sudo` access, a set of common dependencies for development, and [Vcpkg](https://github.com/microsoft/vcpkg) a cross-platform package manager for C++.
36+
37+
### Using Vcpkg
38+
This dev container and its associated image includes a clone of the [`Vcpkg`](https://github.com/microsoft/vcpkg) repo for library packages, and a bootstrapped instance of the [Vcpkg-tool](https://github.com/microsoft/vcpkg-tool) itself.
39+
40+
The minimum version of `cmake` required to install packages is higher than the version available in the main package repositories for Debian (<=11) and Ubuntu (<=21.10). `Vcpkg` will download a compatible version of `cmake` for its own use if that is the case (on x86_64 architectures), however you can opt to reinstall a different version of `cmake` globally by adding `REINSTALL_CMAKE_VERSION_FROM_SOURCE: <VERSION>` to build args in `.devcontainer/docker-compose.yml`. This will install `cmake` from its github releases. For example:
41+
42+
```yaml
43+
args:
44+
VARIANT: debian-11
45+
REINSTALL_CMAKE_VERSION_FROM_SOURCE: "3.21.5" # Set to "none" to skip re-install of cmake
46+
```
47+
48+
Most additional library packages installed using Vcpkg will be downloaded from their [official distribution locations](https://github.com/microsoft/vcpkg#security). To configure Vcpkg in this container to access an alternate registry, more information can be found here: [Registries: Bring your own libraries to vcpkg](https://devblogs.microsoft.com/cppblog/registries-bring-your-own-libraries-to-vcpkg/).
49+
50+
To update the available library packages, pull the latest from the git repository using the following command in the terminal:
51+
52+
```sh
53+
cd "${VCPKG_ROOT}"
54+
git pull --ff-only
55+
```
56+
57+
> Note: Please review the [Vcpkg license details](https://github.com/microsoft/vcpkg#license) to better understand its own license and additional license information pertaining to library packages and supported ports.
3658

3759
### Adding the definition to a project or codespace
3860

containers/cpp-mariadb/test-project/test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ source test-utils.sh vscode
66
# Run common tests
77
checkCommon
88

9+
# Help determine distro
10+
. /etc/os-release
11+
912
# Run definition specific tests
1013
checkExtension "ms-vscode.cpptools"
1114
checkExtension "ms-vscode.cmake-tools"
1215
checkExtension "ms-vscode.cpptools-extension-pack"
1316
checkOSPackages "command-line-tools" build-essential cmake cppcheck valgrind clang lldb llvm gdb
17+
checkOSPackages "tools-for-vcpkg" tar curl zip unzip pkg-config bash-completion ninja-build
18+
VCPKG_UNSUPPORTED_ARM64_VERSION_CODENAMES="stretch bionic"
19+
if [ "$(dpkg --print-architecture)" = "amd64" ] || [[ ! "${VCPKG_UNSUPPORTED_ARM64_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
20+
check "VCPKG_ROOT" [ -d "${VCPKG_ROOT}" ]
21+
check "VCPKG_DOWNLOAD" [ -d "${VCPKG_DOWNLOADS}" ]
22+
VCPKG_FORCE_SYSTEM_BINARIES=1 check "vcpkg-from-root" ${VCPKG_ROOT}/vcpkg --version
23+
VCPKG_FORCE_SYSTEM_BINARIES=1 check "vcpkg-from-bin" vcpkg --version
24+
fi
25+
checkOSPackages "tools-for-mariadb" libmariadb3 libmariadb-dev
1426
check "g++" g++ -g main.cpp -o main.out -lmariadbcpp
1527
check "main.out" ./main.out
1628
rm main.out

containers/cpp/test-project/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ checkCommon
1212
# Run definition specific tests
1313
checkExtension "ms-vscode.cpptools"
1414
checkOSPackages "command-line-tools" build-essential cmake cppcheck valgrind clang lldb llvm gdb
15-
checkOSPackages "tools-for-vcpkg" tar curl zip unzip pkg-config bash-completion
15+
checkOSPackages "tools-for-vcpkg" tar curl zip unzip pkg-config bash-completion ninja-build
1616
VCPKG_UNSUPPORTED_ARM64_VERSION_CODENAMES="stretch bionic"
1717
if [ "$(dpkg --print-architecture)" = "amd64" ] || [[ ! "${VCPKG_UNSUPPORTED_ARM64_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
1818
check "VCPKG_ROOT" [ -d "${VCPKG_ROOT}" ]

0 commit comments

Comments
 (0)