legrego / homeassistant-elasticsearch

Publish Home-Assistant events to Elasticsearch
https://legrego.github.io/homeassistant-elasticsearch/
MIT License
145 stars 38 forks source link

Utilize docker for ES components #231

Closed strawgate closed 2 months ago

strawgate commented 2 months ago

Utilize docker to run elasticsearch and kibana for testing.

github-actions[bot] commented 2 months ago

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
elasticsearch
   __init__.py84297%204–205
   config_flow.py2713088%87, 130, 238, 308, 331, 369, 406, 447–450, 452–453, 455, 457–459, 461–462, 476–477, 481, 521, 527, 537, 567, 642, 651, 695–696
   const.py310100% 
   entity_details.py330100% 
   errors.py28389%51, 60, 67
   es_doc_creator.py1690100% 
   es_doc_publisher.py2321593%97, 213–214, 230–231, 320, 410–411, 413–414, 416–420
   es_gateway.py1002080%82–83, 98, 102, 118–120, 122, 124–125, 127–131, 133–137
   es_index_manager.py1081189%195–200, 208–209, 223–224, 244
   es_integration.py37294%43–44
   es_privilege_check.py500100% 
   es_serializer.py100100% 
   es_version.py220100% 
   logger.py20100% 
   system_info.py17194%23
   utils.py40100% 
TOTAL11988492% 

Tests Skipped Failures Errors Time
92 0 :zzz: 0 :x: 0 :fire: 6.495s :stopwatch:
strawgate commented 2 months ago

Fixes https://github.com/legrego/homeassistant-elasticsearch/issues/230

strawgate commented 2 months ago

Example for 8.7.0

sudo /bin/bash ./run_ek_8_7_0
Performing Environment Clean-up
- Stopping and removing container kb01
- Stopping and removing container es01
- Removing network elastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 8.7.0 took 1 seconds
- Pulling Kibana image for 8.7.0 took 0 seconds
Starting Elasticsearch and Kibana
- Wait for Elasticsearch (5ea701590bd92401faf11cdd00741e62c6887afc511b44fd40faee720a196d54) to be ready............. (took 12 seconds)
Configuring Elasticsearch:
- Resetting elastic user account password
- Generating an Enrollment Token for Kibana
Configuring Kibana:
- Wait for Kibana (c5e7434d9474ac650d1f9e6dfda5ee58923a9eb0cea4c4040218e408a7cf7f99) to be ready. (took 0 seconds)
- Enrolling Kibana
Configuring HASS Access:
- Wait for Elasticsearch (5ea701590bd92401faf11cdd00741e62c6887afc511b44fd40faee720a196d54) cluster to be green (took 0 seconds)
- Creating a role for Home Assistant
- Creating a user for Home Assistant

---Ready to use!---
Elasticsearch
  Url: https://localhost:9200
  User: elastic
  Password: dHtygB+f43RV8aipm9hz

  User: hass_writer
  Password: changeme

Kibana
  Url: http://localhost:5601
  User: elastic
  Password: dHtygB+f43RV8aipm9hz

Setup Information
  Version: 8.7.0
  Setup Code: 912361
  Enrollment Token: eyJ2ZXIiOiI4LjcuMCIsImFkciI6WyIxNzIuMjguMC4yOjkyMDAiXSwiZmdyIjoiNGQ2ZTkxZGUyYTY2NmE5YTdjZGM5Yzg5ODE1NDk4NDk3MmFmYTViOWRjYWFkNjA2MjNlMjdlYTJmY2NiZjFmZCIsImtleSI6IlczNElnWTRCajhmeUpGOExyZFRKOmYtcEJYUWxwVDFXa19oWHU3Z0t5Y0EifQ==
  Containers: 5ea701590bd92401faf11cdd00741e62c6887afc511b44fd40faee720a196d54 c5e7434d9474ac650d1f9e6dfda5ee58923a9eb0cea4c4040218e408a7cf7f99
  Duration: 26 seconds

Example for 7.10.0

