diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b40a3d1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,39 @@ +# This is only used for developing the zsh-in-docker script, but can be used as an example. + +FROM debian:latest + +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && apt-get update \ + && apt-get install -y sudo wget \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + # + # Clean up + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +USER $USERNAME + +# RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \ +COPY zsh-in-docker.sh /tmp +RUN /tmp/zsh-in-docker.sh \ + -t https://github.com/denysdovhan/spaceship-prompt \ + -a 'SPACESHIP_PROMPT_ADD_NEWLINE="false"' \ + -a 'SPACESHIP_PROMPT_SEPARATE_LINE="false"' \ + -p git \ + -p https://github.com/zsh-users/zsh-autosuggestions \ + -p https://github.com/zsh-users/zsh-completions \ + -p https://github.com/zsh-users/zsh-history-substring-search \ + -p https://github.com/zsh-users/zsh-syntax-highlighting \ + -p 'history-substring-search' \ + -a 'bindkey "\$terminfo[kcuu1]" history-substring-search-up' \ + -a 'bindkey "\$terminfo[kcud1]" history-substring-search-down' + +ENTRYPOINT [ "/bin/zsh" ] +CMD ["-l"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2fec915..c3669ad 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,4 @@ -// More info: https://containers.dev/implementors/json_reference/ { - "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bullseye", - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {} - }, - "customizations": { - "vscode": { - "extensions": [ - "mads-hartmann.bash-ide-vscode", - "dbaeumer.vscode-eslint" - ] - } - }, - "postCreateCommand": "npm install -g @devcontainers/cli" + "name": "my-project-devcontainer", + "image": "ghcr.io/bayt-al-hiqma/dev:latest" } diff --git a/.devcontainer/zsh-in-docker.sh b/.devcontainer/zsh-in-docker.sh new file mode 100755 index 0000000..c20c760 --- /dev/null +++ b/.devcontainer/zsh-in-docker.sh @@ -0,0 +1,183 @@ +#!/bin/sh + +####################################################################################################### +# MIT License (MIT) +# Copyright 2019 Deluan Quintao +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +# associated documentation files (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, publish, distribute, +# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or +# substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +####################################################################################################### + +set -e + +THEME=default +PLUGINS="" +ZSHRC_APPEND="" +INSTALL_DEPENDENCIES=true + +while getopts ":t:p:a:x" opt; do + case ${opt} in + t) THEME=$OPTARG + ;; + p) PLUGINS="${PLUGINS}$OPTARG " + ;; + a) ZSHRC_APPEND="$ZSHRC_APPEND\n$OPTARG" + ;; + x) INSTALL_DEPENDENCIES=false + ;; + \?) + echo "Invalid option: $OPTARG" 1>&2 + ;; + :) + echo "Invalid option: $OPTARG requires an argument" 1>&2 + ;; + esac +done +shift $((OPTIND -1)) + +echo +echo "Installing Oh-My-Zsh with:" +echo " THEME = $THEME" +echo " PLUGINS = $PLUGINS" +echo + +check_dist() { + ( + . /etc/os-release + echo "$ID" + ) +} + +check_version() { + ( + . /etc/os-release + echo "$VERSION_ID" + ) +} + +install_dependencies() { + DIST=$(check_dist) + VERSION=$(check_version) + echo "###### Installing dependencies for $DIST" + + if [ "$(id -u)" = "0" ]; then + Sudo='' + elif which sudo; then + Sudo='sudo' + else + echo "WARNING: 'sudo' command not found. Skipping the installation of dependencies. " + echo "If this fails, you need to do one of these options:" + echo " 1) Install 'sudo' before calling this script" + echo "OR" + echo " 2) Install the required dependencies: git curl zsh" + return + fi + + case $DIST in + alpine) + $Sudo apk add --update --no-cache git curl zsh + ;; + amzn) + $Sudo yum update -y + $Sudo yum install -y git zsh + $Sudo yum install -y ncurses-compat-libs # this is required for AMZN Linux (ref: https://github.com/emqx/emqx/issues/2503) + ;; + *) + $Sudo apt-get update + $Sudo apt-get -y install git curl zsh locales + if [ "$VERSION" != "14.04" ]; then + $Sudo apt-get -y install locales-all + fi + $Sudo locale-gen en_US.UTF-8 + esac +} + +zshrc_template() { + _HOME=$1; + _THEME=$2; shift; shift + _PLUGINS=$*; + + if [ "$_THEME" = "default" ]; then + _THEME="powerlevel10k/powerlevel10k" + fi + + cat < "$HOME"/.zshrc + +# Install powerlevel10k if no other theme was specified +if [ "$THEME" = "default" ]; then + git clone --depth 1 https://github.com/romkatv/powerlevel10k "$HOME"/.oh-my-zsh/custom/themes/powerlevel10k + powerline10k_config >> "$HOME"/.zshrc +fi diff --git a/.github/actions/smoke-test/action.yaml b/.github/actions/smoke-test/action.yaml deleted file mode 100644 index 5f98ba8..0000000 --- a/.github/actions/smoke-test/action.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: 'Smoke test' -inputs: - template: - description: 'Template to test' - required: true - -runs: - using: composite - steps: - - name: Checkout main - id: checkout_release - uses: actions/checkout@v3 - - - name: Build template - id: build_template - shell: bash - run: ${{ github.action_path }}/build.sh ${{ inputs.template }} - - - name: Test template - id: test_template - shell: bash - run: ${{ github.action_path }}/test.sh ${{ inputs.template }} \ No newline at end of file diff --git a/.github/actions/smoke-test/build.sh b/.github/actions/smoke-test/build.sh deleted file mode 100755 index a5b90eb..0000000 --- a/.github/actions/smoke-test/build.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -TEMPLATE_ID="$1" - -set -e - -shopt -s dotglob - -SRC_DIR="/tmp/${TEMPLATE_ID}" -cp -R "src/${TEMPLATE_ID}" "${SRC_DIR}" - -pushd "${SRC_DIR}" - -# Configure templates only if `devcontainer-template.json` contains the `options` property. -OPTION_PROPERTY=( $(jq -r '.options' devcontainer-template.json) ) - -if [ "${OPTION_PROPERTY}" != "" ] && [ "${OPTION_PROPERTY}" != "null" ] ; then - OPTIONS=( $(jq -r '.options | keys[]' devcontainer-template.json) ) - - if [ "${OPTIONS[0]}" != "" ] && [ "${OPTIONS[0]}" != "null" ] ; then - echo "(!) Configuring template options for '${TEMPLATE_ID}'" - for OPTION in "${OPTIONS[@]}" - do - OPTION_KEY="\${templateOption:$OPTION}" - OPTION_VALUE=$(jq -r ".options | .${OPTION} | .default" devcontainer-template.json) - - if [ "${OPTION_VALUE}" = "" ] || [ "${OPTION_VALUE}" = "null" ] ; then - echo "Template '${TEMPLATE_ID}' is missing a default value for option '${OPTION}'" - exit 1 - fi - - echo "(!) Replacing '${OPTION_KEY}' with '${OPTION_VALUE}'" - OPTION_VALUE_ESCAPED=$(sed -e 's/[]\/$*.^[]/\\&/g' <<<"${OPTION_VALUE}") - find ./ -type f -print0 | xargs -0 sed -i "s/${OPTION_KEY}/${OPTION_VALUE_ESCAPED}/g" - done - fi -fi - -popd - -TEST_DIR="test/${TEMPLATE_ID}" -if [ -d "${TEST_DIR}" ] ; then - echo "(*) Copying test folder" - DEST_DIR="${SRC_DIR}/test-project" - mkdir -p ${DEST_DIR} - cp -Rp ${TEST_DIR}/* ${DEST_DIR} - cp test/test-utils/test-utils.sh ${DEST_DIR} -fi - -export DOCKER_BUILDKIT=1 -echo "(*) Installing @devcontainer/cli" -npm install -g @devcontainers/cli - -echo "Building Dev Container" -ID_LABEL="test-container=${TEMPLATE_ID}" -devcontainer up --id-label ${ID_LABEL} --workspace-folder "${SRC_DIR}" diff --git a/.github/actions/smoke-test/test.sh b/.github/actions/smoke-test/test.sh deleted file mode 100755 index 5de1a2c..0000000 --- a/.github/actions/smoke-test/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -TEMPLATE_ID="$1" -set -e - -SRC_DIR="/tmp/${TEMPLATE_ID}" -echo "Running Smoke Test" - -ID_LABEL="test-container=${TEMPLATE_ID}" -devcontainer exec --workspace-folder "${SRC_DIR}" --id-label ${ID_LABEL} /bin/sh -c 'set -e && if [ -f "test-project/test.sh" ]; then cd test-project && if [ "$(id -u)" = "0" ]; then chmod +x test.sh; else sudo chmod +x test.sh; fi && ./test.sh; else ls -a; fi' - -# Clean up -docker rm -f $(docker container ls -f "label=${ID_LABEL}" -q) -rm -rf "${SRC_DIR}" diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml deleted file mode 100644 index 778bed4..0000000 --- a/.github/workflows/test-pr.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: "CI - Test Templates" -on: - pull_request: - -jobs: - detect-changes: - runs-on: ubuntu-latest - outputs: - templates: ${{ steps.filter.outputs.changes }} - steps: - - uses: dorny/paths-filter@v2 - id: filter - with: - filters: | - color: ./**/color/** - hello: ./**/hello/** - - test: - needs: [detect-changes] - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - templates: ${{ fromJSON(needs.detect-changes.outputs.templates) }} - steps: - - uses: actions/checkout@v3 - - - name: Smoke test for '${{ matrix.templates }}' - id: smoke_test - uses: ./.github/actions/smoke-test - with: - template: "${{ matrix.templates }}" diff --git a/src/color/.devcontainer/devcontainer.json b/src/color/.devcontainer/devcontainer.json deleted file mode 100644 index 0c20573..0000000 --- a/src/color/.devcontainer/devcontainer.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "Favorite color", - "image": "mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant}", - - // ๐Ÿ‘‡ Features to add to the Dev Container. More info: https://containers.dev/implementors/features. - // "features": {}, - - // ๐Ÿ‘‡ Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - "postCreateCommand": "echo '${templateOption:favorite}' > /tmp/color.txt" - - // ๐Ÿ‘‡ Configure tool-specific properties. - // "customizations": {}, - - // ๐Ÿ‘‡ Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/src/color/README.md b/src/color/README.md deleted file mode 100644 index a329dff..0000000 --- a/src/color/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# My Favorite Color (color) - -A Template to remind you of your favorite color - -## Options - -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| imageVariant | Debian version (use bullseye on local arm64/Apple Silicon): | string | bullseye | -| favorite | Choose your favorite color. | string | red | - - - ---- - -_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/devcontainers/template-starter/blob/main/src/color/devcontainer-template.json). Add additional notes to a `NOTES.md`._ diff --git a/src/color/devcontainer-template.json b/src/color/devcontainer-template.json deleted file mode 100644 index a64d31c..0000000 --- a/src/color/devcontainer-template.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "id": "color", - "version": "1.0.0", - "name": "My Favorite Color", - "description": "A Template to remind you of your favorite color", - "documentationURL": "https://github.com/devcontainers/template-starter/tree/main/src/color", - "licenseURL": "https://github.com/devcontainers/template-starter/blob/main/LICENSE", - "options": { - "imageVariant": { - "type": "string", - "description": "Debian version (use bullseye on local arm64/Apple Silicon):", - "proposals": [ - "bullseye", - "buster" - ], - "default": "bullseye" - }, - "favorite": { - "type": "string", - "description": "Choose your favorite color.", - "proposals": [ - "red", - "gold", - "green" - ], - "default": "red" - } - }, - "platforms": [ - "Any" - ] -} diff --git a/src/hello/.devcontainer/Dockerfile b/src/hello/.devcontainer/Dockerfile deleted file mode 100644 index 9c45c4c..0000000 --- a/src/hello/.devcontainer/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM mcr.microsoft.com/devcontainers/base:${templateOption:imageVariant} - -RUN mkdir -p /usr/local/etc \ - && echo "${templateOption:greeting}" > /usr/local/etc/greeting.txt \ No newline at end of file diff --git a/src/hello/.devcontainer/devcontainer.json b/src/hello/.devcontainer/devcontainer.json deleted file mode 100644 index fc33f83..0000000 --- a/src/hello/.devcontainer/devcontainer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "Hello, World", - "build": { - "dockerfile": "Dockerfile" - }, - - // ๐Ÿ‘‡ Features to add to the Dev Container. More info: https://containers.dev/implementors/features. - // "features": {}, - - // ๐Ÿ‘‡ Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // ๐Ÿ‘‡ Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "cat /usr/local/etc/greeting.txt" - - // ๐Ÿ‘‡ Configure tool-specific properties. - // "customizations": {}, - - // ๐Ÿ‘‡ Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/src/hello/README.md b/src/hello/README.md deleted file mode 100644 index 2cdac8f..0000000 --- a/src/hello/README.md +++ /dev/null @@ -1,17 +0,0 @@ - -# Hello, World (hello) - -A hello world Template - -## Options - -| Options Id | Description | Type | Default Value | -|-----|-----|-----|-----| -| imageVariant | Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): | string | jammy | -| greeting | Select a pre-made greeting, or enter your own | string | hey | - - - ---- - -_Note: This file was auto-generated from the [devcontainer-template.json](https://github.com/devcontainers/template-starter/blob/main/src/hello/devcontainer-template.json). Add additional notes to a `NOTES.md`._ diff --git a/src/hello/devcontainer-template.json b/src/hello/devcontainer-template.json deleted file mode 100644 index 342c75e..0000000 --- a/src/hello/devcontainer-template.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "id": "hello", - "version": "1.0.0", - "name": "Hello, World", - "description": "A hello world Template", - "documentationURL": "https://github.com/devcontainers/template-starter/tree/main/src/hello", - "licenseURL": "https://github.com/devcontainers/template-starter/blob/main/LICENSE", - "options": { - "imageVariant": { - "type": "string", - "description": "Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon):", - "proposals": [ - "jammy", - "focal", - "bionic" - ], - "default": "jammy" - }, - "greeting": { - "type": "string", - "description": "Select a pre-made greeting, or enter your own", - "proposals": [ - "hey", - "hello", - "hi", - "howdy" - ], - "default": "hey" - } - }, - "platforms": [ - "Any" - ] -} diff --git a/test/color/test.sh b/test/color/test.sh deleted file mode 100644 index b75ba5b..0000000 --- a/test/color/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Template specific tests -check "distro" lsb_release -c -check "color" [ $(cat /tmp/color.txt | grep red) ] - -# Report result -reportResults diff --git a/test/hello/test.sh b/test/hello/test.sh deleted file mode 100644 index 0428c34..0000000 --- a/test/hello/test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -cd $(dirname "$0") -source test-utils.sh - -# Template specific tests -check "distro" lsb_release -c -check "greeting" [ $(cat /usr/local/etc/greeting.txt | grep hey) ] - -# Report result -reportResults diff --git a/test/test-utils/test-utils.sh b/test/test-utils/test-utils.sh deleted file mode 100644 index 5e4b4ae..0000000 --- a/test/test-utils/test-utils.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -FAILED=() - -echoStderr() -{ - echo "$@" 1>&2 -} - -check() { - LABEL=$1 - shift - echo -e "\n๐Ÿงช Testing $LABEL" - if "$@"; then - echo "โœ… Passed!" - return 0 - else - echoStderr "โŒ $LABEL check failed." - FAILED+=("$LABEL") - return 1 - fi -} - -reportResults() { - if [ ${#FAILED[@]} -ne 0 ]; then - echoStderr -e "\n๐Ÿ’ฅ Failed tests: ${FAILED[@]}" - exit 1 - else - echo -e "\n๐Ÿ’ฏ All passed!" - exit 0 - fi -}