Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
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
438 changes: 415 additions & 23 deletions README.md

Large diffs are not rendered by default.

691 changes: 691 additions & 0 deletions devcontainer/devrd

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions devcontainer/setup-container
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

set -e

# Function to install devcontainer template
install_devcontainer() {
echo "🚀 Installing EVerest DevContainer Template"
echo "=========================================="

read -p "Enter the workspace directory (default is the current directory): " WORKSPACE_DIR
if [ -z "$WORKSPACE_DIR" ]; then
WORKSPACE_DIR="./"
fi
WORKSPACE_DIR=$(realpath -m "$WORKSPACE_DIR")

read -p "Enter the version of the everest-dev-environment (default is 'main'): " VERSION
if [ -z "$VERSION" ]; then
VERSION="main"
fi

echo "Create the workspace directory '$WORKSPACE_DIR' if it does not exist"
mkdir -p $WORKSPACE_DIR

# Check if workspace directory has files other than everest-dev-environment
WORKSPACE_CONTENTS=$(ls -A $WORKSPACE_DIR 2>/dev/null | grep -v "^everest-dev-environment$" || true)
if [ -n "$WORKSPACE_CONTENTS" ]; then
# The workspace directory is not empty (excluding everest-dev-environment), warning do you want to continue?
read -p "The workspace directory is not empty, do you want to continue? (y/N): " -r
case "$REPLY" in
[Nn]|"")
echo "Exiting.."
exit 1
;;
[Yy])
;;
*)
echo "Invalid input. Exiting.."
exit 1
;;
esac
fi

# Check if everest-dev-environment exists locally
if [ -d "everest-dev-environment" ]; then
echo "Found local everest-dev-environment directory, using it instead of cloning..."
SOURCE_DIR="everest-dev-environment"
else
echo "No local everest-dev-environment found, cloning from GitHub..."
TMP_DIR=$(mktemp --directory)
git clone --quiet --depth 1 --single-branch --branch "$VERSION" https://github.com/EVerest/everest-dev-environment.git "$TMP_DIR"
SOURCE_DIR="$TMP_DIR"
fi

echo "Copy the template devcontainer configuration files to the workspace directory"
cp -n -r $SOURCE_DIR/devcontainer/template/. $WORKSPACE_DIR/

# Ensure devrd script is executable
if [ -f "$WORKSPACE_DIR/devrd" ]; then
chmod +x "$WORKSPACE_DIR/devrd"
echo "✓ DevRD script installed and made executable"
else
echo "✖ Warning: DevRD script not found after installation"
fi

# Only remove temporary directory if we cloned it
if [ "$SOURCE_DIR" != "everest-dev-environment" ]; then
echo "Remove the temporary everest-dev-environment repository"
rm -rf "$SOURCE_DIR"
fi

echo "DevContainer template installation complete!"
echo "Files installed to: $WORKSPACE_DIR"
echo ""
echo "Installed components:"
echo " ✓ Dev Yard script (./devrd)"
echo " ✓ DevContainer configuration (.devcontainer/)"
echo " ✓ Shell completion (devrd-completion.bash/.zsh)"
echo ""
echo "Next steps:"
echo " cd $WORKSPACE_DIR"
echo " ./devrd env"
echo " ./devrd build"
echo " ./devrd start"
echo " ./devrd prompt"
echo ""
echo "Optional - Enable command completion:"
echo " Add to your shell configuration file:"
echo " • For bash: Add 'source .devcontainer/devrd-completion.bash' to ~/.bashrc"
echo " • For zsh: Add 'source .devcontainer/devrd-completion.zsh' to ~/.zshrc"
echo " • For zsh: Also ensure completion is enabled: 'autoload -U compinit && compinit'"
}

