From 2a673553f114a606637673bdadaa16d215402af3 Mon Sep 17 00:00:00 2001 From: despiegk Date: Tue, 14 Jan 2025 11:53:28 +0100 Subject: [PATCH] fix hero for git --- cli/hero.v | 2 +- docker/herolib/Dockerfile | 3 +- docker/herolib/debug.sh | 13 ------- docker/herolib/shell.sh | 61 ++++++++++++++++++++++++++++++ docker/herolib/start.sh | 8 ++++ lib/develop/gittools/repos_print.v | 11 +++--- 6 files changed, 78 insertions(+), 20 deletions(-) create mode 100755 docker/herolib/shell.sh diff --git a/cli/hero.v b/cli/hero.v index 20b65edf..d04de408 100644 --- a/cli/hero.v +++ b/cli/hero.v @@ -74,7 +74,7 @@ fn do() ! { // herocmds.cmd_bootstrap(mut cmd) // herocmds.cmd_run(mut cmd) - // herocmds.cmd_git(mut cmd) + herocmds.cmd_git(mut cmd) // herocmds.cmd_init(mut cmd) // herocmds.cmd_imagedownsize(mut cmd) // herocmds.cmd_biztools(mut cmd) diff --git a/docker/herolib/Dockerfile b/docker/herolib/Dockerfile index 5a70bb52..959e5963 100644 --- a/docker/herolib/Dockerfile +++ b/docker/herolib/Dockerfile @@ -14,7 +14,7 @@ COPY scripts/ourinit.sh /usr/local/bin/ RUN chmod +x /tmp/install_v.sh /tmp/install_herolib.vsh RUN apt-get update && apt-get install -y \ - curl bash sudo mc wget tmux + curl bash sudo mc wget tmux htop RUN bash /tmp/install_v.sh @@ -24,6 +24,7 @@ RUN bash /tmp/install_vscode.sh RUN /tmp/install_herolib.vsh && \ apt-get clean && \ + echo "PS1='HERO: \w \$ '" >> ~/.bashrc \ rm -rf /var/lib/apt/lists/* ENTRYPOINT ["/bin/bash"] diff --git a/docker/herolib/debug.sh b/docker/herolib/debug.sh index 132059c9..b0d7f37f 100755 --- a/docker/herolib/debug.sh +++ b/docker/herolib/debug.sh @@ -7,19 +7,6 @@ cd "$SCRIPT_DIR" # Remove any existing container named 'debug' (ignore errors) docker rm -f herolib > /dev/null 2>&1 -# Run the Docker container -# docker run --name herolib -it \ -# --entrypoint="/bin/bash" \ -# -v "${SCRIPT_DIR}/scripts:/scripts" \ -# -v "$HOME/code:/root/code" \ -# -p 4100:8100 \ -# -p 4101:8101 \ -# -p 4102:8102 \ -# -p 4379:6379 \ -# -p 4000:3000 \ -# herolib -c "/usr/local/bin/ourinit.sh && /bin/bash" - - docker run --name herolib -it \ --entrypoint="/usr/local/bin/ourinit.sh" \ -v "${SCRIPT_DIR}/scripts:/scripts" \ diff --git a/docker/herolib/shell.sh b/docker/herolib/shell.sh new file mode 100755 index 00000000..342ef308 --- /dev/null +++ b/docker/herolib/shell.sh @@ -0,0 +1,61 @@ +#!/bin/bash -e + +# Get the directory where the script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPT_DIR" + +CONTAINER_NAME="herolib" +TARGET_PORT=4000 + +# Function to check if a container is running +is_container_running() { + docker ps --filter "name=$CONTAINER_NAME" --filter "status=running" -q +} + +# Function to check if a port is accessible +is_port_accessible() { + nc -zv 127.0.0.1 "$1" &>/dev/null +} + +# Check if the container exists and is running +if ! is_container_running; then + echo "Container $CONTAINER_NAME is not running." + + # Check if the container exists but is stopped + if docker ps -a --filter "name=$CONTAINER_NAME" -q | grep -q .; then + echo "Starting existing container $CONTAINER_NAME..." + docker start "$CONTAINER_NAME" + else + echo "Container $CONTAINER_NAME does not exist. Attempting to start with start.sh..." + if [[ -f "$SCRIPT_DIR/start.sh" ]]; then + bash "$SCRIPT_DIR/start.sh" + else + echo "Error: start.sh not found in $SCRIPT_DIR." + exit 1 + fi + fi + + # Wait for the container to be fully up + sleep 5 +fi + +# Verify the container is running +if ! is_container_running; then + echo "Error: Failed to start container $CONTAINER_NAME." + exit 1 +fi +echo "Container $CONTAINER_NAME is running." + +# Check if the target port is accessible +if is_port_accessible "$TARGET_PORT"; then + echo "Port $TARGET_PORT is accessible." +else + echo "Port $TARGET_PORT is not accessible. Please check the service inside the container." +fi + +# Enter the container +echo +echo " ** WE NOW LOGIN TO THE CONTAINER ** " +echo +docker exec -it herolib bash -c "PS1='HERO: \w \$ ' /bin/bash" + diff --git a/docker/herolib/start.sh b/docker/herolib/start.sh index e69de29b..a584aad7 100644 --- a/docker/herolib/start.sh +++ b/docker/herolib/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# Get the directory where the script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPT_DIR" + + + diff --git a/lib/develop/gittools/repos_print.v b/lib/develop/gittools/repos_print.v index aef85494..44a2689d 100644 --- a/lib/develop/gittools/repos_print.v +++ b/lib/develop/gittools/repos_print.v @@ -48,11 +48,12 @@ pub fn (mut gitstructure GitStructure) repos_print(args ReposGetArgs) ! { console.print_lf(1) // Display header with optional argument filtering information - header := if args.str().len > 0 { - 'Repositories: ${gitstructure.config.coderoot} [${args.str()}]' - } else { - 'Repositories: ${gitstructure.config.coderoot}' - } + // header := if args.str().len > 0 { + // 'Repositories: ${gitstructure.config.coderoot} [${args.str()}]' + // } else { + // 'Repositories: ${gitstructure.config.coderoot}' + // } + header:='Repositories: ${gitstructure.config.coderoot}' console.print_header(header) // Print the repository information in a formatted array