From a1f846e4c89922bcaef1705de2cd17d20d701865 Mon Sep 17 00:00:00 2001 From: Salvydas Lukosius Date: Fri, 27 Oct 2023 07:25:29 +0100 Subject: [PATCH] [WIP] --- .trunk/configs/.hadolint.yaml | 4 ++-- .trunk/trunk.yaml | 6 +++--- docker/Dockerfile | 27 +++++++++++++++++---------- docker/build.sh | 5 +++-- docker/run.sh | 14 +++++++++----- docker/tests/setup.zsh | 2 +- docker/utils.zsh | 2 +- docker/zshenv | 2 +- 8 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.trunk/configs/.hadolint.yaml b/.trunk/configs/.hadolint.yaml index 98bf0cd..b64d07b 100644 --- a/.trunk/configs/.hadolint.yaml +++ b/.trunk/configs/.hadolint.yaml @@ -1,4 +1,4 @@ # Following source doesn't work in most setups ignored: - - SC1090 - - SC1091 + - DL3018 + - SC1071 diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 0d154b1..e94a355 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -8,11 +8,11 @@ plugins: uri: https://github.com/trunk-io/plugins lint: disabled: + - terrascan + - trivy + - checkov - yamllint enabled: - - checkov@2.5.9 - - terrascan@1.18.3 - - trivy@0.46.0 - trufflehog@3.60.4 - actionlint@1.6.26 - git-diff-check diff --git a/docker/Dockerfile b/docker/Dockerfile index 6fb79eb..1e902d0 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,36 +2,43 @@ ARG VERSION=latest FROM alpine:${VERSION} LABEL maintainer="<%= Z-Shell Community %>" LABEL email="<%= team@zshell.dev =%>" +LABEL version="<%= ZI_ZSH_VERSION %>" ARG HOSTNAME=zi@docker -ARG ZUSER=z-user -ARG SHELL=/bin/zsh ARG DIR=/static +ARG SHELL=/bin/zsh + +ARG ZUSER +ARG PUID +ARG PGID +ARG TERM +ARG ZI_ZSH_VERSION ENV ZUSER=${ZUSER} ENV PUID=${PUID} ENV PGID=${PGID} +ENV DIR=${DIR} +ENV TERM=${TERM} 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 \ +jq git libuser rsync zsh ncurses-dev pcre-dev zlib-dev alpine-zsh-config \ && apk --no-cache --virtual zsh-build-tools add autoconf bash build-base go vim -WORKDIR $DIR +WORKDIR ${DIR} COPY . . RUN chmod +x entrypoint.sh && ./entrypoint.sh VOLUME ["/src", "/data"] -COPY --chown=${ZUSER} . /src +COPY --chmod=+x . /src USER ${ZUSER} WORKDIR /home/${ZUSER} +SHELL ["/bin/zsh", "-c"] -RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh)" -- -i skip +RUN curl -fsSLO 'https://raw.githubusercontent.com/z-shell/zi-src/main/lib/sh/install.sh' \ +&& chmod +x install.sh && ./install.sh -i skip -CMD ["/bin/zsh", "-l"] +CMD ["zsh", "-l"] diff --git a/docker/build.sh b/docker/build.sh index 1d1c703..0af2f54 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash +# # -*- mode: bash; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=bash sw=2 ts=2 et +# col_error="" col_info="" @@ -35,11 +37,10 @@ build() { [[ -n ${NO_CACHE} ]] && args+=(--no-cache "$@") if docker build \ - --build-arg "ZUSER=${USER:-$(id -u -n || true)}" \ + --build-arg "ZUSER=user" \ --build-arg "PUID=${UID:-$(id -u || true)}" \ --build-arg "PGID=${GID:-$(id -g || true)}" \ --build-arg "TERM=${TERM:-xterm-256color}" \ - --build-arg "HOSTNAME=zi@docker" \ --build-arg "ZI_ZSH_VERSION=${zsh_version}" \ --file "${dockerfile}" \ --tag "${image_name}:${tag}" \ diff --git a/docker/run.sh b/docker/run.sh index 7f28f72..ac7e74a 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash +# # -*- mode: bash; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=bash sw=2 ts=2 et +# col_error="" col_info="" @@ -153,14 +155,17 @@ if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then CONTAINER_IMAGE="$2" shift 2 ;; + # Set the tag of the container image -t | --tag) CONTAINER_TAG="$2" shift 2 ;; + # Set an environment variable in the container -e | --env | --environment) CONTAINER_ENV+=("$2") shift 2 ;; + # Mount a volume into the container -v | --volume) CONTAINER_VOLUMES+=("$2") shift 2 @@ -170,6 +175,7 @@ if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then WRAP_CMD=1 shift ;; + # Whether to run zd with zunit --tests | --zunit | -z) ZUNIT=1 shift @@ -205,13 +211,11 @@ if [[ ${BASH_SOURCE[0]} == "${0}" ]]; then cd -P -- "$(dirname "$0")" pwd -P )" || exit 9 - # Mount root of the repo to /src - # Mount /tmp/zunit-zd 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}/runtime_data:/data" + "${ROOT_DIR}/zshenv:/home/user/.zshenv" + "${ROOT_DIR}/zshrc:/home/user/.zshrc" ) CONTAINER_ENV+=( "QUIET=1" diff --git a/docker/tests/setup.zsh b/docker/tests/setup.zsh index d7176af..7f433c7 100755 --- a/docker/tests/setup.zsh +++ b/docker/tests/setup.zsh @@ -1,7 +1,7 @@ #!/usr/bin/env zunit setup() { - export DATA_DIR="${TMPDIR:-/tmp}/ZZUnit" + export DATA_DIR="${TMPDIR:-/tmp}/runtime_data" export PLUGINS_DIR="${DATA_DIR}/plugins" export SNIPPETS_DIR="${DATA_DIR}/snippets" export ZPFX="${DATA_DIR}/polaris" diff --git a/docker/utils.zsh b/docker/utils.zsh index e084046..487ca61 100755 --- a/docker/utils.zsh +++ b/docker/utils.zsh @@ -70,5 +70,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 } diff --git a/docker/zshenv b/docker/zshenv index fed16b8..3cbca43 100755 --- a/docker/zshenv +++ b/docker/zshenv @@ -5,6 +5,6 @@ export TERM=${TERM:-xterm-256color} export SHELL=${SHELL:-${commands[zsh]}} typeset -Ag ZI + export ZI[HOME_DIR]=${ZI_HOME_DIR:-/data} export ZI[BIN_DIR]=${ZI_BIN_DIR:-$HOME/.zi/bin} -