# Function to display help
show_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "This script installs the EVerest DevContainer template to a workspace."
echo ""
echo "Installed components:"
echo " • DevRD script (./devrd) - Main development environment manager"
echo " • DevContainer configuration (.devcontainer/) - VS Code container config"
echo " • Shell completion (devrd-completion.bash/.zsh) - Command completion for bash/zsh"
echo ""
echo "After installation:"
echo " 1. cd to your workspace directory"
echo " 2. Run './devrd env' to generate .env file"
echo " 3. Run './devrd build' to build containers"
echo " 4. Run './devrd start' to start services"
echo " 5. Run './devrd prompt' to get shell access"
echo ""
echo "Optional - Enable command completion:"
echo " Add to your shell configuration file:"
echo " • For bash: Add 'source .devcontainer/devrd-completion.bash' to ~/.bashrc"
echo " • For zsh: Add 'source .devcontainer/devrd-completion.zsh' to ~/.zshrc"
echo " • For zsh: Also ensure completion is enabled: 'autoload -U compinit && compinit'"
echo ""
echo "Options:"
echo " --help Display this help message"
echo ""
echo "Examples:"
echo " $0 # Install DevContainer template to workspace"
echo ""
echo "After installation, use './devrd' to manage the development environment."
exit 0
}

# Parse command line arguments
while [ $# -gt 0 ]; do
case $1 in
--help)
show_help
;;
*)
echo "Unknown option: $1"
show_help
;;
esac
done

# Execute the installation
install_devcontainer
39 changes: 0 additions & 39 deletions devcontainer/setup-devcontainer.sh

This file was deleted.

96 changes: 96 additions & 0 deletions devcontainer/template/.devcontainer/devrd-completion.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# Bash completion for devrd script
# Source this file or add to your .bashrc to enable completion

_devrd_completion() {
local cur prev opts cmds
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

# Available commands
cmds="install env build start stop prompt purge exec flows flow"

# Available options
opts="-v --version -w --workspace --help"

# Function to get available Node-RED flows dynamically
_get_nodered_flows() {
# Get the current project name (same logic as devrd script)
local project_name="${DOCKER_COMPOSE_PROJECT_NAME:-$(basename "$(pwd)")_devcontainer}"

# Check if we're in the right directory and container is running
if [ -f "devrd" ] && docker compose -p "$project_name" -f .devcontainer/docker-compose.yml -f .devcontainer/general-devcontainer/docker-compose.devcontainer.yml ps devcontainer | grep -q "Up"; then
# Get flows from the container and return full paths (relative to workspace)
docker compose -p "$project_name" -f .devcontainer/docker-compose.yml -f .devcontainer/general-devcontainer/docker-compose.devcontainer.yml exec -T devcontainer find /workspace -name "*-flow.json" -type f 2>/dev/null | sed 's|/workspace/||' | sort
else
# Fallback to common flow file paths
echo "everest-core/config/nodered/config-sil-dc-flow.json"
echo "everest-core/config/nodered/config-sil-dc-bpt-flow.json"
echo "everest-core/config/nodered/config-sil-energy-management-flow.json"
echo "everest-core/config/nodered/config-sil-two-evse-flow.json"
echo "everest-core/config/nodered/config-sil-flow.json"
fi
}

# Function to get available container names
_get_container_names() {
echo "mqtt ocpp sil"
}

# If the previous word is an option that takes an argument, complete based on the option
case "$prev" in

-v|--version)
# Complete with common version patterns
COMPREPLY=( $(compgen -W "main master develop release/1.0 release/1.1" -- "$cur") )
return 0
;;
-w|--workspace)
# Complete directories
COMPREPLY=( $(compgen -d -- "$cur") )
return 0
;;
flow)
# Complete with available flow file paths dynamically
local flows
flows=$(_get_nodered_flows)
COMPREPLY=( $(compgen -W "$flows" -- "$cur") )
return 0
;;
start|stop)
# Complete with available container names
local containers
containers=$(_get_container_names)
COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
return 0
;;
exec)
# For exec command, complete with common commands
COMPREPLY=( $(compgen -W "ls pwd cd cmake ninja make" -- "$cur") )
return 0
;;
esac

