Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev container with Celix dependencies #656

Merged
merged 1 commit into from
Dec 15, 2023
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/.project
.DS_Store
.clion.source.upload.marker
.idea
.vscode
*.iml
Expand Down
25 changes: 25 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# 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.

tasks:
- init: |
mkdir -p cmake-build-debug-gitpod
cd cmake-build-debug-gitpod && ../container/support-scripts/build-all.sh && make -j

image:
file: container/Containerfile.gitpod
rlenferink marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
![Celix MacOS](https://github.com/apache/celix/workflows/Celix%20MacOS/badge.svg)
[![codecov](https://codecov.io/gh/apache/celix/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/celix)
[![Coverity Scan Build Status](https://scan.coverity.com/projects/6685/badge.svg)](https://scan.coverity.com/projects/6685)
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/apache/celix)

Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component
and in-process service-oriented programming.
Expand Down
64 changes: 64 additions & 0 deletions container/Containerfile.gitpod
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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.

# SSH credentials:
# root@password

FROM docker.io/gitpod/workspace-full:2023-10-06-16-22-14@sha256:76d3041cc7a2caa00d6f4610ace0e15009c361515f3d5d9ee6690e4019adcfd4

# Switch to root user to install dependencies and configure sshd
USER root

# Install dependencies
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
# Development dependencies \
dos2unix \
git \
locales-all \
rsync \
tar \
ssh \
tzdata \
# Build dependencies \
build-essential \
ccache \
cmake \
curl \
default-jdk \
gcc \
g++ \
gdb \
make \
python3 \
# Celix dependencies \
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 && \
apt-get clean

# Switch back to the (default) gitpod user
USER gitpod
71 changes: 71 additions & 0 deletions container/Containerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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.

# SSH credentials:
# root@password

FROM docker.io/library/ubuntu:22.04@sha256:b492494d8e0113c4ad3fe4528a4b5ff89faa5331f7d52c5c138196f69ce176a6

# Install dependencies
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
# Development dependencies \
dos2unix \
git \
locales-all \
rsync \
tar \
ssh \
tzdata \
# Build dependencies \
build-essential \
ccache \
cmake \
curl \
default-jdk \
gcc \
g++ \
gdb \
make \
python3 \
# Celix dependencies \
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 && \
apt-get clean

RUN ( \
echo 'Port 2233'; \
echo 'LogLevel INFO'; \
echo 'PermitRootLogin yes'; \
echo 'PasswordAuthentication yes'; \
echo 'Subsystem sftp /usr/lib/openssh/sftp-server'; \
) > /etc/ssh/sshd_config_celix \
&& mkdir /run/sshd

RUN yes password | passwd root

CMD ["/usr/sbin/sshd", "-D", "-e", "-f", "/etc/ssh/sshd_config_celix"]
56 changes: 56 additions & 0 deletions container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Celix dev container usage

This subdirectory contains a [Gitpod Containerfile](./Containerfile.gitpod) for developing on Celix using [Gitpod](https://gitpod.io/#https://github.com/apache/celix)
and a [Ubuntu Containerfile](./Containerfile.ubuntu) for local development on Celix.

The below steps only need to be executed if you want to develop locally, and not via Gitpod.

## Build the celix-dev image yourself

To always be able to develop on Celix with an up-to-date image, built the image yourself.

```bash
./container/build-ubuntu-container.sh
```

## Using the image

### Start locally with SSH daemon

```bash
cd <project-root>

# Start a local container with the SSH daemon running
./container/start-ubuntu-container.sh
```

Now connect to the container via the remote container option of your favoured IDE and start building/developing.

For example, you can now start with:

* CLion connected to the container using [JetBrains Gateway](https://www.jetbrains.com/help/clion/remote-development-a.html)
* CLion configured to connect to the container as [Remote Host](https://www.jetbrains.com/help/clion/remote-projects-support.html)

When finished with development and testing, press `CTRL + \` to stop the SSH daemon and exit the container.

### Start locally with only a bash shell

The start script allows passing of additional paramters, which will override the starting of the SSH daemon.
Execute the following commands to open a bash shell and build Celix from the command line:

```bash
cd <project-root>

# Start a local container and open a bash shell
./container/start-ubuntu-container.sh bash

# Build Apache Celix
mkdir celix-build
cd celix-build
../container/support-scripts/build-all.sh
make -j

# Run the unit tests for Apache Celix
ctest --output-on-failure
```

35 changes: 35 additions & 0 deletions container/build-ubuntu-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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 a Celix dev container with all needed dependencies pre-installed.

SCRIPT_LOCATION=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
CELIX_REPO_ROOT=$(realpath "${SCRIPT_LOCATION}/..")

# Check which container engine is available.
# Check for podman first, because the 'podman-docker' package might be installed providing a dummy 'docker' command.
if command -v podman > /dev/null 2>&1; then
CONTAINER_ENGINE="podman"
else
CONTAINER_ENGINE="docker"
fi

cd "${SCRIPT_LOCATION}"
${CONTAINER_ENGINE} build -t apache/celix-dev:ubuntu-latest -f Containerfile.ubuntu .

48 changes: 48 additions & 0 deletions container/start-ubuntu-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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.
#
# Start a Celix dev container with all needed dependencies
# pre-installed already.

SCRIPT_LOCATION=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
CELIX_REPO_ROOT=$(realpath "${SCRIPT_LOCATION}/..")

CONTAINER_COMMAND_DEFAULT="/usr/sbin/sshd -D -e -f /etc/ssh/sshd_config_celix"
CONTAINER_COMMAND=${1:-${CONTAINER_COMMAND_DEFAULT}}

# Check which container engine is available.
# Check for podman first, because the 'podman-docker' package might be installed providing a dummy 'docker' command.
if command -v podman > /dev/null 2>&1; then
CONTAINER_ENGINE="podman"
else
CONTAINER_ENGINE="docker"
fi

# Start a container with all the Celix dependencies pre-installed
# --privileged to allow the unit tests to change thread priorities
# --net=host is used to allow e.g. communication with etcd
# --volume & --workdir are set to the Celix repo root (to allow building and editing of the Celix repo)
# --security-opt disables SELinux for the container
${CONTAINER_ENGINE} run -it --rm --privileged \
--net=host \
--volume "${CELIX_REPO_ROOT}":"${CELIX_REPO_ROOT}" \
--workdir "${CELIX_REPO_ROOT}" \
--security-opt label=disable \
apache/celix-dev:ubuntu-latest ${CONTAINER_COMMAND}

30 changes: 30 additions & 0 deletions container/support-scripts/build-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
rlenferink marked this conversation as resolved.
Show resolved Hide resolved
#
# 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 \
..

Loading