From 70922c93f894ad28bfb36ffbb3dc4573f8e4bf08 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Tue, 11 Jun 2024 20:10:32 +0000 Subject: [PATCH] Update devcontainer setup for gpg --- .devcontainer/Containerfile | 41 +++++-- .../build-container-images.sh | 0 ...d-conan.sh => build-project-with-conan.sh} | 0 .devcontainer/devcontainer.json | 6 +- .devcontainer/run-dev-container.sh | 109 ++++++++++++++++++ ...setup-apt.sh => setup-project-with-apt.sh} | 0 ...p-conan.sh => setup-project-with-conan.sh} | 0 container/run-ubuntu-container.sh | 47 -------- 8 files changed, 145 insertions(+), 58 deletions(-) rename container/build-ubuntu-container.sh => .devcontainer/build-container-images.sh (100%) rename .devcontainer/{build-conan.sh => build-project-with-conan.sh} (100%) create mode 100755 .devcontainer/run-dev-container.sh rename .devcontainer/{setup-apt.sh => setup-project-with-apt.sh} (100%) rename .devcontainer/{setup-conan.sh => setup-project-with-conan.sh} (100%) delete mode 100755 container/run-ubuntu-container.sh diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile index f783456cc..8b95e0e70 100644 --- a/.devcontainer/Containerfile +++ b/.devcontainer/Containerfile @@ -74,18 +74,43 @@ RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \ sudo apt-get clean -ARG DEVELOP_PACKAGES="dos2unix git locales-all rsync tar ssh tzdata sudo vim" -FROM conan-build as conan-develop +#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 -RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \ - DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends $DEVELOP_PACKAGES && \ +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 -FROM apt-build as apt-develop + #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 DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \ - DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends $DEVELOP_PACKAGES && \ - sudo apt-get clean +RUN ${APT_INSTALL} + +#Setup sshd +RUN ${SSHD_INSTALL} diff --git a/container/build-ubuntu-container.sh b/.devcontainer/build-container-images.sh similarity index 100% rename from container/build-ubuntu-container.sh rename to .devcontainer/build-container-images.sh diff --git a/.devcontainer/build-conan.sh b/.devcontainer/build-project-with-conan.sh similarity index 100% rename from .devcontainer/build-conan.sh rename to .devcontainer/build-project-with-conan.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cbad0a422..e3a99b055 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,11 +2,11 @@ "name": "Apache Celix Dev Container", "build": { "dockerfile": "Containerfile", - "target": "conan-develop" + "target": "conan-dev" }, "runArgs" : [ "--userns=keep-id" ], - "onCreateCommand": "sh .devcontainer/setup-conan.sh", - "postCreateCommand": "sh .devcontainer/build-conan.sh" + "onCreateCommand": "sh .devcontainer/setup-project-with-conan.sh", + "postCreateCommand": "sh .devcontainer/build-project-with-conan.sh" } diff --git a/.devcontainer/run-dev-container.sh b/.devcontainer/run-dev-container.sh new file mode 100755 index 000000000..39ea6a799 --- /dev/null +++ b/.devcontainer/run-dev-container.sh @@ -0,0 +1,109 @@ +#!/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="sudo /usr/sbin/sshd -D -e -p 2233" +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 + +# Check if container celix-dev already exists +if [ "$(${CONTAINER_ENGINE} ps -a --format '{{.Names}}' | grep celix-dev)" ]; then + echo "Container 'celix-dev' already exists. Do you want to remove it?" + select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Removing container celix-dev"; ${CONTAINER_ENGINE} rm -f celix-dev; break;; + No ) exit;; + esac + done + echo "" +fi + +ADDITIONAL_ARGS="" +echo "Do you want to mount the .ssh directory to the container (as an overlayfs)?" +select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Add .ssh directory mount arguments"; ADDITIONAL_ARGS="--volume ${HOME}/.ssh:/home/celixdev/.ssh:O"; break;; + No ) break;; + esac +done +echo "" + +if [ -e "${HOME}/.gnupg" ]; then + echo "Do you want to mount the .gnupg directory to the container (as an overlayfs)?" + select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Add .gnupg directory mount arguments"; ADDITIONAL_ARGS="--volume ${HOME}/.gnupg:/home/celixdev/.gnupg:O"; break;; + No ) break;; + esac + done + echo "" +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 +# --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 'celix-dev' with command: ${CONTAINER_COMMAND}" +${CONTAINER_ENGINE} run -it --rm --privileged -d \ + --name celix-dev \ + --userns keep-id \ + --net=host \ + ${ADDITIONAL_ARGS} \ + --volume "${CELIX_REPO_ROOT}":"${CELIX_REPO_ROOT}" \ + --workdir "${CELIX_REPO_ROOT}" \ + --security-opt label=disable \ + apache/celix-conan-dev:latest bash -c "${CONTAINER_COMMAND}" +echo "" + +echo "Do you want to setup the git user and email in the container?" +USER_NAME=$(git config user.name) +USER_EMAIL=$(git config user.email) +select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Setting up git user and email"; ${CONTAINER_ENGINE} exec celix-dev bash -c "git config --global user.email '${USER_EMAIL}' && git config --global user.name '${USER_NAME}'"; break;; + No ) break;; + esac +done +echo "" + +echo "Do you want to copy the ssh key to the container?" +select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Copying ssh key (password: celixdev)"; ssh-copy-id -p 2233 celixdev@localhost; break;; + No ) break;; + esac +done +echo "" + +echo "Done." diff --git a/.devcontainer/setup-apt.sh b/.devcontainer/setup-project-with-apt.sh similarity index 100% rename from .devcontainer/setup-apt.sh rename to .devcontainer/setup-project-with-apt.sh diff --git a/.devcontainer/setup-conan.sh b/.devcontainer/setup-project-with-conan.sh similarity index 100% rename from .devcontainer/setup-conan.sh rename to .devcontainer/setup-project-with-conan.sh diff --git a/container/run-ubuntu-container.sh b/container/run-ubuntu-container.sh deleted file mode 100755 index 998b8c1cb..000000000 --- a/container/run-ubuntu-container.sh +++ /dev/null @@ -1,47 +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. -# -# 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 bash -c "${CONTAINER_COMMAND}"