sudo /bin/bash ./run_ek_7_10_0
Performing Environment Clean-up
- Stopping and removing container kb01
- Stopping and removing container es01
- Removing network elastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 7.10.0 took 0 seconds
- Pulling Kibana image for 7.10.0 took 1 seconds
Starting Elasticsearch and Kibana
Configuring Elasticsearch:
- Wait for Elasticsearch (a0478c8649e9cb6a7fe101a932ae67c7d1344455e5f86c0f571d8e9ab84893ea) to be ready........ (took 7 seconds)
Configuring Kibana:
- Wait for Kibana (2010f527a679540e40fc952d94587d2c7f6eb3d72ebc84b149eb72c309ffc4a8) to be ready.... (took 3 seconds)

---Ready to use!---
Elasticsearch
  Url: http://localhost:9200
  Unauthenticated Access

Kibana
  Url: http://localhost:5601
  Unauthenticated Access

Setup Information
  Version: 7.10.0
  Containers: a0478c8649e9cb6a7fe101a932ae67c7d1344455e5f86c0f571d8e9ab84893ea 2010f527a679540e40fc952d94587d2c7f6eb3d72ebc84b149eb72c309ffc4a8
  Duration: 12 seconds
legrego commented 2 months ago

Integration elasticsearch - /github/workspace/custom_components/elasticsearch: Error: R] [SERVICES] Service publish_events has no icon in icons.json.

Error: Process completed with exit code 1.

Hmm, I wonder if your last commit was unlucky enough to get an updated set of hassfest validations. In any event, this is complaining about a service that we define, but for which we don't have an icon.

The actual issue is worse: we declare this service, but I'm pretty sure we (I) dropped the implementation for this a while back.

real-time update: Yep, I removed this a while back: https://github.com/legrego/homeassistant-elasticsearch/pull/103.

I think the simplest thing is to remove the custom_components/elasticsearch/services.yaml file from this repo. It defines a service that we don't actually offer.

legrego commented 2 months ago

Opened https://github.com/legrego/homeassistant-elasticsearch/pull/243 to drop this file

strawgate commented 2 months ago

Have you been able to debug the component in vscode? I haven't except for the tests, I may try to spend some time trying to figure out how to debug interactively

legrego commented 2 months ago

Have you been able to debug the component in vscode? I haven't except for the tests, I may try to spend some time trying to figure out how to debug interactively

No, I've only done the painful "Add log statements and reboot Home Assistant" debug loop.

legrego commented 2 months ago

This might prove useful:

strawgate commented 2 months ago

Given how much easier this makes testing ES versions and given how much testing on ES versions I need to do for my other PR, perhaps this can merge before I fix hass debugging?

strawgate commented 2 months ago

I believe this is ready to go

legrego commented 2 months ago

Awesome, I'll prioritize reviewing this first.

strawgate commented 2 months ago

Will take a look with another fresh dev environment today, out of curiosity, what host platform are you using for development?

legrego commented 2 months ago

I am running MacOS Sonoma 14.4.1

strawgate commented 2 months ago

Okay should be working now.

Note, you may have to manually go into the ports tab image

and remove stale entries for 5601 and 9200 for this to work

legrego commented 2 months ago

That's much better, I'm able to start both Kibana and ES. I'm still testing, but I notice some peculiar output for the ES and Kibana passwords:

Password: source/workspaces/homeassistant-elasticsearch/.venv/bin/activatev3j0TIs7Aku-i2ULfV_K

It should be:

Password: v3j0TIs7Aku-i2ULfV_K

 *  Executing task: /bin/bash ./scripts/run_ek_8_13_0 

