From 15d2b060ec926317c2f4c888e7a5ab6dd61377f1 Mon Sep 17 00:00:00 2001 From: MarkoSagadin Date: Thu, 10 Oct 2024 15:04:42 +0200 Subject: [PATCH] feat: add zsh image for ncs-zephyr --- .../build-and-publish-ncs-zephyr.yaml | 14 ++++ README.md | 2 + ncs-zephyr/Dockerfile | 84 ++++++++++++++++++- ncs-zephyr/build_zsh.sh | 8 ++ ncs-zephyr/run.sh | 2 +- 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100755 ncs-zephyr/build_zsh.sh diff --git a/.github/workflows/build-and-publish-ncs-zephyr.yaml b/.github/workflows/build-and-publish-ncs-zephyr.yaml index dd4114a..5190fd4 100644 --- a/.github/workflows/build-and-publish-ncs-zephyr.yaml +++ b/.github/workflows/build-and-publish-ncs-zephyr.yaml @@ -73,3 +73,17 @@ jobs: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.variant.ncs_version }}-dev:latest build-args: | NCS_SDK_VERSION=${{ matrix.variant.ncs_version }} + + - name: Build and push Zsh image + id: push-zsh + uses: docker/build-push-action@v5 + with: + file: ./ncs-zephyr/Dockerfile + target: zsh + platforms: linux/amd64 + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.variant.ncs_version }}-zsh:${{ inputs.release_version }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.variant.ncs_version }}-zsh:latest + build-args: | + NCS_SDK_VERSION=${{ matrix.variant.ncs_version }} diff --git a/README.md b/README.md index 4b2c39a..7792435 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ The `ncs-zepyhr` folder contains only a single Dockerfile with two multi-stage b suitable to be used in the CI. - `DEV` - A docker image which inherits from `CI` stage. It contains flashing tools and some configuration to make development inside the container easier. +- `ZSH` - A docker image which inherits from `DEV` stage. It contains ZSH shell and some other tools + for nicer developer experience. #### Naming scheme diff --git a/ncs-zephyr/Dockerfile b/ncs-zephyr/Dockerfile index 238796b..8b55f0e 100644 --- a/ncs-zephyr/Dockerfile +++ b/ncs-zephyr/Dockerfile @@ -162,8 +162,90 @@ RUN find /home/user/ncs/toolchains/ -path '**/usr/local/bin/*' | \ # Make 'user' default on launch USER user +# Append environment variables of the toolchain-manager to the user's bashrc to +# get access to the installed programs. See extra info at the end of the file. +RUN nrfutil toolchain-manager env --as-script sh >> ~/.bashrc + +############# +# ZSH image # +############# + +FROM dev AS zsh + +USER root + +# Install some utility tools. +RUN \ + apt-get -y update \ + && apt-get -y upgrade \ + && apt-get -y install --no-install-recommends git zsh \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && wget -c https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz -O - | tar xz \ + && chmod +x eza \ + && mv eza /usr/local/bin/eza \ + && chsh -s $(which zsh) + +USER user + +RUN < ~/.zsh/antigen.zsh +git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf +~/.fzf/install + +cat >> ~/.zshrc << EOF +# Install plugin manager and plugins +source $HOME/.zsh/antigen.zsh +antigen bundle agkozak/zsh-z +antigen bundle zsh-users/zsh-completions +antigen bundle zsh-users/zsh-autosuggestions +antigen bundle hcgraf/zsh-sudo +antigen bundle zsh-users/zsh-syntax-highlighting # Needs to be last bundle +antigen apply + +# Setup pure prompt +fpath+=($HOME/.zsh/pure) +autoload -U promptinit; promptinit +prompt pure +zstyle :prompt:pure:git:stash show yes + +# Change the path color +zstyle :prompt:pure:user color cyan +zstyle :prompt:pure:host color cyan + +setopt histignoredups # Ignore command history duplicates +setopt menu_complete # Tab completion when choice ambiguous + +# Aliases +alias ls='eza' +alias cp="cp -i" # confirm before overwriting something +alias df='df -h' # human-readable sizes +alias free='free -m' # show sizes in MB +alias ll='ls -aglh --color=auto --group-directories-first' +alias ml='minicom' +alias cl='rm -fr build' +alias ..="cd .." +alias ...="cd ../.." +alias ....="cd ../../.." +alias .....="cd ../../../.." +alias ......="cd ../../../../.." + +# Fzf +source <(fzf --zsh) +EOF + +EOT + + # Append environment variables of the toolchain-manager to the user's bashrc to # get access to the installed programs. # Previously that was done with the ENTRYPOINT command, however that is a bit # error prone for devcontainer usecases, as it isn't always taken into account. -RUN nrfutil toolchain-manager env --as-script sh >> ~/.bashrc +RUN nrfutil toolchain-manager env --as-script sh >> ~/.zshrc + +# Execute the file so that plugins are installed. +RUN zsh ~/.zshrc + +CMD [ "/bin/zsh" ] diff --git a/ncs-zephyr/build_zsh.sh b/ncs-zephyr/build_zsh.sh new file mode 100755 index 0000000..fc0f9dd --- /dev/null +++ b/ncs-zephyr/build_zsh.sh @@ -0,0 +1,8 @@ +#! /usr/bin/env bash +NCS_SDK_VERSION=v2.7.0 + +docker build \ + --build-arg "NCS_SDK_VERSION=$NCS_SDK_VERSION" \ + --target zsh \ + -f "Dockerfile" \ + -t "irnas/ncs-zephyr-$NCS_SDK_VERSION-zsh:latest" . diff --git a/ncs-zephyr/run.sh b/ncs-zephyr/run.sh index 55609e1..e8186f4 100755 --- a/ncs-zephyr/run.sh +++ b/ncs-zephyr/run.sh @@ -27,4 +27,4 @@ docker run -it --rm \ --publish 8080:8080 \ --publish 8081:8081 \ --publish 8090:8090 \ - irnas/ncs-zephyr-v2.7.0-dev:latest + irnas/ncs-zephyr-v2.7.0-zsh:latest