Skip to content

Commit

Permalink
Refactor Containerfile to build and dev with non root user
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Jun 10, 2024
1 parent 6f45fb6 commit 3ceb3c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
48 changes: 24 additions & 24 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Apache Celix Dev Container",
"build": {
"dockerfile": "Containerfile",
"target": "develop"
"target": "conan-develop"
},
"runArgs" : [
"--userns=keep-id"
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/setup-apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

0 comments on commit 3ceb3c5

Please sign in to comment.