From 21cf541fd8e4e4053f1765587a18cc4f40b71a68 Mon Sep 17 00:00:00 2001 From: Roy Lenferink Date: Sun, 24 Sep 2023 20:37:28 +0200 Subject: [PATCH] Add Gitpod and Ubuntu dev containers with Celix dependencies This allows building and developing of Celix by using this pre-built container --- .gitignore | 1 + .gitpod.yml | 25 +++++++++ README.md | 1 + container/Containerfile.gitpod | 64 +++++++++++++++++++++++ container/Containerfile.ubuntu | 71 ++++++++++++++++++++++++++ container/README.md | 56 ++++++++++++++++++++ container/build-ubuntu-container.sh | 35 +++++++++++++ container/start-ubuntu-container.sh | 48 +++++++++++++++++ container/support-scripts/build-all.sh | 30 +++++++++++ 9 files changed, 331 insertions(+) create mode 100644 .gitpod.yml create mode 100644 container/Containerfile.gitpod create mode 100644 container/Containerfile.ubuntu create mode 100644 container/README.md create mode 100755 container/build-ubuntu-container.sh create mode 100755 container/start-ubuntu-container.sh create mode 100755 container/support-scripts/build-all.sh diff --git a/.gitignore b/.gitignore index 65ddf3698..6073f702f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ /.project .DS_Store +.clion.source.upload.marker .idea .vscode *.iml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 000000000..317f2cea7 --- /dev/null +++ b/.gitpod.yml @@ -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 diff --git a/README.md b/README.md index c0c2a07f9..dc7528a2c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/container/Containerfile.gitpod b/container/Containerfile.gitpod new file mode 100644 index 000000000..7ac418c14 --- /dev/null +++ b/container/Containerfile.gitpod @@ -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 diff --git a/container/Containerfile.ubuntu b/container/Containerfile.ubuntu new file mode 100644 index 000000000..af732e059 --- /dev/null +++ b/container/Containerfile.ubuntu @@ -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"] diff --git a/container/README.md b/container/README.md new file mode 100644 index 000000000..b958466ab --- /dev/null +++ b/container/README.md @@ -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 + +# 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 + +# 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 +``` + diff --git a/container/build-ubuntu-container.sh b/container/build-ubuntu-container.sh new file mode 100755 index 000000000..aafa8aa0d --- /dev/null +++ b/container/build-ubuntu-container.sh @@ -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 . + diff --git a/container/start-ubuntu-container.sh b/container/start-ubuntu-container.sh new file mode 100755 index 000000000..2df3dadef --- /dev/null +++ b/container/start-ubuntu-container.sh @@ -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} + diff --git a/container/support-scripts/build-all.sh b/container/support-scripts/build-all.sh new file mode 100755 index 000000000..16acf6dff --- /dev/null +++ b/container/support-scripts/build-all.sh @@ -0,0 +1,30 @@ +#!/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 \ + .. +