From 7e1939d7726f4942c65b0668692a12b0dd80b0a6 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 08:04:22 +0000 Subject: [PATCH 1/9] Added Docker environment for easy setup --- .gitignore | 1 + Docker | 1 + 2 files changed, 2 insertions(+) create mode 160000 Docker diff --git a/.gitignore b/.gitignore index 57fce96f..b8ac92c7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Gemfile.lock *.swp examples/make_example/build examples/temp_sensor/build +Docker/.env diff --git a/Docker b/Docker new file mode 160000 index 00000000..f208e73c --- /dev/null +++ b/Docker @@ -0,0 +1 @@ +Subproject commit f208e73c2ef0955794352e965f8da940b81262da From c9f2a61b6c5e326d374d8b6ec688001dc42d19ce Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 08:14:20 +0000 Subject: [PATCH 2/9] Added Docker environment for easy setup --- Docker | 1 - docker/README.md | 30 +++++ docker/Resources/.clang-format | 188 ++++++++++++++++++++++++++++ docker/Resources/Dockerfile | 112 +++++++++++++++++ docker/Resources/fish-starship.fish | 9 ++ docker/Resources/init.sh | 32 +++++ docker/Resources/logging.sh | 49 ++++++++ docker/Resources/starship.toml | 28 +++++ docker/Resources/vim/.vimrc | 5 + docker/Resources/vim/lsp.vim | 12 ++ docker/Resources/vim/mappings.vim | 6 + docker/Resources/vim/plugins.vim | 13 ++ docker/Resources/vim/ui.vim | 14 +++ docker/attach.sh | 18 +++ docker/run.sh | 30 +++++ docker/setup.sh | 37 ++++++ 16 files changed, 583 insertions(+), 1 deletion(-) delete mode 160000 Docker create mode 100644 docker/README.md create mode 100644 docker/Resources/.clang-format create mode 100644 docker/Resources/Dockerfile create mode 100644 docker/Resources/fish-starship.fish create mode 100644 docker/Resources/init.sh create mode 100644 docker/Resources/logging.sh create mode 100644 docker/Resources/starship.toml create mode 100644 docker/Resources/vim/.vimrc create mode 100644 docker/Resources/vim/lsp.vim create mode 100644 docker/Resources/vim/mappings.vim create mode 100644 docker/Resources/vim/plugins.vim create mode 100644 docker/Resources/vim/ui.vim create mode 100755 docker/attach.sh create mode 100755 docker/run.sh create mode 100755 docker/setup.sh diff --git a/Docker b/Docker deleted file mode 160000 index f208e73c..00000000 --- a/Docker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f208e73c2ef0955794352e965f8da940b81262da diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..e3c60932 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,30 @@ +# CMock Docker environment for development + +A Docker-based virtual development environment based on Arch. The container uses SSH keys from the host OS, loaded as Read-only when starting the container (executing `./run.sh`), allowing to use host OS SSH authentication. Keys are not persistent in the image, and are only injected when starting the container. The only persistent things in the image is the workspace and the configuration scripts placed inside the image during building. The environment comes with pre-configured Vim with Clangd support. The `run.sh` is configured to clean up the container when you call `exit` from inside, to avoid any hanging running containers. The container does not affect any files or settings on your host OS. + +# Instruction + +1. Install Docker for your host OS; + +2. Generate your SSH keys on the host OS if you don't have any yet, and add them in your GitHub account settings to be able to contribute; + +3. Fork the CMock repository, so that the Docker environment can resolve it from your GitHub and clone the fork into the workspace during first run. + +4. Create `.env` file locally in your cloned repository, with `GIT_USER_NAME` and `GIT_USER_EMAIL` variables set; + Example: + ``` + // .env + GIT_USER_NAME=TheJourneymansGuide + GIT_USER_EMAIL=k.woj.coding@gmail.com + ``` + This allows `git` inside the container to resolve your fork of the CMock repo, and to know what user name and e-mail to use when you commit something; + +5. Run `./setup.sh` - this will create a docker volume for workspace persistance on your local machine, and will create the environment image; + +6. Run `./run.sh` - this will start the image. If the CMock repository is not present in workspace, it will automatically get cloned during the first start. + +7. \* If you would like to attach to the container with a second terminal, the `attach.sh` script will automatically resolve your current cmock-dev-arch instance and connect to it (executed as: `./attach.sh`); + +> __IMPORTANT__: Be careful when you run multiple terminals in the same container. If you close the 'root' terminal that started the container, it will kill the container and subsequently disconnect all the other terminals from it. + +> __NOTE__: Make sure you have Unicode-compliant font to enable the fish terminal to display symbols instead of rectangles. Example fonts are `Fira Code` and `Cascadia Code`. diff --git a/docker/Resources/.clang-format b/docker/Resources/.clang-format new file mode 100644 index 00000000..e20c9b02 --- /dev/null +++ b/docker/Resources/.clang-format @@ -0,0 +1,188 @@ +BasedOnStyle: Mozilla + +IndentWidth: 4 +ColumnLimit: 120 +TabWidth: 4 +UseTab: Never +AlignAfterOpenBracket: true +AlignArrayOfStructures: Right +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + AlignCompound: true + AlignFunctionDeclarations: true + AlignFunctionPointers: true + PadOperators: true +AlignConsecutiveBitFields: AcrossComments +AlignConsecutiveDeclarations: AcrossComments +AlignConsecutiveMacros: AcrossComments +AlignConsecutiveShortCaseStatements: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true + AlignCaseArrows: true + AlignCaseColons: true +AlignEscapedNewlines: LeftWithLastLine +AlignOperands: BreakBeforeBinaryOperators +AlignTrailingComments: + Kind: Always + OverEmptyLines: 1 + MaxEmptyLinesToKeep: 1 + AlignPPAndNotPP: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakBeforeMultilineStrings: true +BinPackArguments: false +BinPackLongBracedList: true +BinPackParameters: OnePerLine +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BracedInitializerIndentWidth: 4 +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterReturnType: ExceptShortType +BreakArrays: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeCloseBracketBracedList: true +BreakBeforeCloseBracketFunction: false +BreakBeforeCloseBracketIf: false +BreakBeforeCloseBracketLoop: false +BreakBeforeCloseBracketSwitch: false +BreakBeforeInlineASMColon: Always +BreakBeforeTernaryOperators: true +BreakBinaryOperations: RespectPrecedence +BreakFunctionDefinitionParameters: false +BreakStringLiterals: true +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: Block +DerivePointerAlignment: false +EnumTrailingComma: Remove +ExperimentalAutoDetectBinPacking: false +IncludeBlocksStyle: Merge +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: false +IndentPPDirectives: BeforeHash +IndentWrappedFunctionNames: true +InsertBraces: true +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: -1 + Decimal: 3 + DecimalMinDigitsInsert: 5 + DecimalMaxDigitsRemove: 4 + Hex: 2 + HexMinDigitsInsert: 5 + HexMaxDigitsRemove: 4 +KeepEmptyLines: + AtEndOfFile: true + AtStartOfBlock: false + AtStartOfFile: false +LineEnding: LF +MaxEmptyLinesToKeep: 1 +NumericLiteralCase: + ExponentLetter: Lower + HexDigit: Upper + Prefix: Lower + Suffix: Lower +OneLineFormatOffRegex: ^(// NOLINT) +PPIndentWidth: 4 +PointerAlignment: Left +QualifierAlignment: Left +QualifierOrder: [friend, inline, static, const, constexpr, volatile, type] +ReflowComments: Always +RemoveBracesLLVM: false +RemoveEmptyLinesInUnwrappedLines: true +RemoveParentheses: Leave +RemoveSemicolon: true +SeparateDefinitionBlocks: Always +SkipMacroDefinitionBody: false +SortIncludes: + Enabled: true + IgnoreCase: true + IgnoreExtension: true +SpaceAfterLogicalNot: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeParens: Never +SpaceBeforeSquareBrackets: false +SpaceInEmptyBraces: false +SpaceBeforeTrailingComments: 3 +SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: 1 +SpacesInParens: Never +SpacesInSquareBrackets: false +Standard: Latest + +--- +Language: Cpp +AccessModifierOffset: -4 +AllowBreakBeforeNoexceptSpecifier: Never +AllowBreakBeforeQtProperty: true +AllowShortCompoundRequirementOnASingleLine: true +AllowShortLambdasOnASingleLine: Empty +AllowShortNamespacesOnASingleLine: false +BreakBeforeConceptDeclarations: Always +BreakBeforeTemplateCloser: false +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakTemplateDeclarations: Yes +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +FixNamespaceComments: true +IndentAccessModifiers: false +IndentExportBlock: true +IndentRequiresClause: true +LambdaBodyIndentation: Signature +NamespaceIndentation: All +PackConstructorInitializers: CurrentLine +ReferenceAlignment: Left +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +ShortNamespaceLines: 0 +SortUsingDeclarations: Lexicographic +SpaceAfterOperatorKeyword: false +SpaceAfterTemplateKeyword: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeRangeBasedForLoopColon: true +SpacesInAngles: Never +WrapNamespaceBodyWithEmptyLines: Never + +--- +Language: C +IndentGotoLabels: false +SpaceAfterCStyleCast: true diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile new file mode 100644 index 00000000..8d9b06cb --- /dev/null +++ b/docker/Resources/Dockerfile @@ -0,0 +1,112 @@ +#syntax=docker/dockerfile:1.6 + +FROM archlinux:latest + +# Set the locale +ENV TERM=xterm-256color +ENV STARSHIP_CONFIG=/etc/starship/starship.toml + +# Install basic dependencies for the system +RUN pacman -Syu --noconfirm && \ + pacman -S --noconfirm \ + glibc \ + base \ + base-devel \ + sudo \ + bash + +ENV PATH="/usr/bin:$PATH" + +RUN pacman -Syu --noconfirm \ + git \ + curl \ + wget + +RUN pacman -Syu --noconfirm \ + openssh \ + ca-certificates \ + zip \ + unzip \ + vim \ + tree + +RUN pacman -Syu --noconfirm \ + fish \ + starship \ + noto-fonts \ + noto-fonts-emoji \ + fzf \ + ripgrep \ + fd \ + universal-ctags + +# Create dev user +ARG USERNAME=Dev +ARG UID=1000 +ARG GID=1000 + +RUN groupadd -g ${GID} ${USERNAME} && \ + useradd -m -u ${UID} -g ${GID} -s /usr/bin/fish ${USERNAME} + +RUN echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USERNAME} && \ + chmod 0440 /etc/sudoers.d/${USERNAME} + +# Install development dependencies +RUN pacman -Syu --noconfirm \ + make \ + cmake \ + ninja + +RUN pacman -Syu --noconfirm \ + bash-language-server \ + fzf + +RUN pacman -Syu --noconfirm \ + llvm \ + clang \ + clang-tools-extra + +RUN pacman -Syu --noconfirm \ + gdb \ + valgrind \ + gtest + + +RUN pacman -Syu --noconfirm \ + ruby \ + ruby-irb \ + ruby-rake \ + ruby-bundler + +USER ${USERNAME} +ENV HOME=/home/Dev + +# Install Vim cofiguration +RUN sudo mkdir -p /usr/share/vim/vimfiles/autoload && \ + sudo curl -fLo /usr/share/vim/vimfiles/autoload/plug.vim \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + +COPY Resources/vim /home/Dev/.vim +COPY Resources/vim/.vimrc /home/Dev/.vimrc +RUN vim +'PlugInstall --sync' +qa + +# Copy and execute configuration scripts +RUN sudo mkdir -p /etc/fish/conf.d +RUN sudo mkdir -p /opt/container-scripts + +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +COPY Resources/init.sh /opt/container-scripts/init.sh +COPY Resources/logging.sh /opt/container-scripts/logging.sh +COPY Resources/fish-starship.fish /etc/fish/conf.d/starship.fish +COPY Resources/starship.toml /etc/starship/starship.toml + +RUN sudo chmod +x /opt/container-scripts/init.sh + +# Copy clang-format configuration +COPY Resources/.clang-format /etc/clang-format/.clang-format + +# Configure the entrypoint +WORKDIR /workspace +ENTRYPOINT ["/usr/bin/fish", "-lc", "/opt/container-scripts/init.sh; exec fish"] diff --git a/docker/Resources/fish-starship.fish b/docker/Resources/fish-starship.fish new file mode 100644 index 00000000..cc6e292f --- /dev/null +++ b/docker/Resources/fish-starship.fish @@ -0,0 +1,9 @@ +if status --is-interactive + starship init fish | source +end + +set -gx STARSHIP_LOG error +set -gx EDITOR nvim + +set -gx LANG C.UTF-8 +set -gx LC_ALL C.UTF-8 diff --git a/docker/Resources/init.sh b/docker/Resources/init.sh new file mode 100644 index 00000000..4dcd5211 --- /dev/null +++ b/docker/Resources/init.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +source "$SCRIPT_DIR/logging.sh" + +section "Running container initialization.." + +if [[ -n "${GIT_USER_NAME:-}" ]]; then + git config --global user.name "$GIT_USER_NAME" +fi + +if [[ -n "${GIT_USER_EMAIL:-}" ]]; then + git config --global user.email "$GIT_USER_EMAIL" +fi + +git config --global credential.helper 'cache --timeout=36000' + +section "Git config inside container:" +log "User name: $(git config --global --get user.name || "(user.name not set)")" +log "User email: $(git config --global --get user.email || "(user.email not set)")" + +section "Searching for CMock forked repository" + +REPO_PATH=$(find -iname "CMock") + +if [[ -z $REPO_PATH ]]; then + git clone git@github.com:$GIT_USER_NAME/CMock.git +fi + +echo; diff --git a/docker/Resources/logging.sh b/docker/Resources/logging.sh new file mode 100644 index 00000000..aaa9161b --- /dev/null +++ b/docker/Resources/logging.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +[[ -n "${__LOGGING_SH_LOADED:-}" ]] && return +__LOGGING_SH_LOADED=1 + +set -o pipefail + +if [[ -t 1 ]]; then + RED='\033[0;31m' + GREEN='\033[0;92m' + YELLOW='\033[1;33m' + BLUE='\033[0;34m' + MAGENTA='\033[0;35m' + LIGHT_RED='\033[0;91m' + CYAN='\033[0;36m' + BOLD='\033[1m' + DIM='\033[2m' + RESET='\033[0m' + LIGHT_CYAN='\033[0;96m' + LIGHT_YELLOW='\033[0;93m' +else + RED='' + GREEN='' + YELLOW='' + BLUE='' + MAGENTA='' + LIGHT_RED='' + CYAN='' + BOLD='' + DIM='' + RESET='' + LIGHT_CYAN='' + LIGHT_YELL0W='' +fi + +section() { echo -e "${BOLD}${LIGHT_RED} ==> ${RESET}$*"; } +log() { echo -e "${LIGHT_CYAN} [\u2139]${RESET} $*"; } +success() { echo -e "${LIGHT_CYAN} [\u2714]${RESET} $*\n"; } +warn() { echo -e "${YELLOW} [\u26A0]${RESET} $*"; } +error() { echo -e "${RED} [\u2716]${RESET} $*" >&2; } + +run() { + log "$*" + "$0" +} + +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + trap 'error "Command failed at line ${BASH_LINENO[0]}"' ERR +fi diff --git a/docker/Resources/starship.toml b/docker/Resources/starship.toml new file mode 100644 index 00000000..0a701b1b --- /dev/null +++ b/docker/Resources/starship.toml @@ -0,0 +1,28 @@ +add_newline = true + +[username] +format = " [\\u256D\\u2500$user]($style)@" +style_user = "bold red" +show_always = true + +[hostname] +format = "[$hostname]($style) in " +style = "bold dimmed red" + +[directory] +style = "purple" +truncate_to_repo = true + +[git_branch] +style = "bold cyan" + +[git_status] +style = "white" + +[cmd_duration] +format = " took [$duration]($style)" + +[character] +success_symbol = " [\\u2570\\u2500\\u03BB](bold red)" +error_symbol = " [\\u0D7](bold red)" +use_symbol_for_status = true diff --git a/docker/Resources/vim/.vimrc b/docker/Resources/vim/.vimrc new file mode 100644 index 00000000..69edbbd9 --- /dev/null +++ b/docker/Resources/vim/.vimrc @@ -0,0 +1,5 @@ +source ~/.vim/plugins.vim +source ~/.vim/ui.vim +source ~/.vim/mappings.vim +source ~/.vim/format.vim +source ~/.vim/lsp.vim diff --git a/docker/Resources/vim/lsp.vim b/docker/Resources/vim/lsp.vim new file mode 100644 index 00000000..ca3a1af4 --- /dev/null +++ b/docker/Resources/vim/lsp.vim @@ -0,0 +1,12 @@ +if executable('clangd') + au User lsp_setup call lsp#register_server({ + \ 'name': 'clangd' + \ 'cmd': {server_info->['clangd']}, + \ 'whitelist': ['c', 'cpp'], + \ }) +endif + +nnoremap gd :LspDefinition +nnoremap gr :LspReferences +nnoremap gi :LspImplementation +nnoremap K :LspHover diff --git a/docker/Resources/vim/mappings.vim b/docker/Resources/vim/mappings.vim new file mode 100644 index 00000000..d5a53cbb --- /dev/null +++ b/docker/Resources/vim/mappings.vim @@ -0,0 +1,6 @@ +nnoremap :Files +nnoremap :Buffers + +if executable($SHELL) + nnoremap t :vsplit | terminal fish +endif diff --git a/docker/Resources/vim/plugins.vim b/docker/Resources/vim/plugins.vim new file mode 100644 index 00000000..116d5d78 --- /dev/null +++ b/docker/Resources/vim/plugins.vim @@ -0,0 +1,13 @@ +call plug#begin('/home/Dev/.vim/plugged') + +" LSP +Plug 'prabirshrestha/vim-lsp' +Plug 'mattn/vim-lsp-settings' + +" Fuzzy finder +Plug 'junegunn/fzf.vim' + +" Language support +Plug 'sheerun/vim-polyglot' + +call plug#end() diff --git a/docker/Resources/vim/ui.vim b/docker/Resources/vim/ui.vim new file mode 100644 index 00000000..0d3be9ec --- /dev/null +++ b/docker/Resources/vim/ui.vim @@ -0,0 +1,14 @@ +set number +set relativenumber +set colorcolumn=120 +set signcolumn=yes +set cursorline + +syntax on +set background=dark + +if has("termguicolors") + set termguicolors +endif + +hi Normal ctermbg=NONE guibg=NONE diff --git a/docker/attach.sh b/docker/attach.sh new file mode 100755 index 00000000..8bf0d6a8 --- /dev/null +++ b/docker/attach.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +IMAGE_NAME="cmock-dev-arch" +CONTAINER_WORKDIR="/workspace" + +export MSYS_NO_PATHCONV=1 + +CONTAINER_ID=$(docker ps --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}" | head -n 1) + +if [ -z "$CONTAINER_ID" ]; then + error "No running container found for image '$IMAGE_NAME';" + exit 1 +fi + +success "Attaching to container $CONTAINER_ID..." + +docker exec -it -w "$CONTAINER_WORKDIR" "$CONTAINER_ID" fish diff --git a/docker/run.sh b/docker/run.sh new file mode 100755 index 00000000..3a553b69 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,30 @@ +#! /usr/bin/env bash +set -e + +IMAGE_NAME="cmock-dev-arch" +VOLUME_NAME="cmock-dev-workspace" +CONTAINER_WORKDIR="/workspace" + +export MSYS_NO_PATHCONV=1 + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +source "$SCRIPT_DIR/Resources/logging.sh" + +export $(grep -v '^#' .env | xargs) + +OS_TYPE="$(uname -s)" + +DOCKER_RUN_ARGS=( + -it + --rm + -e GIT_USER_NAME=$GIT_USER_NAME + -e GIT_USER_EMAIL=$GIT_USER_EMAIL + -v "${VOLUME_NAME}:${CONTAINER_WORKDIR}" + -w "${CONTAINER_WORKDIR}" + -v "${HOME}/.ssh/id_ed25519:/home/Dev/.ssh/id_ed25519:ro" + -v "${HOME}/.ssh/id_ed25519.pub:/home/Dev/.ssh/id_ed25519.pub:ro" + -v "${HOME}/.ssh/id_rsa:/home/Dev/.ssh/id_rsa:ro" + -v "${HOME}/.ssh/id_rsa.pub:/home/Dev/.ssh/id_rsa.pub:ro" +) + +docker run --env-file .env ${DOCKER_RUN_ARGS[@]} "$IMAGE_NAME" diff --git a/docker/setup.sh b/docker/setup.sh new file mode 100755 index 00000000..5b898326 --- /dev/null +++ b/docker/setup.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -e + +VOLUME_NAME="cmock-dev-workspace" +IMAGE_NAME="cmock-dev-arch" +DOCKERFILE_PATH="./Resources/Dockerfile" +CONTEXT_DIR="." + +SCRIPT_DIR="$(cd -- "$(dirname -- "$BASH_SOURCE[0]}")" &>/dev/null && pwd)" +source "$SCRIPT_DIR/Resources/logging.sh" + +section "Cleaning up dangling Docker volumes..." +docker volume prune -f + +success "Docker cleanup completed" + +section "Checking if Docker volume '$VOLUME_NAME' exists..." +if ! docker volume inspect "$VOLUME_NAME" > /dev/null 2>&1; then + log "Volume '$VOLUME_NAME' does not exist. Creating..." + docker volume create "$VOLUME_NAME" + success "Volume '$VOLUME_NAME' created." +else + success "Volume '$VOLUME_NAME' found." +fi + +echo "Building Docker image '$IMAGE_NAME' from $DOCKERFILE_PATH..." + +# Temporarily forward ssh to allow for cloning during image build +DOCKER_BUILDKIT=1 docker build \ + -t "$IMAGE_NAME" \ + -f "$DOCKERFILE_PATH" \ + "$CONTEXT_DIR" +success "Docker image '$IMAGE_NAME' built successfully." + +log "Setup complete. Volume: $VOLUME_NAME | Image: $IMAGE_NAME" +log "Run with ./run.sh" +echo; From b7e7ce47f6596684a2cabea4d487582705121caf Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 08:15:52 +0000 Subject: [PATCH 3/9] Added `less` packet --- docker/Resources/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile index 8d9b06cb..346f4bd9 100644 --- a/docker/Resources/Dockerfile +++ b/docker/Resources/Dockerfile @@ -13,7 +13,8 @@ RUN pacman -Syu --noconfirm && \ base \ base-devel \ sudo \ - bash + bash \ + less ENV PATH="/usr/bin:$PATH" From 2eff82ee497ec871cd0908fb4e7071c0657eef85 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 08:32:47 +0000 Subject: [PATCH 4/9] Added baking reference CMock repo into the image --- docker/Resources/Dockerfile | 5 +++++ docker/Resources/init.sh | 13 +++++++++---- docker/run.sh | 4 +++- docker/setup.sh | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile index 346f4bd9..f9f7e005 100644 --- a/docker/Resources/Dockerfile +++ b/docker/Resources/Dockerfile @@ -82,6 +82,11 @@ RUN pacman -Syu --noconfirm \ USER ${USERNAME} ENV HOME=/home/Dev +# Seed the Docker image with CMock repository and its dependencies +RUN git clone git@github.com:$GIT_USER_NAME/CMock.git /opt/cmock && \ + cd /opt/cmock && \ + ./vendor/bundle install + # Install Vim cofiguration RUN sudo mkdir -p /usr/share/vim/vimfiles/autoload && \ sudo curl -fLo /usr/share/vim/vimfiles/autoload/plug.vim \ diff --git a/docker/Resources/init.sh b/docker/Resources/init.sh index 4dcd5211..7a7322e2 100644 --- a/docker/Resources/init.sh +++ b/docker/Resources/init.sh @@ -23,10 +23,15 @@ log "User email: $(git config --global --get user.email || "(user.email not set) section "Searching for CMock forked repository" -REPO_PATH=$(find -iname "CMock") - -if [[ -z $REPO_PATH ]]; then - git clone git@github.com:$GIT_USER_NAME/CMock.git +CMOCK_REPO="/workspace/CMock" +CMOCK_REFERENCE="/opt/CMock" + +if [[ ! -d "$CMOCK_REPO/.git" ]]; then + log "CMock repository not found in workspace. Seeding CMock into workspace volume" + cp -a "$CMOCK_REFERENCE" "$CMOCK_REPO" + success "CMock seeded successfully" +else + success "CMock repository found in workspace" fi echo; diff --git a/docker/run.sh b/docker/run.sh index 3a553b69..93286950 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -10,7 +10,9 @@ export MSYS_NO_PATHCONV=1 SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "$SCRIPT_DIR/Resources/logging.sh" -export $(grep -v '^#' .env | xargs) +set -a +source <(grep -v '^\s*#' $SCRIPT_DIR/.env | grep -v '^\s*$') +set +a OS_TYPE="$(uname -s)" diff --git a/docker/setup.sh b/docker/setup.sh index 5b898326..3c34691f 100755 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -9,6 +9,10 @@ CONTEXT_DIR="." SCRIPT_DIR="$(cd -- "$(dirname -- "$BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "$SCRIPT_DIR/Resources/logging.sh" +set -a +source <(grep -v '^\s*#' $SCRIPT_DIR/.env | grep -v '^\s*$') +set +a + section "Cleaning up dangling Docker volumes..." docker volume prune -f @@ -27,6 +31,7 @@ echo "Building Docker image '$IMAGE_NAME' from $DOCKERFILE_PATH..." # Temporarily forward ssh to allow for cloning during image build DOCKER_BUILDKIT=1 docker build \ + --build-arg GIT_USER_NAME=$GIT_USER_NAME \ -t "$IMAGE_NAME" \ -f "$DOCKERFILE_PATH" \ "$CONTEXT_DIR" From a45c0779d41419069e136f6be84df3508c6ede35 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 08:37:37 +0000 Subject: [PATCH 5/9] Removed redundant .env sourcing in run.sh --- docker/run.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docker/run.sh b/docker/run.sh index 93286950..a1186d57 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -10,17 +10,11 @@ export MSYS_NO_PATHCONV=1 SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "$SCRIPT_DIR/Resources/logging.sh" -set -a -source <(grep -v '^\s*#' $SCRIPT_DIR/.env | grep -v '^\s*$') -set +a - OS_TYPE="$(uname -s)" DOCKER_RUN_ARGS=( -it --rm - -e GIT_USER_NAME=$GIT_USER_NAME - -e GIT_USER_EMAIL=$GIT_USER_EMAIL -v "${VOLUME_NAME}:${CONTAINER_WORKDIR}" -w "${CONTAINER_WORKDIR}" -v "${HOME}/.ssh/id_ed25519:/home/Dev/.ssh/id_ed25519:ro" From f45d40e608d9c57995f224cdfaf7e9113489f370 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 09:15:44 +0000 Subject: [PATCH 6/9] Changed bundle installer invokation --- docker/Resources/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile index f9f7e005..f980144a 100644 --- a/docker/Resources/Dockerfile +++ b/docker/Resources/Dockerfile @@ -85,7 +85,7 @@ ENV HOME=/home/Dev # Seed the Docker image with CMock repository and its dependencies RUN git clone git@github.com:$GIT_USER_NAME/CMock.git /opt/cmock && \ cd /opt/cmock && \ - ./vendor/bundle install + bundle install # Install Vim cofiguration RUN sudo mkdir -p /usr/share/vim/vimfiles/autoload && \ From 92e52fb4ca64bf5e33eeec0f54ca90f6f1164328 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 10:52:47 +0100 Subject: [PATCH 7/9] Fixed problems with git fork URL resolution, added checking for .env file presence --- .gitignore | 2 +- docker/Resources/Dockerfile | 14 +++++++++----- docker/Resources/init.sh | 1 + docker/Resources/vim/.vimrc | 1 - docker/setup.sh | 7 ++++++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b8ac92c7..4758aaf1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ Gemfile.lock *.swp examples/make_example/build examples/temp_sensor/build -Docker/.env +docker/.env diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile index f980144a..b1a2545a 100644 --- a/docker/Resources/Dockerfile +++ b/docker/Resources/Dockerfile @@ -2,6 +2,9 @@ FROM archlinux:latest +ARG GIT_USER_NAME="ThrowTheSwitch" +ENV GIT_USER_NAME=${GIT_USER_NAME} + # Set the locale ENV TERM=xterm-256color ENV STARSHIP_CONFIG=/etc/starship/starship.toml @@ -79,14 +82,15 @@ RUN pacman -Syu --noconfirm \ ruby-rake \ ruby-bundler +# Seed the Docker image with CMock repository and its dependencies +RUN git clone "https://github.com/${GIT_USER_NAME}/CMock.git" /opt/CMock && \ + cd /opt/CMock && \ + bundle install && \ + chown -R Dev:Dev /opt/CMock + USER ${USERNAME} ENV HOME=/home/Dev -# Seed the Docker image with CMock repository and its dependencies -RUN git clone git@github.com:$GIT_USER_NAME/CMock.git /opt/cmock && \ - cd /opt/cmock && \ - bundle install - # Install Vim cofiguration RUN sudo mkdir -p /usr/share/vim/vimfiles/autoload && \ sudo curl -fLo /usr/share/vim/vimfiles/autoload/plug.vim \ diff --git a/docker/Resources/init.sh b/docker/Resources/init.sh index 7a7322e2..ce5c912b 100644 --- a/docker/Resources/init.sh +++ b/docker/Resources/init.sh @@ -29,6 +29,7 @@ CMOCK_REFERENCE="/opt/CMock" if [[ ! -d "$CMOCK_REPO/.git" ]]; then log "CMock repository not found in workspace. Seeding CMock into workspace volume" cp -a "$CMOCK_REFERENCE" "$CMOCK_REPO" + cd $CMOCK_REPO && git remote set-url origin git@github.com:$GIT_USER_NAME/CMock.git success "CMock seeded successfully" else success "CMock repository found in workspace" diff --git a/docker/Resources/vim/.vimrc b/docker/Resources/vim/.vimrc index 69edbbd9..ce2ee4ef 100644 --- a/docker/Resources/vim/.vimrc +++ b/docker/Resources/vim/.vimrc @@ -1,5 +1,4 @@ source ~/.vim/plugins.vim source ~/.vim/ui.vim source ~/.vim/mappings.vim -source ~/.vim/format.vim source ~/.vim/lsp.vim diff --git a/docker/setup.sh b/docker/setup.sh index 3c34691f..0c992109 100755 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -6,9 +6,14 @@ IMAGE_NAME="cmock-dev-arch" DOCKERFILE_PATH="./Resources/Dockerfile" CONTEXT_DIR="." -SCRIPT_DIR="$(cd -- "$(dirname -- "$BASH_SOURCE[0]}")" &>/dev/null && pwd)" +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "$SCRIPT_DIR/Resources/logging.sh" +if [[ ! -f "$SCRIPT_DIR/.env" ]]; then + error "No .env file present. Please create it and set GIT_USER_NAME and GIT_USER_EMAIL before proceeding" + exit 1 +fi + set -a source <(grep -v '^\s*#' $SCRIPT_DIR/.env | grep -v '^\s*$') set +a From e260d5c1e17a7a1296743eaab7e29b53f8254a37 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 11:02:18 +0100 Subject: [PATCH 8/9] Added safeguard for .env absence in run.sh, improved SSH key resolution --- docker/run.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/docker/run.sh b/docker/run.sh index a1186d57..1afe6a04 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -10,6 +10,23 @@ export MSYS_NO_PATHCONV=1 SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" source "$SCRIPT_DIR/Resources/logging.sh" +if [[ ! -f "$SCRIPT_DIR/.env" ]]; then + error "No .env file present. Please create it and set GIT_USER_NAME and GIT_USER_EMAIL before proceeding" + exit 1 +fi + +SSH_KEYS=() + +if [[ -f ${HOME}/.ssh/id_ed25519 ]]; then + SSH_KEYS+=("-v" "${HOME}/.ssh/id_ed25519:/home/Dev/.ssh/id_ed25519:ro") + SSH_KEYS+=("-v" "${HOME}/.ssh/id_ed25519.pub:/home/Dev/.ssh/id_ed25519.pub:ro") +fi + +if [[ -f ${HOME}/.ssh/id_rsa ]]; then + SSH_KEYS+=("-v" "${HOME}/.ssh/id_rsa:/home/Dev/.ssh/id_rsa:ro") + SSH_KEYS+=("-v" "${HOME}/.ssh/id_rsa.pub:/home/Dev/.ssh/id_rsa.pub:ro") +fi + OS_TYPE="$(uname -s)" DOCKER_RUN_ARGS=( @@ -17,10 +34,7 @@ DOCKER_RUN_ARGS=( --rm -v "${VOLUME_NAME}:${CONTAINER_WORKDIR}" -w "${CONTAINER_WORKDIR}" - -v "${HOME}/.ssh/id_ed25519:/home/Dev/.ssh/id_ed25519:ro" - -v "${HOME}/.ssh/id_ed25519.pub:/home/Dev/.ssh/id_ed25519.pub:ro" - -v "${HOME}/.ssh/id_rsa:/home/Dev/.ssh/id_rsa:ro" - -v "${HOME}/.ssh/id_rsa.pub:/home/Dev/.ssh/id_rsa.pub:ro" + ${SSH_KEYS[@]} ) docker run --env-file .env ${DOCKER_RUN_ARGS[@]} "$IMAGE_NAME" From 881027e2f979706f33148909440bb2c5185d3582 Mon Sep 17 00:00:00 2001 From: KacperWojciechowski Date: Sat, 24 Jan 2026 11:06:39 +0100 Subject: [PATCH 9/9] Removed clang-format configuration --- docker/Resources/.clang-format | 188 --------------------------------- docker/Resources/Dockerfile | 3 - 2 files changed, 191 deletions(-) delete mode 100644 docker/Resources/.clang-format diff --git a/docker/Resources/.clang-format b/docker/Resources/.clang-format deleted file mode 100644 index e20c9b02..00000000 --- a/docker/Resources/.clang-format +++ /dev/null @@ -1,188 +0,0 @@ -BasedOnStyle: Mozilla - -IndentWidth: 4 -ColumnLimit: 120 -TabWidth: 4 -UseTab: Never -AlignAfterOpenBracket: true -AlignArrayOfStructures: Right -AlignConsecutiveAssignments: - Enabled: true - AcrossEmptyLines: false - AcrossComments: true - AlignCompound: true - AlignFunctionDeclarations: true - AlignFunctionPointers: true - PadOperators: true -AlignConsecutiveBitFields: AcrossComments -AlignConsecutiveDeclarations: AcrossComments -AlignConsecutiveMacros: AcrossComments -AlignConsecutiveShortCaseStatements: - Enabled: true - AcrossEmptyLines: true - AcrossComments: true - AlignCaseArrows: true - AlignCaseColons: true -AlignEscapedNewlines: LeftWithLastLine -AlignOperands: BreakBeforeBinaryOperators -AlignTrailingComments: - Kind: Always - OverEmptyLines: 1 - MaxEmptyLinesToKeep: 1 - AlignPPAndNotPP: true -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Always -AllowShortCaseExpressionOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: true -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: Empty -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true -AlwaysBreakBeforeMultilineStrings: true -BinPackArguments: false -BinPackLongBracedList: true -BinPackParameters: OnePerLine -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterFunction: true - AfterNamespace: false - AfterStruct: false - AfterUnion: false - AfterExternBlock: true - BeforeCatch: true - BeforeElse: true - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false -BracedInitializerIndentWidth: 4 -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterReturnType: ExceptShortType -BreakArrays: false -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Custom -BreakBeforeCloseBracketBracedList: true -BreakBeforeCloseBracketFunction: false -BreakBeforeCloseBracketIf: false -BreakBeforeCloseBracketLoop: false -BreakBeforeCloseBracketSwitch: false -BreakBeforeInlineASMColon: Always -BreakBeforeTernaryOperators: true -BreakBinaryOperations: RespectPrecedence -BreakFunctionDefinitionParameters: false -BreakStringLiterals: true -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: Block -DerivePointerAlignment: false -EnumTrailingComma: Remove -ExperimentalAutoDetectBinPacking: false -IncludeBlocksStyle: Merge -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExternBlock: false -IndentPPDirectives: BeforeHash -IndentWrappedFunctionNames: true -InsertBraces: true -InsertNewlineAtEOF: true -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: -1 - Decimal: 3 - DecimalMinDigitsInsert: 5 - DecimalMaxDigitsRemove: 4 - Hex: 2 - HexMinDigitsInsert: 5 - HexMaxDigitsRemove: 4 -KeepEmptyLines: - AtEndOfFile: true - AtStartOfBlock: false - AtStartOfFile: false -LineEnding: LF -MaxEmptyLinesToKeep: 1 -NumericLiteralCase: - ExponentLetter: Lower - HexDigit: Upper - Prefix: Lower - Suffix: Lower -OneLineFormatOffRegex: ^(// NOLINT) -PPIndentWidth: 4 -PointerAlignment: Left -QualifierAlignment: Left -QualifierOrder: [friend, inline, static, const, constexpr, volatile, type] -ReflowComments: Always -RemoveBracesLLVM: false -RemoveEmptyLinesInUnwrappedLines: true -RemoveParentheses: Leave -RemoveSemicolon: true -SeparateDefinitionBlocks: Always -SkipMacroDefinitionBody: false -SortIncludes: - Enabled: true - IgnoreCase: true - IgnoreExtension: true -SpaceAfterLogicalNot: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: true -SpaceBeforeParens: Never -SpaceBeforeSquareBrackets: false -SpaceInEmptyBraces: false -SpaceBeforeTrailingComments: 3 -SpacesInContainerLiterals: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: 1 -SpacesInParens: Never -SpacesInSquareBrackets: false -Standard: Latest - ---- -Language: Cpp -AccessModifierOffset: -4 -AllowBreakBeforeNoexceptSpecifier: Never -AllowBreakBeforeQtProperty: true -AllowShortCompoundRequirementOnASingleLine: true -AllowShortLambdasOnASingleLine: Empty -AllowShortNamespacesOnASingleLine: false -BreakBeforeConceptDeclarations: Always -BreakBeforeTemplateCloser: false -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon -BreakTemplateDeclarations: Yes -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: Always -FixNamespaceComments: true -IndentAccessModifiers: false -IndentExportBlock: true -IndentRequiresClause: true -LambdaBodyIndentation: Signature -NamespaceIndentation: All -PackConstructorInitializers: CurrentLine -ReferenceAlignment: Left -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -ShortNamespaceLines: 0 -SortUsingDeclarations: Lexicographic -SpaceAfterOperatorKeyword: false -SpaceAfterTemplateKeyword: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeRangeBasedForLoopColon: true -SpacesInAngles: Never -WrapNamespaceBodyWithEmptyLines: Never - ---- -Language: C -IndentGotoLabels: false -SpaceAfterCStyleCast: true diff --git a/docker/Resources/Dockerfile b/docker/Resources/Dockerfile index b1a2545a..ae38e2c9 100644 --- a/docker/Resources/Dockerfile +++ b/docker/Resources/Dockerfile @@ -114,9 +114,6 @@ COPY Resources/starship.toml /etc/starship/starship.toml RUN sudo chmod +x /opt/container-scripts/init.sh -# Copy clang-format configuration -COPY Resources/.clang-format /etc/clang-format/.clang-format - # Configure the entrypoint WORKDIR /workspace ENTRYPOINT ["/usr/bin/fish", "-lc", "/opt/container-scripts/init.sh; exec fish"]