From: Mark Jonas <
toe...@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.
Suggested-by: Ayoub Zaki <
ayoub...@embetrix.com>
Signed-off-by: Mark Jonas <
toe...@gmail.com>
---
.devcontainer/Dockerfile | 33 +++++++++++++++++++++++++++++++++
.devcontainer/devcontainer.json | 13 +++++++++++++
.gitignore | 3 +++
DevContainer.md | 26 ++++++++++++++++++++++++++
4 files changed, 75 insertions(+)
create mode 100644 .devcontainer/Dockerfile
create mode 100644 .devcontainer/devcontainer.json
create mode 100644 DevContainer.md
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 00000000..e0f6d84e
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,33 @@
+# SPDX-FileCopyrightText: 2024 Mark Jonas <
toe...@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+FROM ubuntu:24.04
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+# Dummy uid/gid for devuser; will be changed at devcontainer startup
+ARG USER_UID=1234
+ARG USER_GID=1234
+ARG USER_SHELL=/bin/bash
+ARG USERNAME=devuser
+
+# Remove ubuntu user to free up uid:gid 1000:1000
+RUN userdel -r ubuntu || true
+
+RUN groupadd --gid ${USER_GID} ${USERNAME} && \
+ useradd --shell ${USER_SHELL} --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME}
+
+RUN apt-get update
+
+# Allow devuser to execute any command as root without password prompt
+RUN apt-get -y install --no-install-recommends sudo && \
+ echo "${USERNAME} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} && \
+ chmod 0440 /etc/sudoers.d/${USERNAME}
+
+# Install SWUpdate build dependencies
+COPY ./ci/setup.sh /tmp
+RUN chmod +x /tmp/setup.sh && /tmp/setup.sh
+
+USER ${USERNAME}
+WORKDIR /home/${USERNAME}
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..9935f7e2
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,13 @@
+// SPDX-FileCopyrightText: 2024 Mark Jonas <
toe...@gmail.com>
+//
+// SPDX-License-Identifier: MIT
+
+{
+ "name": "SWUpdate Development Container",
+ "build": {
+ "dockerfile": "Dockerfile",
+ "context": ".."
+ },
+ "remoteUser": "devuser",
+ "updateRemoteUserUID": true
+}
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..c8c81e7a
--- /dev/null
+++ b/DevContainer.md
@@ -0,0 +1,26 @@
+<!--
+SPDX-FileCopyrightText: 2024 Mark Jonas <
toe...@gmail.com>
+
+SPDX-License-Identifier: MIT
+-->
+
+# Introduction
+The SWUpdate devcontainer is a Docker-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 supports compiling and running SWUpdate for x86-64 targets.
+
+# Usage
+## Compile and run tests
+You can compile and run all SWUpdate tests inside the devcontainer. This is very
+helpful during development and highly recommend before sending a patch to the
+mailing list.
+
+To compile and run all SWUpdate tests, execute the following command using a
+devcontainer terminal.
+
+```
+ci/test-configs.sh
+```
--
2.43.0