From 0ca5c2ba504a1963148e259cf69e607162f712b7 Mon Sep 17 00:00:00 2001 From: Lod Date: Wed, 18 Dec 2024 10:55:33 +0100 Subject: [PATCH] Manala up - introduce zsh Add a message after `make sh` to remind that containerd is not compatible with molecule (for test on Mac Silicon) --- .manala.yaml | 6 +- .manala/Makefile | 2 +- .manala/docker/Dockerfile | 41 +++-- .manala/docker/compose.yaml | 11 +- .manala/docker/compose/term.yaml | 9 ++ .manala/docker/docker.mk | 3 + .manala/docker/entrypoint.sh | 6 +- .manala/etc/profile.d/oh-my-bash.sh | 148 ------------------ .manala/etc/starship/starship.toml | 24 +++ .../etc/{profile.d/message.sh => zsh/.zlogin} | 8 +- .../{profile.d/zz-direnv.sh => zsh/.zprofile} | 4 +- .manala/etc/zsh/.zshrc | 116 ++++++++++++++ 12 files changed, 206 insertions(+), 172 deletions(-) create mode 100644 .manala/docker/compose/term.yaml delete mode 100644 .manala/etc/profile.d/oh-my-bash.sh create mode 100644 .manala/etc/starship/starship.toml rename .manala/etc/{profile.d/message.sh => zsh/.zlogin} (77%) rename .manala/etc/{profile.d/zz-direnv.sh => zsh/.zprofile} (85%) create mode 100644 .manala/etc/zsh/.zshrc diff --git a/.manala.yaml b/.manala.yaml index c573a9f4e..9beb53c37 100644 --- a/.manala.yaml +++ b/.manala.yaml @@ -12,6 +12,10 @@ manala: project: name: manala-ansible-roles + help: | + ## Containerd ## + Build of test containers with Molecule is incompatible with Containerd on Mac ARM + Turn it off in Docker Desktop in order to launch your tests in local ########## # System # @@ -41,6 +45,6 @@ system: ansible-lint: version: 24.7.0 molecule: - version: 24.7.0 + version: 24.12.0 dependencies: - molecule-plugins[docker]==23.5.3 diff --git a/.manala/Makefile b/.manala/Makefile index 5dfcacf72..2dfef15cb 100644 --- a/.manala/Makefile +++ b/.manala/Makefile @@ -49,7 +49,7 @@ sh: else \ $(call manala_docker_command, \ $(if $(PORT),--publish $(PORT)), \ - ) bash --login ; \ + ) zsh --login ; \ fi .PHONY: sh diff --git a/.manala/docker/Dockerfile b/.manala/docker/Dockerfile index fcbc39eda..959069391 100644 --- a/.manala/docker/Dockerfile +++ b/.manala/docker/Dockerfile @@ -10,10 +10,12 @@ ARG MANALA_USER_ID="1000" ARG MANALA_GROUP_ID="1000" ARG GOSU_VERSION="1.17" -ARG GOMPLATE_VERSION="4.1.0" -ARG DIRENV_VERSION="2.34.0" +ARG GOMPLATE_VERSION="4.2.0" +ARG DIRENV_VERSION="2.35.0" ARG JQ_VERSION="1.7.1" -ARG YQ_VERSION="4.44.3" +ARG YQ_VERSION="4.44.5" +ARG STARSHIP_VERSION="1.21.1" +ARG FZF_VERSION="0.56.3" # The 'container' environment variable tells systemd that it's running inside a # Docker container environment. @@ -23,13 +25,15 @@ ENV container="docker" # Default locale ENV LANG="C.UTF-8" +# Starship +ENV STARSHIP_CONFIG=/etc/starship/starship.toml + SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN \ apt-get --quiet update \ && apt-get --quiet --yes --purge --autoremove upgrade \ && apt-get --quiet --yes --no-install-recommends --verbose-versions install \ - bash-completion \ bzip2 \ ca-certificates \ curl \ @@ -43,9 +47,10 @@ RUN \ socat \ sudo \ vim \ + zsh \ # User && addgroup --gid ${MANALA_GROUP_ID} lazy \ - && adduser --home /home/lazy --shell /bin/bash --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \ + && adduser --home /home/lazy --shell /bin/zsh --uid ${MANALA_USER_ID} --gecos lazy --ingroup lazy --disabled-password lazy \ && install --verbose --mode 0755 --group lazy --owner lazy --directory /run/user/${MANALA_USER_ID} \ && echo "lazy ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/lazy \ # Gosu @@ -68,10 +73,20 @@ RUN \ && curl -sSLf "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_$(case $(dpkg --print-architecture) in "amd64") echo "amd64" ;; "arm64") echo "arm64" ;; esac)" \ --output /usr/local/bin/yq \ && chmod +x /usr/local/bin/yq \ - # Bash completion - && install --verbose --mode 0755 --directory /etc/bash_completion.d \ - # Oh My Bash - && git clone https://github.com/ohmybash/oh-my-bash.git /usr/local/share/oh-my-bash \ + # Oh My Zsh + && git clone https://github.com/ohmyzsh/ohmyzsh.git /usr/local/share/oh-my-zsh \ + # See: https://github.com/ohmyzsh/ohmyzsh/issues/11995 + && git clone https://github.com/zsh-users/zsh-autosuggestions.git /usr/local/share/oh-my-zsh/custom/plugins/zsh-autosuggestions \ + && git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /usr/local/share/oh-my-zsh/custom/plugins/zsh-syntax-highlighting \ + && echo "ZDOTDIR=/etc/zsh" > /etc/zsh/zshenv \ + # Starship + && curl -sSLf "https://github.com/starship/starship/releases/download/v${STARSHIP_VERSION}/starship-$(case $(dpkg --print-architecture) in "amd64") echo "x86_64" ;; "arm64") echo "aarch64" ;; esac)-unknown-linux-musl.tar.gz" \ + | bsdtar -xvf - -C /usr/local/bin \ + && echo "Defaults env_keep += STARSHIP_CONFIG" > /etc/sudoers.d/starship \ + # Fzf + && curl -sSLf "https://github.com/junegunn/fzf/releases/download/v${FZF_VERSION}/fzf-${FZF_VERSION}-linux_$(case $(dpkg --print-architecture) in "amd64") echo "amd64" ;; "arm64") echo "arm64" ;; esac).tar.gz" \ + | bsdtar -xvf - -C /usr/local/bin \ + && chmod +x /usr/local/bin/fzf \ # Clean && rm -rf /var/lib/apt/lists/* @@ -88,13 +103,10 @@ RUN \ openssh-client \ pipx \ python3 \ - python3-argcomplete \ shellcheck \ sshpass \ # Sudo && echo "Defaults env_keep += \"PIPX_*\"" > /etc/sudoers.d/pipx \ - # Bash completion - && activate-global-python-argcomplete --dest /etc/bash_completion.d \ # Clean && rm -rf /var/lib/apt/lists/* @@ -140,12 +152,11 @@ RUN \ # Molecule RUN \ pipx install --pip-args="--no-cache-dir" \ - molecule==24.7.0 \ - && _MOLECULE_COMPLETE=bash_source molecule > /etc/bash_completion.d/molecule \ + molecule==24.12.0 \ && pipx inject --pip-args="--no-cache-dir" molecule \ molecule-plugins[docker]==23.5.3 # Run COPY docker/entrypoint.sh / ENTRYPOINT ["/entrypoint.sh"] -CMD ["bash"] +CMD ["zsh"] diff --git a/.manala/docker/compose.yaml b/.manala/docker/compose.yaml index 198a244ac..d6549130d 100644 --- a/.manala/docker/compose.yaml +++ b/.manala/docker/compose.yaml @@ -11,7 +11,8 @@ services: build: context: .. dockerfile: docker/Dockerfile - image: manala-ansible-roles:20240916111724 + image: manala-ansible-roles:20241217124745 + pull_policy: never volumes: - ../..:${MANALA_DIR} environment: @@ -22,5 +23,9 @@ services: - path: ../../.env.local required: false working_dir: ${MANALA_DIR} - # Use default docker bridge network - network_mode: bridge + networks: + - network + +networks: + network: + name: manala-ansible-roles diff --git a/.manala/docker/compose/term.yaml b/.manala/docker/compose/term.yaml new file mode 100644 index 000000000..6dacb7273 --- /dev/null +++ b/.manala/docker/compose/term.yaml @@ -0,0 +1,9 @@ +services: + + ########## + # System # + ########## + + system: + environment: + TERM: ${TERM:-xterm} diff --git a/.manala/docker/docker.mk b/.manala/docker/docker.mk index a232759c5..cbd3db94a 100644 --- a/.manala/docker/docker.mk +++ b/.manala/docker/docker.mk @@ -101,6 +101,9 @@ MANALA_DOCKER_COMPOSE_FILE += \ # Debug MANALA_DOCKER_COMPOSE_ENV += $(if $(MANALA_DOCKER_DEBUG), BUILDKIT_PROGRESS=plain) +# Term +MANALA_DOCKER_COMPOSE_FILE += $(MANALA_DIR)/.manala/docker/compose/term.yaml + # Usage: # $(manala_docker_compose) [COMMAND] [ARGS...] diff --git a/.manala/docker/entrypoint.sh b/.manala/docker/entrypoint.sh index d8dd64624..073399d8e 100755 --- a/.manala/docker/entrypoint.sh +++ b/.manala/docker/entrypoint.sh @@ -5,11 +5,12 @@ set -e # Ssh agent bridge if [ -n "${SSH_AUTH_SOCK}" ]; then sh -c " \ - while sleep 1; do \ + while true; do \ rm -f /var/run/ssh-auth-bridge.sock ; socat \ UNIX-LISTEN:/var/run/ssh-auth-bridge.sock,fork,mode=777 \ UNIX-CONNECT:/var/run/ssh-auth.sock ; \ + sleep 1; \ done \ " & fi @@ -17,11 +18,12 @@ fi # Docker bridge if [ -n "${DOCKER_HOST}" ]; then sh -c " \ - while sleep 1; do \ + while true; do \ rm -f /var/run/docker-bridge.sock ; socat -t 600 \ UNIX-LISTEN:/var/run/docker-bridge.sock,fork,mode=777 \ UNIX-CONNECT:/var/run/docker.sock ; \ + sleep 1; \ done \ " & fi diff --git a/.manala/etc/profile.d/oh-my-bash.sh b/.manala/etc/profile.d/oh-my-bash.sh deleted file mode 100644 index fe240f8fd..000000000 --- a/.manala/etc/profile.d/oh-my-bash.sh +++ /dev/null @@ -1,148 +0,0 @@ -# Enable the subsequent settings only in interactive sessions -case $- in - *i*) ;; - *) return;; -esac - -# Path to your oh-my-bash installation. -export OSH=/usr/local/share/oh-my-bash - -# Set name of the theme to load. Optionally, if you set this to "random" -# it'll load a random theme each time that oh-my-bash is loaded. -OSH_THEME="font" - -# If you set OSH_THEME to "random", you can ignore themes you don't like. -# OMB_THEME_RANDOM_IGNORED=("powerbash10k" "wanelo") - -# Uncomment the following line to use case-sensitive completion. -# OMB_CASE_SENSITIVE="true" - -# Uncomment the following line to use hyphen-insensitive completion. Case -# sensitive completion must be off. _ and - will be interchangeable. -# OMB_HYPHEN_SENSITIVE="false" - -# Uncomment the following line to disable bi-weekly auto-update checks. -DISABLE_AUTO_UPDATE="true" - -# Uncomment the following line to change how often to auto-update (in days). -# export UPDATE_OSH_DAYS=13 - -# Uncomment the following line to disable colors in ls. -# DISABLE_LS_COLORS="true" - -# Uncomment the following line to disable auto-setting terminal title. -# DISABLE_AUTO_TITLE="true" - -# Uncomment the following line to enable command auto-correction. -ENABLE_CORRECTION="true" - -# Uncomment the following line to display red dots whilst waiting for completion. -COMPLETION_WAITING_DOTS="true" - -# Uncomment the following line if you want to disable marking untracked files -# under VCS as dirty. This makes repository status check for large repositories -# much, much faster. -DISABLE_UNTRACKED_FILES_DIRTY="true" - -# Uncomment the following line if you don't want the repository to be considered dirty -# if there are untracked files. -# SCM_GIT_DISABLE_UNTRACKED_DIRTY="true" - -# Uncomment the following line if you want to completely ignore the presence -# of untracked files in the repository. -# SCM_GIT_IGNORE_UNTRACKED="true" - -# Uncomment the following line if you want to change the command execution time -# stamp shown in the history command output. One of the following values can -# be used to specify the timestamp format. -# * 'mm/dd/yyyy' # mm/dd/yyyy + time -# * 'dd.mm.yyyy' # dd.mm.yyyy + time -# * 'yyyy-mm-dd' # yyyy-mm-dd + time -# * '[mm/dd/yyyy]' # [mm/dd/yyyy] + [time] with colors -# * '[dd.mm.yyyy]' # [dd.mm.yyyy] + [time] with colors -# * '[yyyy-mm-dd]' # [yyyy-mm-dd] + [time] with colors -# If not set, the default value is 'yyyy-mm-dd'. -# HIST_STAMPS='yyyy-mm-dd' - -# Uncomment the following line if you do not want OMB to overwrite the existing -# aliases by the default OMB aliases defined in lib/*.sh -# OMB_DEFAULT_ALIASES="check" - -# Would you like to use another custom folder than $OSH/custom? -# OSH_CUSTOM=/path/to/new-custom-folder - -# To disable the uses of "sudo" by oh-my-bash, please set "false" to -# this variable. The default behavior for the empty value is "true". -OMB_USE_SUDO=true - -# To enable/disable display of Python virtualenv and condaenv -# OMB_PROMPT_SHOW_PYTHON_VENV=true # enable -# OMB_PROMPT_SHOW_PYTHON_VENV=false # disable - -# Which completions would you like to load? (completions can be found in ~/.oh-my-bash/completions/*) -# Custom completions may be added to ~/.oh-my-bash/custom/completions/ -# Example format: completions=(ssh git bundler gem pip pip3) -# Add wisely, as too many completions slow down shell startup. -completions=( - git - ssh -) - -# Which aliases would you like to load? (aliases can be found in ~/.oh-my-bash/aliases/*) -# Custom aliases may be added to ~/.oh-my-bash/custom/aliases/ -# Example format: aliases=(vagrant composer git-avh) -# Add wisely, as too many aliases slow down shell startup. -aliases=( - general - ls -) - -# Which plugins would you like to load? (plugins can be found in ~/.oh-my-bash/plugins/*) -# Custom plugins may be added to ~/.oh-my-bash/custom/plugins/ -# Example format: plugins=(rails git textmate ruby lighthouse) -# Add wisely, as too many plugins slow down shell startup. -plugins=( - git - ansible -) - -# Which plugins would you like to conditionally load? (plugins can be found in ~/.oh-my-bash/plugins/*) -# Custom plugins may be added to ~/.oh-my-bash/custom/plugins/ -# Example format: -# if [ "$DISPLAY" ] || [ "$SSH" ]; then -# plugins+=(tmux-autoattach) -# fi - -source "$OSH"/oh-my-bash.sh - -# User configuration -# export MANPATH="/usr/local/man:$MANPATH" - -# You may need to manually set your language environment -# export LANG=en_US.UTF-8 - -# Preferred editor for local and remote sessions -# if [[ -n $SSH_CONNECTION ]]; then -# export EDITOR='vim' -# else -# export EDITOR='mvim' -# fi - -# Compilation flags -# export ARCHFLAGS="-arch x86_64" - -# ssh -# export SSH_KEY_PATH="~/.ssh/rsa_id" - -# Set personal aliases, overriding those provided by oh-my-bash libs, -# plugins, and themes. Aliases can be placed here, though oh-my-bash -# users are encouraged to define aliases within the OSH_CUSTOM folder. -# For a full list of active aliases, run `alias`. -# -# Example aliases -# alias bashconfig="mate ~/.bashrc" -# alias ohmybash="mate ~/.oh-my-bash" - -# Disable full path print after cd into a directory -# See: https://github.com/ohmybash/oh-my-bash/issues/201 -unset CDPATH diff --git a/.manala/etc/starship/starship.toml b/.manala/etc/starship/starship.toml new file mode 100644 index 000000000..497a54551 --- /dev/null +++ b/.manala/etc/starship/starship.toml @@ -0,0 +1,24 @@ +# Starship config template +# Don't edit this file directly. Instead, set config in project .manala.yaml, and run `manala up`. + +format = """ +[╭─](cyan)$username$hostname$directory$direnv$env_var$custom +[╰](cyan) $cmd_duration$character""" + +[username] +show_always = true +format = '[$user]($style)@' +style_user = 'yellow' + +[hostname] +ssh_only = false +style = 'yellow' + +[directory] +truncation_length = 1 +truncation_symbol = '…/' +read_only = '' +style = 'cyan' + +[direnv] +disabled = false diff --git a/.manala/etc/profile.d/message.sh b/.manala/etc/zsh/.zlogin similarity index 77% rename from .manala/etc/profile.d/message.sh rename to .manala/etc/zsh/.zlogin index 8fe5782e2..13b86ede7 100644 --- a/.manala/etc/profile.d/message.sh +++ b/.manala/etc/zsh/.zlogin @@ -12,5 +12,11 @@ printf "\n" printf " \033[36m‣ ansible \033[35m2.15.12\033[0m\n" printf " \033[36m· docker==7.1.0\033[0m\n" printf " \033[36m‣ ansible-lint \033[35m24.7.0\033[0m\n" -printf " \033[36m‣ molecule \033[35m24.7.0\033[0m\n" +printf " \033[36m‣ molecule \033[35m24.12.0\033[0m\n" printf " \033[36m· molecule-plugins[docker]==23.5.3\033[0m\n" +printf "\n" +cat << EOF +## Containerd ## +Build of test containers with Molecule is incompatible with Containerd on Mac ARM +Turn it off in Docker Desktop in order to launch your tests in local +EOF diff --git a/.manala/etc/profile.d/zz-direnv.sh b/.manala/etc/zsh/.zprofile similarity index 85% rename from .manala/etc/profile.d/zz-direnv.sh rename to .manala/etc/zsh/.zprofile index 24ea57374..e056f36d5 100644 --- a/.manala/etc/profile.d/zz-direnv.sh +++ b/.manala/etc/zsh/.zprofile @@ -1,4 +1,6 @@ -eval "$(direnv hook bash)" +########## +# Direnv # +########## # Config directory export DIRENV_CONFIG=/etc/direnv diff --git a/.manala/etc/zsh/.zshrc b/.manala/etc/zsh/.zshrc new file mode 100644 index 000000000..ace9bc983 --- /dev/null +++ b/.manala/etc/zsh/.zshrc @@ -0,0 +1,116 @@ +# If you come from bash you might have to change your $PATH. +# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH + +# Path to your Oh My Zsh installation. +export ZSH="/usr/local/share/oh-my-zsh" + +# Set name of the theme to load --- if set to "random", it will +# load a random theme each time Oh My Zsh is loaded, in which case, +# to know which specific one was loaded, run: echo $RANDOM_THEME +# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes +ZSH_THEME="" + +# Set list of themes to pick from when loading at random +# Setting this variable when ZSH_THEME=random will cause zsh to load +# a theme from this variable instead of looking in $ZSH/themes/ +# If set to an empty array, this variable will have no effect. +# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) + +# Uncomment the following line to use case-sensitive completion. +# CASE_SENSITIVE="true" + +# Uncomment the following line to use hyphen-insensitive completion. +# Case-sensitive completion must be off. _ and - will be interchangeable. +# HYPHEN_INSENSITIVE="true" + +# Uncomment one of the following lines to change the auto-update behavior +zstyle ':omz:update' mode disabled # disable automatic updates +# zstyle ':omz:update' mode auto # update automatically without asking +# zstyle ':omz:update' mode reminder # just remind me to update when it's time + +# Uncomment the following line to change how often to auto-update (in days). +# zstyle ':omz:update' frequency 13 + +# Uncomment the following line if pasting URLs and other text is messed up. +# DISABLE_MAGIC_FUNCTIONS="true" + +# Uncomment the following line to disable colors in ls. +# DISABLE_LS_COLORS="true" + +# Uncomment the following line to disable auto-setting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment the following line to enable command auto-correction. +# ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +# You can also set it to another string to have that shown instead of the default red dots. +# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f" +# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765) +# COMPLETION_WAITING_DOTS="true" + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Uncomment the following line if you want to change the command execution time +# stamp shown in the history command output. +# You can set one of the optional three formats: +# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" +# or set a custom format using the strftime function format specifications, +# see 'man strftime' for details. +# HIST_STAMPS="mm/dd/yyyy" + +# Would you like to use another custom folder than $ZSH/custom? +# ZSH_CUSTOM=/path/to/new-custom-folder + +# Which plugins would you like to load? +# Standard plugins can be found in $ZSH/plugins/ +# Custom plugins may be added to $ZSH_CUSTOM/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +# Add wisely, as too many plugins slow down shell startup. +plugins=( + git + direnv + zsh-autosuggestions + zsh-syntax-highlighting + fzf + ansible + docker + terraform +) + +source $ZSH/oh-my-zsh.sh + +# User configuration + +# export MANPATH="/usr/local/man:$MANPATH" + +# You may need to manually set your language environment +# export LANG=en_US.UTF-8 + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='nvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch $(uname -m)" + +# Set personal aliases, overriding those provided by Oh My Zsh libs, +# plugins, and themes. Aliases can be placed here, though Oh My Zsh +# users are encouraged to define aliases within a top-level file in +# the $ZSH_CUSTOM folder, with .zsh extension. Examples: +# - $ZSH_CUSTOM/aliases.zsh +# - $ZSH_CUSTOM/macos.zsh +# For a full list of active aliases, run `alias`. +# +# Example aliases +# alias zshconfig="mate ~/.zshrc" +# alias ohmyzsh="mate ~/.oh-my-zsh" + +# Starship +eval "$(starship init zsh)"