Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zsh image for ncs-zephyr #7

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build-and-publish-ncs-zephyr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
84 changes: 83 additions & 1 deletion ncs-zephyr/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOT
mkdir -p ~/.zsh
git clone https://github.com/sindresorhus/pure.git ~/.zsh/pure
curl -L git.io/antigen > ~/.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" ]
8 changes: 8 additions & 0 deletions ncs-zephyr/build_zsh.sh
Original file line number Diff line number Diff line change
@@ -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" .
2 changes: 1 addition & 1 deletion ncs-zephyr/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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