Skip to content

Commit

Permalink
Combine container build ci with devcontainer setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Jun 15, 2024
1 parent 247744a commit d28280e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 282 deletions.
32 changes: 5 additions & 27 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
33 changes: 22 additions & 11 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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.
33 changes: 19 additions & 14 deletions .devcontainer/run-dev-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -66,20 +68,27 @@ 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
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
Expand All @@ -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

Expand Down
48 changes: 34 additions & 14 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Celix development containers
name: Celix build containers

on:
push:
Expand All @@ -7,32 +7,52 @@ 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:
- name: Checkout source code
uses: actions/[email protected]
- 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:
- name: Checkout source code
uses: actions/[email protected]
- 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/[email protected]
- 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
61 changes: 0 additions & 61 deletions container/Containerfile.gitpod

This file was deleted.

71 changes: 0 additions & 71 deletions container/Containerfile.ubuntu

This file was deleted.

Loading

0 comments on commit d28280e

Please sign in to comment.