Skip to content

Commit

Permalink
Merge pull request #731 from apache/feature/devcontainer
Browse files Browse the repository at this point in the history
Feature/devcontainer
  • Loading branch information
PengZheng authored Jan 11, 2025
2 parents 06ae35a + 3b54597 commit 5e18244
Show file tree
Hide file tree
Showing 31 changed files with 599 additions and 304 deletions.
127 changes: 127 additions & 0 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

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

# Install dependencies
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
build-essential \
ccache \
cmake \
gcc \
g++ \
make \
zip \
ninja-build \
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

# 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 \
rapidjson-dev \
uuid-dev && \
sudo apt-get clean

#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

# 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

#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

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

#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
69 changes: 69 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# Apache Celix Development Container

## Introduction

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.

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.

## 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.

VSCode ensures that your host `.gitconfig` file, `.gnupg` directory, 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.

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:

```bash
cd ${CELIX_ROOT}
./.devcontainer/build-devcontainer-image.sh
./.devcontainer/run-devcontainer.sh
ssh -p 2233 celixdev@localhost
```

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.

## 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:

```shell
cd build
ctest --output-on-failure --test-command ./workspaces/celix/build/conanrun.sh
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Build a Celix dev container with all needed dependencies pre-installed.

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

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

cd "${SCRIPT_LOCATION}"
${CONTAINER_ENGINE} build -t apache/celix-dev:ubuntu-latest -f Containerfile.ubuntu .
${CONTAINER_ENGINE} build -t apache/celix-${IMAGE_TARGET} -f Containerfile --target ${IMAGE_TARGET} .
24 changes: 24 additions & 0 deletions .devcontainer/build-project-with-conan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

conan build . --profile debug \
--options celix/*:build_all=True --options celix/*:enable_address_sanitizer=True \
--options celix/*:enable_testing=True --options celix/*:enable_ccache=True \
--conf:build tools.cmake.cmaketoolchain:generator=Ninja \
--output-folder build
25 changes: 11 additions & 14 deletions container/support-scripts/build-all.sh → .devcontainer/conan-container-debug-profile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

BUILD_TYPE=${1:-Debug}

cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX=../celix-install \
-DBUILD_EXPERIMENTAL=ON \
-DENABLE_TESTING=ON \
-DRSA_JSON_RPC=ON \
-DRSA_SHM=ON \
-DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON \
..
#Based on gcc from ubuntu:24.04 base image
[settings]
arch=x86_64
build_type=Debug
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
26 changes: 26 additions & 0 deletions .devcontainer/conan-container-default-profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

#Based on gcc from ubuntu:24.04 base image
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=13
os=Linux
15 changes: 15 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Apache Celix Dev Container",
"build": {
"dockerfile": "Containerfile",
"target": "conan-dev"
},
"runArgs" : [
"--userns=keep-id"
],
"securityOpt":["label=disable"],
"remoteUser": "celixdev",
"containerUser": "celixdev",
"onCreateCommand": "sh .devcontainer/setup-project-with-conan.sh",
"postCreateCommand": "sh .devcontainer/build-project-with-conan.sh"
}
Loading

0 comments on commit 5e18244

Please sign in to comment.