Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 24 additions & 84 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

FROM docker.io/library/ubuntu:24.04@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 as build
FROM docker.io/library/ubuntu:24.04@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 as base

# Install dependencies
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
Expand All @@ -28,101 +28,41 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
make \
zip \
ninja-build \
clang-tidy \
lcov \
sudo \
python3 \
pipx && \
apt-get clean

#python3-pip && \

# Build image using conan & cmake
FROM build as conan-build

# Install conan
#RUN pip3 install conan && pip3 cache purge
##RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
# python3-conan && \
# apt-get clean
ENV PATH="${PATH}:/root/.local/bin"
RUN pipx install conan

# Setup conan profile for root
COPY conan-container-default-profile /root/.conan2/profiles/default
COPY conan-container-debug-profile /root/.conan2/profiles/debug

# Build image using apt dependencies
FROM build as apt-build
FROM base as conan-build

# Install celix dependencies (note git needed for cloning gtest)
RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends \
git \
civetweb \
libavahi-compat-libdnssd-dev \
libcivetweb-dev \
libcpputest-dev \
libcurl4-openssl-dev \
libczmq-dev \
libffi-dev \
libjansson-dev \
libxml2-dev \
libzip-dev \
libuv1-dev \
rapidjson-dev \
uuid-dev && \
sudo apt-get clean
ARG USERNAME=celixdev
ARG USER_UID=1000
ARG USER_GID=1000

#Note from build not conan-build, because conan-dev uses a celixdev user
FROM build as conan-dev

# Remove ubuntu user and add celixdev with sudo rights and a "celixdev" password
RUN userdel -r ubuntu && \
groupadd --gid 1000 celixdev && \
useradd --uid 1000 --gid 1000 -m \
-s /bin/bash -G sudo celixdev && \
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
echo "celixdev:celixdev" | chpasswd
USER celixdev
WORKDIR /home/celixdev

#Create workdir, used in vscode
#RUN sudo mkdir -p /workspaces/celix/build && sudo chown -R celixdev:celixdev /workspaces

# Setup python venv for celixdev and install conan
ENV PATH="${PATH}:/home/celixdev/.local/bin"
RUN pipx install conan
groupadd --gid ${USER_GID} ${USERNAME} && \
useradd --uid ${USER_UID} --gid ${USER_GID} --create-home --shell /bin/bash ${USERNAME} && \
usermod -aG sudo ${USERNAME} && \
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

# Setup conan profile for celixdev
COPY --chown=celixdev:celixdev conan-container-default-profile /home/celixdev/.conan2/profiles/default
COPY --chown=celixdev:celixdev conan-container-debug-profile /home/celixdev/.conan2/profiles/debug
USER ${USERNAME}
WORKDIR /home/${USERNAME}

#Install development dependencies
RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server cmake-curses-gui gdb \
wget curl && \
sudo apt-get clean

RUN sudo mkdir /run/sshd
ENV PATH="${PATH}:/home/${USERNAME}/.local/bin"
RUN pipx install conan && \
conan profile detect --force && \
cp /home/${USERNAME}/.conan2/profiles/default /home/${USERNAME}/.conan2/profiles/release && \
cp /home/${USERNAME}/.conan2/profiles/default /home/${USERNAME}/.conan2/profiles/debug && \
sed -i 's/^build_type=.*/build_type=Release/' /home/${USERNAME}/.conan2/profiles/release && \
sed -i 's/^build_type=.*/build_type=Debug/' /home/${USERNAME}/.conan2/profiles/debug

FROM apt-build as apt-dev

# Remove ubuntu user and add celixdev with sudo rights and a "celixdev" password
RUN userdel -r ubuntu && \
groupadd --gid 1000 celixdev && \
useradd --uid 1000 --gid 1000 -m \
-s /bin/bash -G sudo celixdev && \
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
echo "celixdev:celixdev" | chpasswd
USER celixdev
WORKDIR /home/celixdev
FROM base as conan-dev

#Install development dependencies
RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server cmake-curses-gui gdb \
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
gnupg2 dos2unix locales-all ssh rsync tar tzdata sudo vim cmake-curses-gui gdb \
wget curl && \
sudo apt-get clean

RUN sudo mkdir /run/sshd
apt-get clean \
56 changes: 29 additions & 27 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,51 @@ limitations under the License.

