diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile index 8b95e0e70..4c6f5eb77 100644 --- a/.devcontainer/Containerfile +++ b/.devcontainer/Containerfile @@ -73,20 +73,6 @@ RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \ uuid-dev && \ sudo apt-get clean - - -#TODO deps needed for clion devcontainer -ARG DEVELOP_PACKAGES="$DEVELOP_PACKAGES curl unzip ps libxext libxrender libxtst libxi freetype procps gcompat" - -ARG SSHD_INSTALL="sudo ( \ - 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 \ - && sudo mkdir /run/sshd" - FROM conan-build as conan-dev #Install development dependencies @@ -95,22 +81,14 @@ RUN sudo DEBIAN_FRONTEND="noninteractive" apt-get update && \ gnupg2 dos2unix git locales-all rsync tar ssh tzdata sudo vim openssh-server && \ sudo apt-get clean - #Setup sshd - # RUN sudo mkdir /etc/ssh && \ - # sudo touch /etc/ssh/sshd_config_celix && \ - # sudo echo "Port 2233\n \ - # LogLevel INFO\n \ - # PermitRootLogin yes\n \ - # PasswordAuthentication yes\n \ - # Subsystem sftp /usr/lib/openssh/sftp-server" > /etc/ssh/sshd_config_celix && \ - # sudo mkdir /run/sshd - RUN sudo mkdir /run/sshd FROM apt-build as apt-dev #Install development dependencies -RUN ${APT_INSTALL} +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 && \ + sudo apt-get clean -#Setup sshd -RUN ${SSHD_INSTALL} +RUN sudo mkdir /run/sshd diff --git a/.devcontainer/README.md b/.devcontainer/README.md index ffd0fee00..9f387d4db 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -17,24 +17,32 @@ limitations under the License. # Apache Celix Development Container -## Intro +## Introduction -TODO add intro, explain difference build, dev images and apt/conan variant. +This directory contains a [DevContainer](https://containers.dev) setup for developing Apache Celix inside a container. + +While Apache Celix can be built using CMake with APT-installed dependencies or using Conan with Conan-installed/built +dependencies, this DevContainer setup currently only supports building Celix using 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. ## VSCode Usage -Support for development containers in VSCode is built-in. Just startup VSCode using the celix workspace folder, -and you will be prompted to open the workspace in a container. +VSCode has built-in support for development containers. Simply start VSCode using the Celix workspace folder, and you +will be prompted to open the workspace in a container. -VSCode will ensure that your host .gitconfig file, .gnupg dir, and ssh agent forwarding is available in the container. +VSCode will ensure that your host `.gitconfig` file, `.gnupg` directory, and SSH agent forwarding are available in the +container. ## CLion Usage -Support for devcontainers in CLion is not built-in and currently not fully supported. -For CLion you can instead use remote development via ssh. -The `.devcontainer/run-dev-container.sh` script can be used to start a container with sshd running and interactively -setup .gitconfig, .gnupg, and ssh agent forwarding. -Before `.devcontainer/run-dev-container.sh` can be used, a `celix-conan-dev` image must be build. +CLion does not have built-in support for DevContainers and is not fully supported at this time. +Instead, you can use remote development via SSH with CLion. + +To start a container with SSHD running and interactively set up `.gitconfig`, `.gnupg`, and SSH agent forwarding, use +the `.devcontainer/run-dev-container.sh` script. +Before using this script, you must build a `celix-conan-dev` image. ```bash cd ${CELIX_ROOT} @@ -43,4 +51,7 @@ cd ${CELIX_ROOT} ssh -p 2233 celixdev@localhost ``` -In Clion open the Remote Development window using "File -> Remote Development ..." and add a new configuration. +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. \ No newline at end of file diff --git a/.devcontainer/run-dev-container.sh b/.devcontainer/run-dev-container.sh index 5e682488f..9ebc6969a 100755 --- a/.devcontainer/run-dev-container.sh +++ b/.devcontainer/run-dev-container.sh @@ -22,8 +22,10 @@ SCRIPT_LOCATION=$(realpath "$(dirname "${BASH_SOURCE[0]}")") CELIX_REPO_ROOT=$(realpath "${SCRIPT_LOCATION}/..") +CELIX_CONTAINER_ROOT="/home/celixdev/workspace" -CONTAINER_COMMAND_DEFAULT="sudo /usr/sbin/sshd -D -e -p 2233" +CONTAINER_SSH_PORT=2233 +CONTAINER_COMMAND_DEFAULT="sudo /usr/sbin/sshd -D -e -p ${CONTAINER_SSH_PORT}" CONTAINER_COMMAND=${1:-${CONTAINER_COMMAND_DEFAULT}} CONTAINER_NAME="celixdev" @@ -66,12 +68,19 @@ if [ "$(${CONTAINER_ENGINE} ps -a --format '{{.Names}}' | grep ${CONTAINER_NAME} ask_and_execute "Container '${CONTAINER_NAME}' already exists. Do you want to remove it?" remove_celixdev_container fi +# Check again if container celixdev already exists and exit if it does +if [ "$(${CONTAINER_ENGINE} ps -a --format '{{.Names}}' | grep ${CONTAINER_NAME})" ]; then + echo "Container '${CONTAINER_NAME}' already exists. Exiting." + exit 1 +fi + ADDITIONAL_ARGS="" +GNUPG_DIR_MOUNTED=false add_gnupg_mount() { echo "Adding .gnupg directory mount arguments" - echo "TODO does not work yet, maybe a gpg agent can be used instead" - ADDITIONAL_ARGS="--volume ${HOME}/.gnupg:/home/celixdev/.gnupg:O" + ADDITIONAL_ARGS="${ADDITIONAL_ARGS} --volume ${HOME}/.gnupg:/home/celixdev/.gnupg:O" + GNUPG_DIR_MOUNTED=true } if [ -e "${HOME}/.gnupg" ]; then ask_and_execute "Do you want to mount the .gnupg directory to the container (as an overlayfs)?" add_gnupg_mount @@ -79,7 +88,7 @@ fi add_gitconfig_mount() { echo "Adding .gitconfig file mount arguments" - ADDITIONAL_ARGS="--volume ${HOME}/.gitconfig:/home/celixdev/.gitconfig:ro" + ADDITIONAL_ARGS="${ADDITIONAL_ARGS} --volume ${HOME}/.gitconfig:/home/celixdev/.gitconfig:ro" } if [ -e "${HOME}/.gitconfig" ]; then ask_and_execute "Do you want to mount the .gitconfig file to the container (as read-only)?" add_gitconfig_mount @@ -97,31 +106,27 @@ fi # Start a container with all the Celix dependencies pre-installed # --userns=keep-id is used to keep the user id the same in the container as on the host # --privileged to allow the unit tests to change thread priorities +# -d runs the container in detached mode +# -it starts the container in interactive mode +# --rm removes the container when it is stopped # --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 -# -d runs the container in detached mode echo "Starting container '${CONTAINER_NAME}' with command: ${CONTAINER_COMMAND}" ${CONTAINER_ENGINE} run -it --rm --privileged -d \ --name ${CONTAINER_NAME} \ --userns=keep-id \ --net=host \ ${ADDITIONAL_ARGS} \ - --volume "${CELIX_REPO_ROOT}":"${CELIX_REPO_ROOT}" \ - --workdir "${CELIX_REPO_ROOT}" \ + --volume "${CELIX_REPO_ROOT}":${CELIX_CONTAINER_ROOT} \ + --workdir "${CELIX_CONTAINER_ROOT}" \ --security-opt label=disable \ apache/celix-conan-dev:latest bash -c "${CONTAINER_COMMAND}" echo "" -#copy_ssh_id() { -# echo "Copying ssh key (password: celixdev)" -# ssh-copy-id -p 2233 celixdev@localhost -#} -#ask_and_execute "Do you want to copy the ssh key to the container?" copy_ssh_id - build_conan_deps() { echo "Building Celix dependencies with Conan" - ${CONTAINER_ENGINE} exec -it ${CONTAINER_NAME} bash -c "cd ${CELIX_REPO_ROOT} && .devcontainer/setup-project-with-conan.sh" + ${CONTAINER_ENGINE} exec -it ${CONTAINER_NAME} bash -c "cd ${CELIX_CONTAINER_ROOT} && .devcontainer/setup-project-with-conan.sh" } ask_and_execute "Do you want to build Celix dependencies with Conan?" build_conan_deps diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 95b92edae..ea1eb4004 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -1,4 +1,4 @@ -name: Celix development containers +name: Celix build containers on: push: @@ -7,7 +7,7 @@ on: - cron: '0 0 * * 0' # Weekly on Sunday at 00:00 UTC jobs: - container-build-ubuntu: + container-conan-build-ubuntu: runs-on: ubuntu-22.04 timeout-minutes: 120 steps: @@ -15,18 +15,19 @@ jobs: uses: actions/checkout@v3.3.0 - name: Build container image run: | - cd $GITHUB_WORKSPACE/container/ - ./build-ubuntu-container.sh - - name: Build Celix using container image + docker build -t apache/celix-conan-build:latest --target conan-build -f .devcontainer/Containerfile + - name: Build and test Celix the conan container image run: | - cd $GITHUB_WORKSPACE/container/ - ./run-ubuntu-container.sh "mkdir -p build && cd build && ../container/support-scripts/build-all.sh && make -j" - - name: Run Celix tests using container image - run: | - cd $GITHUB_WORKSPACE/container/ - ./run-ubuntu-container.sh "cd build && ctest --output-on-failure" + docker run --rm -v $(pwd):/workspace --userns=keep-id apache/celix-conan-build:latest /bin/bash -c \ + "cd /workspace && \ + conan build . --build missing --options build_all=True --options enable_address_sanitizer=True \ + --options enable_testing=True --options enable_ccache=True --output-folder build \ + --conf tools.cmake.cmaketoolchain:generator=Ninja --settings build_type=Debug && \ + cd build && \ + source conanrun.sh && \ + ctest --output-on-failure" - container-build-gitpod: + container-apt-build-ubuntu: runs-on: ubuntu-22.04 timeout-minutes: 120 steps: @@ -34,5 +35,24 @@ jobs: uses: actions/checkout@v3.3.0 - name: Build container image run: | - cd $GITHUB_WORKSPACE/container/ - docker build -t apache/celix-dev:gitpod-latest -f Containerfile.gitpod . + docker build -t apache/celix-apt-build:latest --target apt-build -f .devcontainer/Containerfile + - name: Build and test Celix the conan container image + run: | + docker run --rm -v $(pwd):/workspace --userns=keep-id apache/celix-conan-build:latest /bin/bash -c \ + "cd /workspace && \ + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXPERIMENTAL=ON -DENABLE_TESTING=ON -DRSA_JSON_RPC=ON -DRSA_SHM=ON \ + -DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON .. && \ + cd build && \ + make -j && \ + ctest --output-on-failure" + + build-dev-container-images: + runs-on: ubuntu-22.04 + timeout-minutes: 120 + steps: + - name: Checkout source code + uses: actions/checkout@v3.3.0 + - name: Build dev container images + run: | + docker build -t apache/celix-conan-dev:latest --target conan-dev -f .devcontainer/Containerfile + docker build -t apache/celix-apt-dev:latest --target apt-dev -f .devcontainer/Containerfile diff --git a/container/Containerfile.gitpod b/container/Containerfile.gitpod deleted file mode 100644 index a9591d251..000000000 --- a/container/Containerfile.gitpod +++ /dev/null @@ -1,61 +0,0 @@ -# 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/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 deleted file mode 100644 index af732e059..000000000 --- a/container/Containerfile.ubuntu +++ /dev/null @@ -1,71 +0,0 @@ -# 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 deleted file mode 100644 index 1d24de756..000000000 --- a/container/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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/run-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 parameters, 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/run-ubuntu-container.sh bash - -# Build Apache Celix -mkdir -p build -cd build -../container/support-scripts/build-all.sh -make -j - -# Run the unit tests for Apache Celix -ctest --output-on-failure -``` diff --git a/container/support-scripts/build-all.sh b/container/support-scripts/build-all.sh deleted file mode 100755 index 2e7500b2d..000000000 --- a/container/support-scripts/build-all.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/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 \ - ..