Skip to content

Commit 5e18244

Browse files
authored
Merge pull request #731 from apache/feature/devcontainer
Feature/devcontainer
2 parents 06ae35a + 3b54597 commit 5e18244

31 files changed

+599
-304
lines changed

.devcontainer/Containerfile

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
FROM docker.io/library/ubuntu:24.04@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 as build
19+
20+
# Install dependencies
21+
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
22+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
23+
build-essential \
24+
ccache \
25+
cmake \
26+
gcc \
27+
g++ \
28+
make \
29+
zip \
30+
ninja-build \
31+
lcov \
32+
sudo \
33+
python3 \
34+
pipx && \
35+
apt-get clean
36+
37+
#python3-pip && \
38+
39+
# Build image using conan & cmake
40+
FROM build as conan-build
41+
42+
# Install conan
43+
#RUN pip3 install conan && pip3 cache purge
44+
##RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
45+
# python3-conan && \
46+
# apt-get clean
47+
ENV PATH="${PATH}:/root/.local/bin"
48+
RUN pipx install conan
49+
50+
# Setup conan profile for root
51+
COPY conan-container-default-profile /root/.conan2/profiles/default
52+
COPY conan-container-debug-profile /root/.conan2/profiles/debug
53+
54+
# Build image using apt dependencies
55+
FROM build as apt-build
56+
57+
# Install celix dependencies (note git needed for cloning gtest)
58+
RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \
59+
DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends \
60+
git \
61+
civetweb \
62+
libavahi-compat-libdnssd-dev \
63+
libcivetweb-dev \
64+
libcpputest-dev \
65+
libcurl4-openssl-dev \
66+
libczmq-dev \
67+
libffi-dev \
68+
libjansson-dev \
69+
libxml2-dev \
70+
libzip-dev \
71+
rapidjson-dev \
72+
uuid-dev && \
73+
sudo apt-get clean
74+
75+
#Note from build not conan-build, because conan-dev uses a celixdev user
76+
FROM build as conan-dev
77+
78+
# Remove ubuntu user and add celixdev with sudo rights and a "celixdev" password
79+
RUN userdel -r ubuntu && \
80+
groupadd --gid 1000 celixdev && \
81+
useradd --uid 1000 --gid 1000 -m \
82+
-s /bin/bash -G sudo celixdev && \
83+
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
84+
echo "celixdev:celixdev" | chpasswd
85+
USER celixdev
86+
WORKDIR /home/celixdev
87+
88+
#Create workdir, used in vscode
89+
#RUN sudo mkdir -p /workspaces/celix/build && sudo chown -R celixdev:celixdev /workspaces
90+
91+
# Setup python venv for celixdev and install conan
92+
ENV PATH="${PATH}:/home/celixdev/.local/bin"
93+
RUN pipx install conan
94+
95+
# Setup conan profile for celixdev
96+
COPY --chown=celixdev:celixdev conan-container-default-profile /home/celixdev/.conan2/profiles/default
97+
COPY --chown=celixdev:celixdev conan-container-debug-profile /home/celixdev/.conan2/profiles/debug
98+
99+
#Install development dependencies
100+
RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \
101+
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
102+
gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server cmake-curses-gui gdb \
103+
wget curl && \
104+
sudo apt-get clean
105+
106+
RUN sudo mkdir /run/sshd
107+
108+
FROM apt-build as apt-dev
109+
110+
# Remove ubuntu user and add celixdev with sudo rights and a "celixdev" password
111+
RUN userdel -r ubuntu && \
112+
groupadd --gid 1000 celixdev && \
113+
useradd --uid 1000 --gid 1000 -m \
114+
-s /bin/bash -G sudo celixdev && \
115+
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
116+
echo "celixdev:celixdev" | chpasswd
117+
USER celixdev
118+
WORKDIR /home/celixdev
119+
120+
#Install development dependencies
121+
RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \
122+
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
123+
gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server cmake-curses-gui gdb \
124+
wget curl && \
125+
sudo apt-get clean
126+
127+
RUN sudo mkdir /run/sshd