Performing Environment Clean-up
source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
- Removing network elasticelasticelastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 8.13.0 took 1 seconds
- Pulling Kibana image for 8.13.0 took 1 seconds
Starting Elasticsearch and Kibana
- Wait for Elasticsearch (69bd5d66c5d9e059d1b2e965fe4ebf945564bc0518982447af3b0396f80c219c) to be ready.................... (took 19 seconds)
Configuring Elasticsearch:
- Resetting elastic user account password
- Generating an Enrollment Token for Kibana
Configuring Kibana:
- Wait for Kibana (1cd634187088c576031e9ac9c7e100d563779b9947edced26eb6111b33af1e3e) to be ready. (took 0 seconds)
- Enrolling Kibana
Configuring HASS Access:
- Wait for Elasticsearch (69bd5d66c5d9e059d1b2e965fe4ebf945564bc0518982447af3b0396f80c219c) cluster to be green (took 0 seconds)
- Creating a role for Home Assistant
- Creating a user for Home Assistant
- Creating an API Key for Home Assistant

---Ready to use!---
Elasticsearch
  Url: https://host.docker.internal:9200
  User: elastic
  Password: source/workspaces/homeassistant-elasticsearch/.venv/bin/activatev3j0TIs7Aku-i2ULfV_K

  User: hass_writer
  Password: changeme
  API Key: null

Kibana
  Host Url: http://host.docker.internal:5601
  User: elastic
  Password: source/workspaces/homeassistant-elasticsearch/.venv/bin/activatev3j0TIs7Aku-i2ULfV_K

Setup Information
  Version: 8.13.0
  Setup Code: 495113
  Enrollment Token: eyJ2ZXIiOiI4LjEzLjAiLCJhZHIiOlsiMTcyLjIyLjAuMjo5MjAwIl0sImZnciI6ImY3ODI5MmE1YjNlN2E1OTk1MWFkNjdmMjZiNDk4MmYzN2MzY2NkZjdhN2I3OWJkOGVhYzE0ZWJjNmE2M2VmZmEiLCJrZXkiOiJDSC0xaFk0QlNvYk05RDdPV2pYQzpIOHZEMWZvOVNLNkJtamRVVExnalBnIn0=
  Containers: 69bd5d66c5d9e059d1b2e965fe4ebf945564bc0518982447af3b0396f80c219c 1cd634187088c576031e9ac9c7e100d563779b9947edced26eb6111b33af1e3e
  Duration: 31 seconds
strawgate commented 2 months ago

Have you made any customizations to like the bash rc or anything like that in your devcontainer?

I cannot reproduce this, running the same task I receive:

Executing task in folder homeassistant-elasticsearch: /bin/bash ./scripts/run_ek_8_13_0 

Performing Environment Clean-up
- Stopping and removing container kb01
- Stopping and removing container es01
- Removing network elastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 8.13.0 took 0 seconds
- Pulling Kibana image for 8.13.0 took 1 seconds
Starting Elasticsearch and Kibana
- Wait for Elasticsearch (03c5533b8ba6c24f3c9dba53de2e2e72c9cb2d2f69ef3712e640090861582913) to be ready............ (took 11 seconds)
Configuring Elasticsearch:
- Resetting elastic user account password
rnAdpdrWaXnY7vJX-FWE
- Generating an Enrollment Token for Kibana
Configuring Kibana:
- Wait for Kibana (d1d55e854277c9f5e7c2f64f7b2e31b2b1bc9ed3886a9ec8a19ee5aa31ac5a84) to be ready. (took 1 seconds)
- Enrolling Kibana
Configuring HASS Access:
- Wait for Elasticsearch (03c5533b8ba6c24f3c9dba53de2e2e72c9cb2d2f69ef3712e640090861582913) cluster to be green (took 0 seconds)
- Creating a role for Home Assistant
- Creating a user for Home Assistant
- Creating an API Key for Home Assistant

---Ready to use!---
Elasticsearch
  Url: https://host.docker.internal:9200
  User: elastic
  Password: rnAdpdrWaXnY7vJX-FWE

  User: hass_writer
  Password: changeme
  API Key: UoygAq8CQ9y4sZUw_gHSeQ

Kibana
  Host Url: http://host.docker.internal:5601
  User: elastic
  Password: rnAdpdrWaXnY7vJX-FWE

