From 2417551976d13c2518208e33b5fe806c5a4a1dd7 Mon Sep 17 00:00:00 2001 From: Michael Platings Date: Wed, 17 Apr 2024 10:02:11 +0000 Subject: [PATCH] Dev container improvements * Add a readme * Base the dev Docker image on the image used in CI. * Upgrade from Bash to Zsh, with oh-my-zsh. * Move ccache directory outside the repo, to keep the repo more clean. * Use the real username of the current user. * Use real path names inside the container. * Allow using vim instead of nano. * Enable Git clone with SSH. * Install some nice-to-have command line utilities. * Install a couple of nice-to-have VSCode extensions. --- .devcontainer/Dockerfile | 36 +++++++++++++++++++ .devcontainer/README.md | 21 +++++++++++ .devcontainer/devcontainer.json | 36 ++++++++++++++----- .devcontainer/install_deps.sh | 20 ----------- .../{setup_ccache.sh => oncreate.sh} | 6 +--- .gitignore | 1 - .gitlab-ci.yml | 1 + .vscode/tasks.json | 16 +++++---- docker/Dockerfile | 7 ---- 9 files changed, 96 insertions(+), 48 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/README.md delete mode 100755 .devcontainer/install_deps.sh rename .devcontainer/{setup_ccache.sh => oncreate.sh} (52%) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..4a24d5797 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 + +# If changing this image ID, please also change it in .gitlab-ci.yml +FROM registry.gitlab.arm.com/kleidi/kleidicv:11 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ + ccache \ + clangd-${LLVM_VERSION} \ + gdb-multiarch \ + git-email \ + libemail-valid-perl \ + nano \ + openssh-client \ + qemu-user \ + ripgrep \ + sudo \ + vim \ + zsh + +# Needed to run pipx packages originally installed for the root user +RUN chmod +x /root + +# Set up directory for volume to persist data between sessions. +RUN mkdir -p /persist && chmod a+rwx /persist + +# Add a normal user with sudo rights. +# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user +ARG USERNAME +RUN useradd -s /usr/bin/zsh -m ${USERNAME} \ + && echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} \ + && chmod 0440 /etc/sudoers.d/${USERNAME} + +USER $USERNAME diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 000000000..ad4149eac --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,21 @@ + + +This folder contains configuration for a Visual Studio Code Dev Container +https://code.visualstudio.com/docs/devcontainers/containers. + +Please note that this dev container configuration is not intended to +form part of the KleidiCV product. The dev container configuration is +only provided for development convenience and is not held to the same +quality standards as the rest of KleidiCV. + +To use this Dev Container you must first log in to the Arm GitLab +Docker registry. Instructions are at +https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html +In summary: +1. In the GitLab UI create an access token. +2. Run `docker login registry.gitlab.arm.com -u FirstnameLastname` +3. Paste the access token when prompted. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index eccc12825..0b5e4ce32 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,37 +1,57 @@ { "build" : { - "dockerfile": "../docker/Dockerfile", + "dockerfile": "Dockerfile", "args": { - "USER": "vscode-user" + "USERNAME": "${localEnv:USER}" }, "options" : [ "--network=host" ] }, - "onCreateCommand" : ".devcontainer/install_deps.sh", - "postStartCommand" : ".devcontainer/setup_ccache.sh ${containerWorkspaceFolder}/.devcontainer/ccache_storage", + "onCreateCommand" : ".devcontainer/oncreate.sh", "containerEnv": { + "CCACHE_DIR": "/persist/ccache", "CMAKE_CXX_COMPILER_LAUNCHER": "ccache", - "EDITOR": "nano", + // Default editor is nano. If you prefer vim then add "export EDITOR=vim" + // to your .profile, .bash_profile, .bashrc or .zshrc then log out and log + // in again before rebuilding the dev container from scratch. + "EDITOR": "${localEnv:EDITOR:nano}", "LC_ALL": "C" }, + "mounts": [ + // Volume to persist data between sessions + "source=${localEnv:USER}-kleidicv-persist,target=/persist,type=volume" + ], "portsAttributes": { "2345": { - "label": "Qemu GDB port", + "label": "QEMU GDB port", "onAutoForward": "ignore" } }, "customizations": { "vscode": { "extensions": [ + "eamodio.gitlens", "llvm-vs-code-extensions.vscode-clangd", + "ms-azuretools.vscode-docker", "ms-vscode.cpptools", "ms-vscode.cmake-tools" - ] + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "zsh", + "terminal.integrated.profiles.linux": { + "zsh": { + "path": "zsh" + } + } + } } }, "runArgs" : [ "--network=host" ], - "remoteUser": "vscode-user" + "remoteUser": "${localEnv:USER}", + // Use real path names inside the container, instead of mapping them to /workspace. + "workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind,consistency=cached", + "workspaceFolder": "${localWorkspaceFolder}" } diff --git a/.devcontainer/install_deps.sh b/.devcontainer/install_deps.sh deleted file mode 100755 index ec1bffeed..000000000 --- a/.devcontainer/install_deps.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -# SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates -# -# SPDX-License-Identifier: Apache-2.0 - -set -exu - -sudo apt-get update -DEBIAN_FRONTEND=noninteractive sudo apt-get install --no-install-recommends -y \ - qemu-user \ - "clangd-${LLVM_VERSION}" \ - ccache \ - gdb-multiarch \ - git-email \ - libemail-valid-perl \ - nano - -# Needed to run pipx packages originally installed for the root user -sudo chmod +x /root diff --git a/.devcontainer/setup_ccache.sh b/.devcontainer/oncreate.sh similarity index 52% rename from .devcontainer/setup_ccache.sh rename to .devcontainer/oncreate.sh index f5f5b3faa..a030e25c7 100755 --- a/.devcontainer/setup_ccache.sh +++ b/.devcontainer/oncreate.sh @@ -6,8 +6,4 @@ set -exu -CCACHE_CACHE_DIR=$1 - -mkdir -p "${CCACHE_CACHE_DIR}" -mkdir -p "${HOME}/.ccache" -echo "cache_dir = ${CCACHE_CACHE_DIR}" > "${HOME}/.ccache/ccache.conf" +sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" "" --unattended diff --git a/.gitignore b/.gitignore index 5c6996fbc..d87d84493 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ build/ public/ -.devcontainer/ccache_storage diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 53697f3bc..51cc45f45 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 +# If changing this image ID, please also change it in .devcontainer/Dockerfile image: registry.gitlab.arm.com/kleidi/kleidicv:11 # Only run CI for main branch & merge requests diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3e6b35632..b8abcae7c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,7 +5,7 @@ "label": "Build KleidiCV", "type": "shell", "command": "${workspaceFolder}/scripts/build.sh", - "problemMatcher" :"$gcc", + "problemMatcher": "$gcc", "args": [ "kleidicv-test" ], @@ -25,14 +25,14 @@ "label": "Build KleidiCV for debug", "type": "shell", "command": "${workspaceFolder}/scripts/build.sh", - "problemMatcher" :"$gcc", + "problemMatcher": "$gcc", "args": [ "kleidicv-test" ], "options": { "env": { - "BUILD_ID" : "kleidicv-debug", - "CMAKE_BUILD_TYPE" : "Debug", + "BUILD_ID": "kleidicv-debug", + "CMAKE_BUILD_TYPE": "Debug", "CMAKE_CXX_FLAGS": "--target=aarch64-linux-gnu", "CMAKE_EXE_LINKER_FLAGS": "--rtlib=compiler-rt -static -fuse-ld=lld", "EXTRA_CMAKE_ARGS": "-DKLEIDICV_ENABLE_SVE2=ON -DKLEIDICV_ENABLE_SVE2_SELECTIVELY=OFF" @@ -51,7 +51,7 @@ { "label": "Clean ccache cache", "type": "shell", - "command": "rm -rf ${workspaceFolder}/.devcontainer/ccache_storage/*", + "command": "rm -rf $CCACHE_DIR", "problemMatcher": [] }, { @@ -181,7 +181,7 @@ "type": "shell", "command": "${workspaceFolder}/.devcontainer/disassemble.sh", "args": [ - "${relativeFile}", + "${relativeFile}" ], "options": { "cwd": "${workspaceFolder}" @@ -198,7 +198,9 @@ "options": { "cwd": "${workspaceFolder}" }, - "problemMatcher": ["$gcc"] + "problemMatcher": [ + "$gcc" + ] } ], "options": { diff --git a/docker/Dockerfile b/docker/Dockerfile index 080b3436c..dbde77284 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -70,10 +70,3 @@ RUN wget \ RUN wget \ https://github.com/opencv/opencv_extra/archive/refs/tags/${OPENCV_VERSION}.tar.gz \ -O /opt/opencv-extra-${OPENCV_VERSION}.tar.gz - -# Add a normal user with sudo rights, can be useful for developement purposes -ARG USER=user -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install sudo -RUN useradd -s /usr/bin/bash -m ${USER} \ - && echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER} -- GitLab