.devcontainer/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
# Apache Celix Development Container
19+
20+
## Introduction
21+
22+
This directory contains a [DevContainer](https://containers.dev) setup for developing Apache Celix inside a container.
23+
24+
Although Apache Celix can be built using CMake with APT-installed dependencies or Conan with Conan-installed/built
25+
dependencies, this DevContainer setup currently only supports Conan.
26+
27+
Please note, the DevContainer setup is not broadly tested and might not work on all systems.
28+
It has been tested on Ubuntu 23.10 and Fedora 40.
29+
30+
## VSCode Usage
31+
32+
VSCode has built-in support for DevContainers.
33+
Simply launch VSCode using the Celix workspace folder, and you will be prompted to open the workspace in a container.
34+
35+
VSCode ensures that your host `.gitconfig` file, `.gnupg` directory, and SSH agent forwarding are available in the
36+
container.
37+
38+
## CLion Usage
39+
40+
At the time of writing this readme, CLion does not fully support DevContainers,
41+
but there is some support focusing on Docker. Using a container and remote development via SSH with CLion works.
42+
43+
To start developing in a container with build a CevContainer image using the `build-devcontainer-image.sh` script
44+
and then start a container with SSHD running and interactively set up `.gitconfig`, `.gnupg`, and SSH agent
45+
forwarding, using the `.devcontainer/run-dev-container.sh` script:
46+
47+
```bash
48+
cd ${CELIX_ROOT}
49+
./.devcontainer/build-devcontainer-image.sh
50+
./.devcontainer/run-devcontainer.sh
51+
ssh -p 2233 celixdev@localhost
52+
```
53+
54+
In CLion, open the Remote Development window by navigating to "File -> Remote Development..." and add a new
55+
configuration. When a new configuration is added, you can start a new project using `/home/celixdev/workspace` as the
56+
project root and selecting CLion as the IDE.
57+
58+
Also ensure the CMake profile from the - conan generated - `CMakeUserPresets.json` is used: Enable the profile in the
59+
Settings -> "Build, Execution, Deployment" -> CMake menu.
60+
61+
## Running tests
62+
Tests can be run using ctest.
63+
When building with conan, the conanrun.sh script will setup the environment for the
64+
built dependencies. To run the tests, execute the following commands:
65+
66+
```shell
67+
cd build
68+
ctest --output-on-failure --test-command ./workspaces/celix/build/conanrun.sh
69+
```
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
# KIND, either express or implied. See the License for the
1717
# specific language governing permissions and limitations
1818
# under the License.
19-
#
20-
# Build a Celix dev container with all needed dependencies pre-installed.
2119

2220
SCRIPT_LOCATION=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
2321
CELIX_REPO_ROOT=$(realpath "${SCRIPT_LOCATION}/..")
22+
IMAGE_TARGET="${1:-conan-dev}"
2423

2524
# Check which container engine is available.
2625
# Check for podman first, because the 'podman-docker' package might be installed providing a dummy 'docker' command.
@@ -31,4 +30,4 @@ else
3130
fi
3231

3332
cd "${SCRIPT_LOCATION}"
34-
${CONTAINER_ENGINE} build -t apache/celix-dev:ubuntu-latest -f Containerfile.ubuntu .
33+
${CONTAINER_ENGINE} build -t apache/celix-${IMAGE_TARGET} -f Containerfile --target ${IMAGE_TARGET} .
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
conan build . --profile debug \
21+
--options celix/*:build_all=True --options celix/*:enable_address_sanitizer=True \
22+
--options celix/*:enable_testing=True --options celix/*:enable_ccache=True \
23+
--conf:build tools.cmake.cmaketoolchain:generator=Ninja \
24+
--output-folder build
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
#!/bin/bash
2-
#
31
# Licensed to the Apache Software Foundation (ASF) under one
42
# or more contributor license agreements. See the NOTICE file
53
# distributed with this work for additional information
64
# regarding copyright ownership. The ASF licenses this file
75
# to you under the Apache License, Version 2.0 (the
86
# "License"); you may not use this file except in compliance
97
# with the License. You may obtain a copy of the License at
10-
#
8+
#
119
# http://www.apache.org/licenses/LICENSE-2.0
12-
#
10+
#
1311
# Unless required by applicable law or agreed to in writing,
1412
# software distributed under the License is distributed on an
1513
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1614
# KIND, either express or implied. See the License for the
1715
# specific language governing permissions and limitations
1816
# under the License.
1917

20-
BUILD_TYPE=${1:-Debug}
21-
22-
cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
23-
-DCMAKE_INSTALL_PREFIX=../celix-install \
24-
-DBUILD_EXPERIMENTAL=ON \
25-
-DENABLE_TESTING=ON \
26-
-DRSA_JSON_RPC=ON \
27-
-DRSA_SHM=ON \
28-
-DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON \
29-
..
18+
#Based on gcc from ubuntu:24.04 base image
19+
[settings]
20+
arch=x86_64
21+
build_type=Debug
22+
compiler=gcc
23+
compiler.cppstd=17
24+
compiler.libcxx=libstdc++11
25+
compiler.version=13
26+
os=Linux
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
#Based on gcc from ubuntu:24.04 base image
19+
[settings]
20+
arch=x86_64
21+
build_type=Release
22+
compiler=gcc
23+
compiler.cppstd=17
24+
compiler.libcxx=libstdc++11
25+
compiler.version=13
26+
os=Linux

.devcontainer/devcontainer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Apache Celix Dev Container",
3+
"build": {
4+
"dockerfile": "Containerfile",
5+
"target": "conan-dev"
6+
},
7+
"runArgs" : [
8+
"--userns=keep-id"
9+
],
10+
"securityOpt":["label=disable"],
11+
"remoteUser": "celixdev",
12+
"containerUser": "celixdev",
13+
"onCreateCommand": "sh .devcontainer/setup-project-with-conan.sh",
14+
"postCreateCommand": "sh .devcontainer/build-project-with-conan.sh"
15+
}

0 commit comments

Comments
 (0)