Setup Information
  Version: 8.13.0
  Setup Code: 332624
  Enrollment Token: eyJ2ZXIiOiI4LjEzLjAiLCJhZHIiOlsiMTkyLjE2OC44MC4yOjkyMDAiXSwiZmdyIjoiZmNjOTlhY2VhNmZjZmY4ZjFiN2U1YzVjY2M2NTZhNmQ4OGEwOGI2YjJhNTdiODYwNzRjMzcxNTcwMDZlMzUyZiIsImtleSI6ImJhZmVoWTRCUl9tUmw4S0pOOEp0Oi1JQ1llZ2ZyU2RhdVcxR3dSVklaNncifQ==
  Containers: 03c5533b8ba6c24f3c9dba53de2e2e72c9cb2d2f69ef3712e640090861582913 d1d55e854277c9f5e7c2f64f7b2e31b2b1bc9ed3886a9ec8a19ee5aa31ac5a84
  Duration: 25 seconds

Would you be able to put some additional logging lines like in bootstrap_ek

echo "- Resetting elastic user account password"
espwd=$(/bin/bash "$dir/reset_es_pwd" "$escontainer")
echo "$espwd" 

and share the output from that and maybe also modify reset_es_pwd to not grep or trim so I can see where the output is getting messed up?


escontainer=$1

return=$(docker exec -it "$escontainer" /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic --silent --batch)

echo -n "$return"
legrego commented 2 months ago

I haven't directly modified my bash profile. I'm looking through my vscode settings to see if there's anything suspect in there.

Here's what I get when making the suggested script edits:

Configuring Elasticsearch:
- Resetting elastic user account password
source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
-NKaSoMSVr-gfAgCjOuc
- Generating an Enrollment Token for Kibana
Configuring Kibana:
- Wait for Kibana (5e996131951c8886fc1fbf7fbe094981ad92fea7edfc5126b52f413b1e13d99f) to be ready. (took 0 seconds)
- Enrolling Kibana
Configuring HASS Access:
- Wait for Elasticsearch (85c966db1d796fef8779cd768b42a39a9b28b8c791166084421746822ab43a19) cluster to be green (took 1 seconds)
- Creating a role for Home Assistant
- Creating a user for Home Assistant
- Creating an API Key for Home Assistant

---Ready to use!---
Elasticsearch
  Url: https://host.docker.internal:9200
  User: elastic
  Password: source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
-NKaSoMSVr-gfAgCjOuc

  User: hass_writer
  Password: changeme
  API Key: null

Kibana
  Host Url: http://host.docker.internal:5601
  User: elastic
  Password: source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
-NKaSoMSVr-gfAgCjOuc
legrego commented 2 months ago

Hmm, we have a difference in how the tasks are getting kicked off.

Yours:

Executing task in folder homeassistant-elasticsearch: /bin/bash ./scripts/run_ek_8_13_0 

Performing Environment Clean-up

Mine:

 *  Executing task: /bin/bash ./scripts/run_ek_8_13_0 

source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
Performing Environment Clean-up
legrego commented 2 months ago

I had this setting turned on:

Larry Gregory 2024-03-28 at 13 00 50@2x

Turning this off "fixes" the problem, and I see the correct output:

*  Executing task: /bin/bash ./scripts/run_ek_8_13_0 

Performing Environment Clean-up
- Stopping and removing container kb01
- Stopping and removing container es01
- Removing network elasticelasticelastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 8.13.0 took 1 seconds
- Pulling Kibana image for 8.13.0 took 1 seconds
Starting Elasticsearch and Kibana
- Wait for Elasticsearch (d61dd92b39cfc795ad5190ce215d214add240491bb7825d4372475122dcd1f46) to be ready................... (took 19 seconds)
Configuring Elasticsearch:
- Resetting elastic user account password
- Generating an Enrollment Token for Kibana
Configuring Kibana:
- Wait for Kibana (7390ca38f9812827f3560377d75d6b7804127af285bc49303c006b9c26b38e11) to be ready. (took 0 seconds)
- Enrolling Kibana
Configuring HASS Access:
- Wait for Elasticsearch (d61dd92b39cfc795ad5190ce215d214add240491bb7825d4372475122dcd1f46) cluster to be green (took 0 seconds)
- Creating a role for Home Assistant
- Creating a user for Home Assistant
- Creating an API Key for Home Assistant