This directory contains a [DevContainer](https://containers.dev) setup for developing Apache Celix inside a container.

Although Apache Celix can be built using CMake with APT-installed dependencies or Conan with Conan-installed/built
dependencies, this DevContainer setup currently only supports Conan.
Although Apache Celix can be built using CMake with APT-installed dependencies or Conan
with Conan-installed/built dependencies, this DevContainer setup is based on Conan.

Please note, the DevContainer setup is not broadly tested and might not work on all systems.
It has been tested on Ubuntu 23.10 and Fedora 40.
It has been tested on MacOS 26 and Fedora 43, using podman.

## Mounts

The devcontainer uses the following container volumes to ensure dependency build and project
building is more efficient, even after recreating a devcontainer:

- celixdev-conan-package-cache
- celixdev-conan-download-cache
- celixdev-ccache-cache

Use `podman volume rm` / `docker volume rm` to remove the volumes if you do no longer use them.

## VSCode Usage

VSCode has built-in support for DevContainers.
Simply launch VSCode using the Celix workspace folder, and you will be prompted to open the workspace in a container.
Launch VSCode using the Celix workspace folder, and you will be prompted to
open the workspace in a container.

VSCode ensures that your host `.gitconfig` file, `.gnupg` directory, and SSH agent forwarding are available in the
container.
VSCode ensures that your host `.gitconfig` file and SSH agent forwarding
are available in the container.

## CLion Usage

At the time of writing this readme, CLion does not fully support DevContainers,
but there is some support focusing on Docker. Using a container and remote development via SSH with CLion works.
CLion 2025.3.1 includes DevContainer support (including Podman), so you can open this repository directly
using the IDE's DevContainer workflow. Once the container is built, enable and select the conan-debug (generated)
profile.

To start developing in a container with build a CevContainer image using the `build-devcontainer-image.sh` script
and then start a container with SSHD running and interactively set up `.gitconfig`, `.gnupg`, and SSH agent
forwarding, using the `.devcontainer/run-dev-container.sh` script:
## Building

```bash
cd ${CELIX_ROOT}
./.devcontainer/build-devcontainer-image.sh
./.devcontainer/run-devcontainer.sh
ssh -p 2233 celixdev@localhost
```
Build can be done from the root workspace dir:

In CLion, open the Remote Development window by navigating to "File -> Remote Development..." and add a new
configuration. When a new configuration is added, you can start a new project using `/home/celixdev/workspace` as the
project root and selecting CLion as the IDE.

Also ensure the CMake profile from the - conan generated - `CMakeUserPresets.json` is used: Enable the profile in the
Settings -> "Build, Execution, Deployment" -> CMake menu.
```shell
cmake --build build --parallel
```

## Running tests

Tests can be run using ctest.
When building with conan, the conanrun.sh script will setup the environment for the
built dependencies. To run the tests, execute the following commands:
When building with Conan, run tests from the build directory after configuring/building:

```shell
cd build
ctest --output-on-failure --test-command ./workspaces/celix/build/conanrun.sh
ctest --output-on-failure --test-dir build
```
33 changes: 0 additions & 33 deletions .devcontainer/build-devcontainer-image.sh

This file was deleted.

24 changes: 0 additions & 24 deletions .devcontainer/build-project-with-conan.sh

This file was deleted.

26 changes: 0 additions & 26 deletions .devcontainer/conan-container-debug-profile

This file was deleted.

26 changes: 0 additions & 26 deletions .devcontainer/conan-container-default-profile

This file was deleted.

37 changes: 33 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,41 @@
"dockerfile": "Containerfile",
"target": "conan-dev"
},
"runArgs" : [
"runArgs": [
"--userns=keep-id"
],
"securityOpt":["label=disable"],
"mounts": [
"type=volume,source=celixdev-conan-package-cache,target=/home/celixdev/.conan2/p",
"type=volume,source=celixdev-conan-download-cache,target=/home/celixdev/.conan2/d",
"type=volume,source=celixdev-ccache-cache,target=/home/celixdev/.ccache"
],
"containerEnv": {
"CONAN_PROFILE": "debug",
"CONAN_OUT": "build",
"CONAN_OPTS": "--options celix/*:build_all=True --options celix/*:enable_address_sanitizer=True --options celix/*:enable_testing=True --options celix/*:enable_ccache=True --options celix/*:enable_code_coverage=True",
"CONAN_CONF": "--conf tools.cmake.cmaketoolchain:generator=Ninja"
},
"securityOpt": [
"label=disable"
],
"remoteUser": "celixdev",
"containerUser": "celixdev",
"onCreateCommand": "sh .devcontainer/setup-project-with-conan.sh",
"postCreateCommand": "sh .devcontainer/build-project-with-conan.sh"
"postCreateCommand": "conan install . --build missing --profile ${CONAN_PROFILE} ${CONAN_OPTS} ${CONAN_CONF} --output-folder ${CONAN_OUT} && cmake --preset conan-debug",
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools",
"matepek.vscode-catch2-test-adapter",
"ms-vscode.cmake-tools"
]
},
"jetbrains": {
"backend": "CLion"
}
}
}
Loading
Loading