Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
ss-o committed Nov 23, 2023
1 parent 6311417 commit 55ade14
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/label-commenter-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ labels:
body: Please follow the issue templates.
action: close
pr:
body: Thank you @{{ pull_request.user.login }} for suggesting this. Please follow the pull request templates.
body: Thank you @{{ pull_request.zunit.login }} for suggesting this. Please follow the pull request templates.
action: close
unlabeled:
issue:
Expand Down Expand Up @@ -38,7 +38,7 @@ labels:
- name: feature-request 💡
labeled:
issue:
body: Thank you @{{ issue.user.login }} for suggesting this.
body: Thank you @{{ issue.zunit.login }} for suggesting this.
- name: locked ‼️
labeled:
issue:
Expand Down
1 change: 1 addition & 0 deletions .trunk/configs/.hadolint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
ignored:
- SC1090
- SC1091
- DL3018
5 changes: 3 additions & 2 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
disable=SC1090
disable=SC1091
disable=SC2312
20 changes: 10 additions & 10 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
version: 0.1
cli:
version: 1.17.1
version: 1.17.2
plugins:
sources:
- id: trunk
ref: v1.2.6
ref: v1.3.0
uri: https://github.com/trunk-io/plugins
lint:
disabled:
- checkov
- terrascan
- yamllint
- trivy
enabled:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected].0
- [email protected].1
- [email protected]
- [email protected]
- prettier@3.0.3
- prettier@3.1.0
- [email protected]
- [email protected]
runtimes:
enabled:
- [email protected]
- node@18.12.1
- [email protected].8
- node@20.10.0
- [email protected].9
actions:
enabled:
- trunk-announce
Expand Down
66 changes: 41 additions & 25 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
ARG VERSION=latest
FROM alpine:${VERSION}
ARG VERSION=edge
FROM alpine:$VERSION
LABEL maintainer="<%= Z-Shell Community %>"
LABEL email="<%= [email protected] =%>"

ARG HOSTNAME=zi@docker
ARG ZUSER=z-user
ARG SHELL=/bin/zsh
ARG DIR=/static

ENV ZUSER=${ZUSER}
ENV PUID=${PUID}
ENV PGID=${PGID}
ENV HOSTNAME=${HOSTNAME}
ENV APK_ADD=${APK_ADD}
ENV DIR=${DIR} TERM=${TERM}
ENV ZI_ZSH_VERSION=${ZI_ZSH_VERSION}
ENV ZI_HOME_DIR=${ZI_HOME_DIR} ZI_BIN_DIR=${ZI_BIN_DIR}

# trunk-ignore(hadolint/DL3018)
RUN apk --no-cache --virtual base add coreutils curl \
jq git libuser rsync sudo zsh ncurses-dev pcre-dev zlib-dev alpine-zsh-config \
&& apk --no-cache --virtual zsh-build-tools add autoconf bash build-base go vim
ARG DIR
ARG PUID
ARG PGID
ARG TERM
ARG ZUSER
ARG ZHOST

ENV DIR=${DIR:-/static}
ENV PUID=${PUID:-1000}
ENV PGID=${PGID:-1000}
ENV TERM=${TERM:-xterm}
ENV ZUSER=${ZUSER:-user}
ENV HOST=$ZHOST

RUN set -ex && apk --no-cache add \
alpine-zsh-config \
ncurses-dev \
build-base \
coreutils \
pcre-dev \
zlib-dev \
autoconf \
libuser \
rsync \
bash \
curl \
sudo \
zsh \
git \
vim \
go \
jq

WORKDIR $DIR
COPY . .
RUN chmod +x entrypoint.sh && ./entrypoint.sh

VOLUME ["/src", "/data"]
COPY --chown=${ZUSER} . /src
COPY --chown=$ZUSER . /src

USER ${ZUSER}
WORKDIR /home/${ZUSER}
USER $ZUSER
WORKDIR /home/$ZUSER

RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh)" -- -i skip
RUN /tmp/install.sh -i skip

CMD ["/bin/zsh", "-l"]
SHELL ["/bin/zsh", "-lc", "@zi-scheduler burst"]