---Ready to use!---
Elasticsearch
  Url: https://host.docker.internal:9200
  User: elastic
  Password: 7Z8codg*UHTvSvss7Jb7

  User: hass_writer
  Password: changeme
  API Key: bttBv_CyRN-jJwgf-SrrBA

Kibana
  Host Url: http://host.docker.internal:5601
  User: elastic
  Password: 7Z8codg*UHTvSvss7Jb7

Setup Information
  Version: 8.13.0
  Setup Code: 527676
  Enrollment Token: eyJ2ZXIiOiI4LjEzLjAiLCJhZHIiOlsiMTcyLjI4LjAuMjo5MjAwIl0sImZnciI6Ijc4Nzc0NTE1N2U4NTg2MjYwMWVhZmQ2ZGMyZjMxYmMxYzVhNzkxNjc1MzQwNjk3NDM2YzY2M2E4ODg3ZmUxZDQiLCJrZXkiOiJWUDBDaG80Ql9WUTBOTUVnTFF2RjpKT3drME1KNFRqcXRfbWgzUWU5QlRRIn0=
  Containers: d61dd92b39cfc795ad5190ce215d214add240491bb7825d4372475122dcd1f46 7390ca38f9812827f3560377d75d6b7804127af285bc49303c006b9c26b38e11
  Duration: 31 seconds
 *  Terminal will be reused by tasks, press any key to close it. 
strawgate commented 2 months ago

If I don't use the workspace I get

Executing task: /bin/bash ./scripts/run_ek_8_13_0 

Performing Environment Clean-up
- Stopping and removing container kb01
- Stopping and removing container es01
- Removing network elastic
Pulling Docker Images for Elasticsearch and Kibana
- Pulling Elasticsearch image for 8.13.0 took 1 seconds
- Pulling Kibana image for 8.13.0 took 0 seconds
Starting Elasticsearch and Kibana

looks like something in your dev container is randomly inserting

source /workspaces/homeassistant-elasticsearch/.venv/bin/activate

this is very weird, it implies that somewhere in these lines that's getting printed?

Performing Environment Clean-up
source /workspaces/homeassistant-elasticsearch/.venv/bin/activate
- Removing network elasticelasticelastic

it implies that somewhere in these lines that's getting printed?

containers=("kb01" "es01")

for container in "${containers[@]}"; do
  # Check if the container exists
  if ! docker ps -a | grep -q "$container"; then
    continue
  fi

  echo "- Stopping and removing container $container"
  docker kill "$container" >/dev/null
  docker rm "$container" >/dev/null
done

# If the network exists, remove it
networks=$(docker network ls | grep -o "elastic")

if [ -n "$networks" ]; then
strawgate commented 2 months ago

I also have that enabled though.... image

legrego commented 2 months ago

What does your settings.json look like within the container?

vscode ➜ /workspaces/homeassistant-elasticsearch (Refactor-Dev-Container) $ cat /home/vscode/.vscode-server/data/Machine/settings.json 
{
        "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
        "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
        "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
        "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
        "python.linting.flake8Enabled": false,
        "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
        "python.linting.mypyEnabled": false,
        "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
        "python.linting.pylintEnabled": false,
        "files.eol": "\n",
        "editor.tabSize": 4,
        "python.analysis.autoSearchPaths": false,
        "editor.formatOnPaste": false,
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "files.trimTrailingWhitespace": true,
        "remote.portsAttributes": {
                "8123": {
                        "label": "Home Assistant",
                        "onAutoForward": "notify"
                }
        }
}
strawgate commented 2 months ago
{
        "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
        "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
        "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
        "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
        "python.linting.flake8Enabled": false,
        "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
        "python.linting.mypyEnabled": false,
        "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
        "python.linting.pylintEnabled": false,
        "files.eol": "\n",
        "editor.tabSize": 4,
        "python.analysis.autoSearchPaths": false,
        "python.terminal.activateEnvInCurrentTerminal": true,
        "editor.formatOnPaste": false,
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "files.trimTrailingWhitespace": true,
        "remote.portsAttributes": {
                "8123": {
                        "label": "Home Assistant",
                        "onAutoForward": "notify"
                }
        }
}