# If we're completing the first word (command), show commands
if [ $COMP_CWORD -eq 1 ]; then

Check warning on line 77 in devcontainer/template/.devcontainer/devrd-completion.bash

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

devcontainer/template/.devcontainer/devrd-completion.bash#L77

Double quote to prevent globbing and word splitting.
COMPREPLY=( $(compgen -W "$cmds" -- "$cur") )
return 0
fi

# If we're completing an option, show options
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
return 0
fi

# For other cases, complete with files/directories
COMPREPLY=( $(compgen -f -- "$cur") )
return 0
}

# Register the completion function
complete -F _devrd_completion devrd
complete -F _devrd_completion ./devrd
complete -F _devrd_completion ../devrd
89 changes: 89 additions & 0 deletions devcontainer/template/.devcontainer/devrd-completion.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/zsh

# Zsh completion for devrd script
# Source this file or add to your .zshrc to enable completion

_devrd_completion() {
local context state line
typeset -A opt_args

# Available commands
local commands=(
'env:Generate .env file with repository information'
'build:Build the development container'
'start:Start containers (profiles: mqtt, ocpp, sil)'
'stop:Stop containers (profiles: mqtt, ocpp, sil)'
'purge:Remove all devcontainer resources (containers, images, volumes)'
'exec:Execute a command in the container'
'prompt:Get a shell prompt in the container'
'flows:List available flows'
'flow:Switch to specific flow file'
)

# Available options
local options=(
'-v[Everest tool branch]:version:'
'--version[Everest tool branch]:version:'
'-w[Workspace directory]:directory:_files -/'
'--workspace[Workspace directory]:directory:_files -/'
'--help[Display help message]'
)

# Function to get available Node-RED flows dynamically
_get_nodered_flows() {
# Get the current project name (same logic as devrd script)
local project_name="${DOCKER_COMPOSE_PROJECT_NAME:-$(basename "$(pwd)")_devcontainer}"

# Check if we're in the right directory and container is running
if [ -f "devrd" ] && docker compose -p "$project_name" -f .devcontainer/docker-compose.yml -f .devcontainer/general-devcontainer/docker-compose.devcontainer.yml ps devcontainer | grep -q "Up"; then
# Get flows from the container and return full paths (relative to workspace)
docker compose -p "$project_name" -f .devcontainer/docker-compose.yml -f .devcontainer/general-devcontainer/docker-compose.devcontainer.yml exec -T devcontainer find /workspace -name "*-flow.json" -type f 2>/dev/null | sed 's|/workspace/||' | sort
else
# Fallback to common flow file paths
echo "everest-core/config/nodered/config-sil-dc-flow.json"
echo "everest-core/config/nodered/config-sil-dc-bpt-flow.json"
echo "everest-core/config/nodered/config-sil-energy-management-flow.json"
echo "everest-core/config/nodered/config-sil-two-evse-flow.json"
echo "everest-core/config/nodered/config-sil-flow.json"
fi
}

# Function to get available container names
_get_container_names() {
echo "mqtt ocpp sil"
}

# Main completion logic
_arguments -C \
"$options[@]" \
"1: :{_describe 'commands' commands}" \
"*::arg:->args"

case $state in
args)
case $line[1] in
flow)
_values 'flow files' $(_get_nodered_flows)
;;
start|stop)
_values 'profiles' $(_get_container_names)
;;
exec)
_values 'commands' 'ls' 'pwd' 'cd' 'cmake' 'ninja' 'make'
;;
purge)
_files
;;
esac
;;
esac
}

# Register the completion function
if command -v compdef >/dev/null 2>&1; then
compdef _devrd_completion devrd
compdef _devrd_completion ./devrd
compdef _devrd_completion ../devrd
else
echo "Warning: zsh completion system not loaded. Add 'autoload -U compinit && compinit' to your .zshrc"
fi
Loading