CMD ["zsh", "-il"]
11 changes: 6 additions & 5 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ build() {
local image_name="${1:-zd}"
local tag="${2:-latest}"
local zsh_version="${3}"
local container_hostname="z-shell"
shift 3

local dockerfile="Dockerfile"
Expand All @@ -35,11 +36,11 @@ build() {
[[ -n ${NO_CACHE} ]] && args+=(--no-cache "$@")

if docker build \
--build-arg "ZUSER=${USER:-$(id -u -n || true)}" \
--build-arg "PUID=${UID:-$(id -u || true)}" \
--build-arg "PGID=${GID:-$(id -g || true)}" \
--build-arg "ZUSER=${USER:-$(id -u -n)}" \
--build-arg "ZHOST=${container_hostname}" \
--build-arg "PUID=${UID:-$(id -u)}" \
--build-arg "PGID=${GID:-$(id -g)}" \
--build-arg "TERM=${TERM:-xterm-256color}" \
--build-arg "HOSTNAME=zi@docker" \
--build-arg "ZI_ZSH_VERSION=${zsh_version}" \
--file "${dockerfile}" \
--tag "${image_name}:${tag}" \
Expand All @@ -55,8 +56,8 @@ build() {
}

if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
BUILD_ZSH_VERSION="${BUILD_ZSH_VERSION-}"
CONTAINER_IMAGE="${CONTAINER_IMAGE:-ghcr.io/z-shell/zd}"
BUILD_ZSH_VERSION="${BUILD_ZSH_VERSION-}"
CONTAINER_TAG="${CONTAINER_TAG:-latest}"
NO_CACHE="${NO_CACHE-}"

Expand Down
7 changes: 6 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ command sed -ir 's#^(root:.+):/bin/ash#\1:/bin/zsh#' /etc/passwd
command adduser -D -s /bin/zsh -u "${PUID}" -h "${HOME}" "${ZUSER}"

command printf '%s' "${ZUSER} ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/user
command mkdir -p /src /data && chown -R "${PUID}:${PGID}" /src /data
command mkdir -p /src /data
command chown -R "${PUID}:${PGID}" /src /data

command wget 'https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh' -qO /tmp/install.sh
command chown "${PUID}:${PGID}" /tmp/install.sh
command chmod u+x /tmp/install.sh

command ln -sfv /src/zshenv "${HOME}/.zshenv"
command ln -sfv /src/zshrc "${HOME}/.zshrc"
Expand Down
8 changes: 4 additions & 4 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
pwd -P
)" || exit 9
# Mount root of the repo to /src
# Mount /tmp/zunit-zd to /data
# Mount /tmp/zunit to /data
CONTAINER_VOLUMES+=(
"${CONTAINER_ROOT}:/src"
"${TMPDIR:-/tmp}/ZZUnit:/data"
"${ROOT_DIR}/zshenv:/home/z-user/.zshenv"
"${ROOT_DIR}/zshrc:/home/z-user/.zshrc"
"${TMPDIR:-/tmp}/zunit:/data"
"${ROOT_DIR}/zshenv:/home/zunit/.zshenv"
"${ROOT_DIR}/zshrc:/home/zunit/.zshrc"
)
CONTAINER_ENV+=(
"QUIET=1"
Expand Down
2 changes: 1 addition & 1 deletion docker/tests/setup.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env zunit

setup() {
export DATA_DIR="${TMPDIR:-/tmp}/ZZUnit"
export DATA_DIR="${TMPDIR:-/tmp}/zunit"
export PLUGINS_DIR="${DATA_DIR}/plugins"
export SNIPPETS_DIR="${DATA_DIR}/snippets"
export ZPFX="${DATA_DIR}/polaris"
Expand Down
39 changes: 22 additions & 17 deletions docker/utils.zsh
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#!/usr/bin/env zsh

zi::prepare() {
# Functions to wrap container setup and initialization.

prepare_system() {
printf '%s\n' "Setting owner of /data to ${PUID}:${PGID}" >&2
sudo chown "${PUID}:${PGID}" /data
sudo chown -R "${PUID}:${PGID}" /data

printf '%s\n' "Copying files from /static to /data" >&2
rsync -raq /static/ /data
}

zi::install() {
sh -c "$(curl -fsSL https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh)" -- -i skip 1&>/dev/null
}
initiate_system() {
typeset -gxU path module_path

zi::module() {
sh -c "$(curl -fsSL https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh)" -- -a zpmod 1&>/dev/null
}
path=("${ZPFX:-${HOME}/.zi/polaris}/bin" "${HOME}/go/bin" $path)
module_path+=( /data/zmodules/zpmod/Src )

zmodload zi/zpmod &>/dev/null

zi::init() {
source ~/.zi/bin/zi.zsh

autoload -Uz _zi
(( ${+_comps} )) && _comps[zi]=_zi
}

zi::reload() {
reload_system() {
local zf1 zf2
for zf1 in ~/.zi/bin/*.zsh; do
source "$zf1"
Expand All @@ -31,6 +34,14 @@ zi::reload() {
done
}

# Functions to wrap Zi commands.

zi::install-zsdoc() {
zi light-mode \
make"PREFIX=$ZPFX install" \
for z-shell/zsdoc
}

zi::setup-keys() {
zi snippet OMZL::key-bindings.zsh
}
Expand All @@ -51,12 +62,6 @@ zi::setup-annexes+add() {
zi light-mode for z-shell/z-a-test
}

zi::install-zsdoc() {
zi light-mode \
make"PREFIX=$ZPFX install" \
for z-shell/zsdoc
}

zi::setup-minimal() {
zi wait lucid light-mode for \
atinit"zicompinit; zicdreplay" \
Expand All @@ -70,5 +75,5 @@ zi::setup-minimal() {
zi::pack-zsh() {
local ZSH_VERSION="$1"
zi pack"$ZSH_VERSION" for zsh
zi pack atload=+"zicompinit; zicdreplay" for system-completions
zi pack atload=+"zicompinit; zicdreplay" for system-completions
}
13 changes: 3 additions & 10 deletions docker/zshrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et

# Prepare and initiate the source tree.
source /src/utils.zsh
zi::prepare; zi::install

typeset -U path module_path
path=("${ZPFX:-${HOME}/.zi/polaris}/bin" "${HOME}/go/bin" $path)
module_path+=( /data/zmodules/zpmod/Src ); zmodload zi/zpmod &>/dev/null

zi::init
prepare_system; initiate_system

# If the ZI_ZSH_VERSION is set will install the specified version of Zsh with Zi.
if [[ -n "$ZI_ZSH_VERSION" ]]; then
if [[ "$ZI_ZSH_VERSION" != "$ZSH_VERSION" ]]; then
zi::pack-zsh "$ZI_ZSH_VERSION"
fi
fi

autoload -Uz _zi
(( ${+_comps} )) && _comps[zi]=_zi

0 comments on commit 55ade14

Please sign in to comment.