From 3ceb3c5af789103f981262d8d1c0b3dbc2d874da Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Mon, 10 Jun 2024 20:20:21 +0200 Subject: [PATCH] Refactor Containerfile to build and dev with non root user --- .devcontainer/Containerfile | 48 ++++++++++++++++----------------- .devcontainer/devcontainer.json | 2 +- .devcontainer/setup-apt.sh | 3 +++ 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile index cadef87a8..f783456cc 100644 --- a/.devcontainer/Containerfile +++ b/.devcontainer/Containerfile @@ -32,15 +32,23 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \ make \ ninja-build \ lcov \ + sudo \ python3 \ python3-pip && \ apt-get clean +# Add user celixdev with sudo rights and a "celixdev" password +RUN useradd -m -s /bin/bash -G sudo celixdev && \ + echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \ + echo "celixdev:celixdev" | chpasswd +USER celixdev +WORKDIR /home/celixdev + # Build image using conan & cmake FROM build as conan-build # Install conan -RUN pip3 install conan && pip3 cache purge +RUN sudo pip3 install conan && pip3 cache purge # Setup conan profile RUN conan profile detect @@ -49,8 +57,8 @@ RUN conan profile detect FROM build as apt-build # Install celix dependencies -RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \ - DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ +RUN DEBIAN_FRONTEND="noninteractive" sudo apt-get update && \ + DEBIAN_FRONTEND="noninteractive" sudo apt-get install -y --no-install-recommends \ civetweb \ libavahi-compat-libdnssd-dev \ libcivetweb-dev \ @@ -63,29 +71,21 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get update && \ libzip-dev \ rapidjson-dev \ uuid-dev && \ - apt-get clean + sudo apt-get clean + + +ARG DEVELOP_PACKAGES="dos2unix git locales-all rsync tar ssh tzdata sudo vim" -FROM conan-build as develop +FROM conan-build as conan-develop #Install development 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 \ - sudo \ - vim && \ - apt-get clean +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 -# Add user celixdev with sudo rights and a "celixdev" password -RUN useradd -m -s /bin/bash -G sudo celixdev -RUN echo "celixdev:celixdev" | chpasswd -USER celixdev +FROM apt-build as apt-develop -# Setup conan profile for user celixdev -RUN conan profile detect +#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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 790e642df..cbad0a422 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "name": "Apache Celix Dev Container", "build": { "dockerfile": "Containerfile", - "target": "develop" + "target": "conan-develop" }, "runArgs" : [ "--userns=keep-id" diff --git a/.devcontainer/setup-apt.sh b/.devcontainer/setup-apt.sh index 6ee40756c..403fb7379 100755 --- a/.devcontainer/setup-apt.sh +++ b/.devcontainer/setup-apt.sh @@ -23,6 +23,7 @@ LC_BUILD_TYPE=$(echo ${BUILD_TYPE} | tr '[:upper:]' '[:lower:]') mkdir -p cmake-build-${LC_BUILD_TYPE} cmake -S . \ + -G Ninja \ -B cmake-build-${LC_BUILD_TYPE} \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_INSTALL_PREFIX=/tmp/celix-install \ @@ -31,3 +32,5 @@ cmake -S . \ -DRSA_JSON_RPC=ON \ -DRSA_SHM=ON \ -DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON + +cmake --build cmake-build-${LC_BUILD_TYPE} --parallel