diff mbox series

[v3,1/1] Add minimal devcontainer

Message ID 20250106170037.96407-2-toertel@gmail.com
State New
Delegated to: Stefano Babic
Headers show
Series Add minimal devcontainer | expand

Commit Message

Mark Jonas Jan. 6, 2025, 5 p.m. UTC
From: Mark Jonas <toertel@gmail.com>

The devcontainer can build and run all SWUpdate tests for x86-64
targets. It uses ci/setup.sh to install the required build dependencies.

The devcontainer must be run unprivileged. Thus, the root user inside
will read and write outside files with the uid and gid of the user who
started the container. This cannot be done using Docker but requires
Podman. Because of this the default container service of VS Code must be
switched from Docker to Podman.

Suggested-by: Ayoub Zaki <ayoub.zaki@embetrix.com>
Suggested-by: Daniel Braunwarth <oss@braunwarth.dev>
Signed-off-by: Mark Jonas <toertel@gmail.com>
---
 .devcontainer/Containerfile     | 11 +++++++
 .devcontainer/devcontainer.json | 11 +++++++
 .gitignore                      |  3 ++
 DevContainer.md                 | 58 +++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+)
 create mode 100644 .devcontainer/Containerfile
 create mode 100644 .devcontainer/devcontainer.json
 create mode 100644 DevContainer.md
diff mbox series

Patch

diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile
new file mode 100644
index 00000000..0347971b
--- /dev/null
+++ b/.devcontainer/Containerfile
@@ -0,0 +1,11 @@ 
+# SPDX-FileCopyrightText: 2024-2025 Mark Jonas <toertel@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+FROM ubuntu:24.04
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+# Install SWUpdate build dependencies
+COPY ./ci/setup.sh /tmp
+RUN chmod +x /tmp/setup.sh && /tmp/setup.sh
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..082e304c
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,11 @@ 
+// SPDX-FileCopyrightText: 2024-2025 Mark Jonas <toertel@gmail.com>
+//
+// SPDX-License-Identifier: MIT
+
+{
+    "name": "SWUpdate Development Container",
+    "build": {
+        "dockerfile": "Containerfile",
+        "context": ".."
+    }
+}
diff --git a/.gitignore b/.gitignore
index 4755ff07..24e9a38e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,6 +127,9 @@  web-app/swupdate-www.tar.gz
 !.gitlab-ci.yml
 !.github
 
+# devcontainer
+!.devcontainer/
+
 # swupdateclient
 Pipfile
 Pipfile.lock
diff --git a/DevContainer.md b/DevContainer.md
new file mode 100644
index 00000000..dac6a26d
--- /dev/null
+++ b/DevContainer.md
@@ -0,0 +1,58 @@ 
+<!--
+SPDX-FileCopyrightText: 2024-2025 Mark Jonas <toertel@gmail.com>
+
+SPDX-License-Identifier: MIT
+-->
+
+# Introduction
+
+The SWUpdate devcontainer is a Podman-based development environment that
+ensures consistent tooling and settings across different machines. It uses
+configuration files to specify the environment setup and automatically builds
+the required development workspace when opened in compatible IDEs like VS Code.
+
+The devcontainer requires Podman because it expects to be run unprivileged.
+That is, the root user inside the container is expected to read and write
+files with the uid and gid of the user who started the container.
+
+The devcontainer supports compiling and running SWUpdate for x86-64 targets.
+
+# Setup
+
+## VS Code
+
+You have to use *Podman* instead of *Docker* by adding the following to the
+VS Code user settings. Please note that changing this setting might break other
+devcontainers you are using which explicitly require Docker. [^1]
+
+[^1]: It is an open backlog item of VS Code to change *dev.containers.dockerPath*
+into a workspace setting. See https://github.com/microsoft/vscode-remote-release/issues/8817
+
+```json
+"dev.containers.dockerPath": "podman"
+```
+
+You can change that setting either in VS Code itself (press `Ctrl+,`) or in
+the configuration file. VS Code user settings are stored in a *settings.json*
+file, with different locations depending on your operating system:
+
+**Linux**: `$HOME/.config/Code/User/settings.json`
+
+**macOS**: `$HOME/Library/Application Support/Code/User/settings.json`
+
+**Windows**: `%APPDATA%\Code\User\settings.json`
+
+# Usage
+
+## Compile and run tests
+
+You can compile and run all SWUpdate tests inside the devcontainer. This is very
+helpful during development and highly recommended before sending a patch to the
+mailing list.
+
+To compile and run all SWUpdate tests, execute the following command using a
+devcontainer terminal.
+
+```sh
+ci/test-configs.sh
+```