From d3dac6d12a1b296b990783405c179ff99180ad88 Mon Sep 17 00:00:00 2001 From: Marco Thaller Date: Thu, 6 Jun 2024 11:34:07 +0200 Subject: [PATCH] build: add Dockerfile + VS code dev container configuration Adds Dockerfile to provide a container running Debian with all required packages installed to build and run mecaps demo application. Adds devcontainer.json so that Dockerfile can be used as dev container in VS code. Tested with: - VS code version 1.93.1 - Docker version 27.2.1 (rootfull and rootless) https://docs.docker.com/engine/security/rootless/ on: - Debian 12 running X11 - Ubuntu 24.04.1 running X11 and Wayland --- .devcontainer/devcontainer.json | 47 +++++++++++++++++++++++++++++++ Dockerfile | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..82f0ba7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,47 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "MECAPS Dockerfile", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + "dockerfile": "../Dockerfile" + }, + + // Docker root-less Setup (use this in case your host runs root-less Docker) + // - changes container user from default user to root which maps to host user + // -> https://docs.docker.com/engine/security/rootless/#how-it-works + "containerUser": "root", + + // X11 | Wayland Setup + // - mounts UDS directory to allow for running GUIs from inside the container + // - set environment variables non-statically (using `remoteEnv` instead of `containerEnv`) + + //// X11 (use this in case your host runs X11) + "mounts": [ "source=/tmp/.X11-unix/,target=/tmp/.X11-unix/,type=bind" ], + "remoteEnv": { + "DISPLAY": "${localEnv:DISPLAY}", + "XDG_RUNTIME_DIR": "/run/user/${localEnv:UID}" + }, + + //// Wayland (use this in case your host runs Wayland) + // "mounts": [ "source=${localEnv:XDG_RUNTIME_DIR}/${localEnv:WAYLAND_DISPLAY},target=/tmp/${localEnv:WAYLAND_DISPLAY},type=bind" ], + // "remoteEnv": { + // "QT_QPA_PLATFORM": "wayland", + // "WAYLAND_DISPLAY": "${localEnv:WAYLAND_DISPLAY}", + // "XDG_RUNTIME_DIR": "/tmp" + // }, + + + "customizations": { + "vscode": { + "extensions": [ + "llvm-vs-code-extensions.vscode-clangd", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "Slint.slint", + "vadimcn.vscode-lldb" + ] + } + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..45e605c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM debian:bookworm-slim + +RUN apt-get update --quiet && \ + apt-get install --assume-yes \ + # minimal build essentials + cmake \ + curl \ + g++ \ + gdb \ + git \ + ninja-build \ + wget \ + # mecaps / kdutils specific pkgs + libcurlpp-dev \ + libmosquittopp-dev \ + libwayland-dev \ + wayland-scanner++ \ + wayland-protocols \ + # slint specific pkgs + libfontconfig-dev \ + libxcb-shape0-dev \ + libxcb-xfixes0-dev \ + libxcb-xkb-dev \ + libxkbcommon-dev \ + libxkbcommon-x11-dev \ + qtbase5-dev + +# Install slint from binary +ARG SLINT_VERSION=1.7.0 +ENV SLINT_INSTALL_DIR=/usr/src/slint +WORKDIR $SLINT_INSTALL_DIR +RUN wget --quiet -O - https://github.com/slint-ui/slint/releases/download/v$SLINT_VERSION/Slint-cpp-$SLINT_VERSION-Linux-x86_64.tar.gz | tar xvzf - --strip-components=1 + +# Set CMake prefix path +ENV CMAKE_PREFIX_PATH=$SLINT_INSTALL_DIR + +# Add non-root user and set as default user +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME + # [Optional] If you need to install software after connecting. + # && apt-get update \ + # && apt-get install -y sudo \ + # && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + # && chmod 0440 /etc/sudoers.d/$USERNAME + +USER $USERNAME