Skip to content

Commit

Permalink
Add devcontainer script
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Feb 27, 2021
1 parent ef478ff commit 2df20b7
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 36 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ venv.bak/



/dev-config
/custom_components/__init__.py
/test*.py
28 changes: 0 additions & 28 deletions bin/dev-deploy

This file was deleted.

86 changes: 86 additions & 0 deletions bin/devcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

# Stop on errors
set -e

ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )"
cd "${ROOT}"

# Load common functions
source ./bin/_common

dk=$(which docker) || die "ERROR: Docker not found."

workspace=${PWD##*/}
workdir="/workspaces/${workspace}"

container="dev-${workspace}"
port="127.0.0.1:9123:8123"
image="ludeeus/container:integration-debian"
volume="${ROOT}:${workdir}"

cmd="${1:-menu}"

if ! ${dk} ps -a | grep -wq ${container} && [[ "${cmd}" != "down" ]]; then
log.info "Create container..."
${dk} create -it --name "${container}" -p "${port}" -v "${volume}" "${image}"
fi

if [[ "${cmd}" == "menu" ]]; then
PS3='Please enter your choice: '
options=(\
"Run Home Assistant on port 9123"
"Run Home Assistant configuration against /config"
"Upgrade Home Assistant to latest dev"
"Install a specific version of Home Assistant"
)
echo
select opt in "${options[@]}"
do
case $REPLY in
1 )
cmd="start"
;;
2 )
cmd="check"
;;
3 )
cmd="upgrade"
;;
4 )
cmd="set-version"
;;
esac
break
done
fi
case "${cmd}" in
"stop" )
log.info "Stop container..."
${dk} stop "${container}"
;;
"down" )
log.info "Destroy container..."
${dk} stop -t 10 "${container}" >/dev/null
${dk} rm "${container}"
;;
"bash" )
if ! ${dk} ps | grep -wq ${container}; then
log.info "Start container..."
${dk} start "${container}"
fi
log.info "Interactive mode..."
${dk} exec -it "${container}" bash
;;
* )
if ! ${dk} ps | grep -wq ${container}; then
log.info "Start container..."
${dk} start "${container}"
fi
log.info "Send command '${cmd}' to container..."
if [[ "${cmd}" == "start" ]]; then
log.info "After Home Assistant initialization you can access to system on http://localhost:9123/"
fi
${dk} exec -it -w "${workdir}" "${container}" container "${cmd}"
;;
esac
5 changes: 0 additions & 5 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,3 @@ pre-commit install
pip3 install -r requirements-dev.txt

touch custom_components/__init__.py

CONFIG=/run/user/$(id -u)/gvfs/smb-share:server=hassio,share=config/
if [ -d "$CONFIG" ] && [ ! -e dev-config ]; then
ln -s "$CONFIG" dev-config
fi
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ show_missing = true
testpaths = tests
norecursedirs =
.git
dev-config
addopts =
--strict-markers
--cov=custom_components
filterwarnings =
ignore::DeprecationWarning:asynctest.*:

[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build,__pycache__,dev-config
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build,__pycache__
doctests = True
# To work with Black
# https://github.com/ambv/black#line-length
Expand Down

0 comments on commit 2df20b7

Please sign in to comment.