looks like mine only differs in "python.terminal.activateEnvInCurrentTerminal": true,

can you share your bashrc? cat ~/.bashrc

cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme
__bash_prompt() {
    local userpart='`export XIT=$? \
        && [ ! -z "${GITHUB_USER}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER} " || echo -n "\[\033[0;32m\]\u " \
        && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
    local gitbranch='`\
        if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \
            export BRANCH=$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null); \
            if [ "${BRANCH}" != "" ]; then \
                echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH}" \
                && if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \
                    git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
                        echo -n " \[\033[1;33m\]✗"; \
                fi \
                && echo -n "\[\033[0;36m\]) "; \
            fi; \
        fi`'
    local lightblue='\[\033[1;34m\]'
    local removecolor='\[\033[0m\]'
    PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ "
    unset -f __bash_prompt
}
__bash_prompt
export PROMPT_DIRTRIM=4
strawgate commented 2 months ago

also perhaps worth checking what env bash returns and perhaps the output of alias

legrego commented 2 months ago

My bash looks identical except for some whitespace differences:

vscode ➜ /workspaces/homeassistant-elasticsearch (Refactor-Dev-Container) $ diff cat-other.txt my-cat.txt 
1d0
< cat ~/.bashrc
51,54c50,53
<         # We have color support; assume it's compliant with Ecma-48
<         # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
<         # a case would tend to support setf rather than setaf.)
<         color_prompt=yes
---
>       # We have color support; assume it's compliant with Ecma-48
>       # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
>       # a case would tend to support setf rather than setaf.)
>       color_prompt=yes
56c55
<         color_prompt=
---
>       color_prompt=
139c138
< export PROMPT_DIRTRIM=4
\ No newline at end of file
---
> export PROMPT_DIRTRIM=4

Mine:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme
__bash_prompt() {
    local userpart='`export XIT=$? \
        && [ ! -z "${GITHUB_USER}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER} " || echo -n "\[\033[0;32m\]\u " \
        && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
    local gitbranch='`\
        if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \
            export BRANCH=$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null); \
            if [ "${BRANCH}" != "" ]; then \
                echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH}" \
                && if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \
                    git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
                        echo -n " \[\033[1;33m\]✗"; \
                fi \
                && echo -n "\[\033[0;36m\]) "; \
            fi; \
        fi`'
    local lightblue='\[\033[1;34m\]'
    local removecolor='\[\033[0m\]'
    PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ "
    unset -f __bash_prompt
}
__bash_prompt
export PROMPT_DIRTRIM=4

also perhaps worth checking what env bash returns and perhaps the output of alias

env bash returns nothing.

vscode ➜ /workspaces/homeassistant-elasticsearch (Refactor-Dev-Container) $ env bash
vscode ➜ /workspaces/homeassistant-elasticsearch (Refactor-Dev-Container) $ alias
alias ls='ls --color=auto'
legrego commented 2 months ago

I also tried opening VSCode into the workspace that you defined in homeassistant-elasticsearch.code-workspace. That made my output start with the same Executing task in folder homeassistant-elasticsearch: /bin/bash ./scripts/run_ek_8_13_0 line that yours has, but I still have the same problem with password output.

I can reliably "fix" this behavior by toggling that one setting. This is really bizarre

legrego commented 2 months ago

In the interest of unblocking your other work, we can merge this and revisit the output problem in a follow-up task. I'll approve this PR, and leave that decision to you.

strawgate commented 2 months ago

Was there anything interesting in your settings.json in the vscode folder? I noticed that was also excluded from git