-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make local hosted devcontainer docker image
- Loading branch information
Showing
15 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ARG BUILD_FROM BUILD_FROM_TAG | ||
FROM python:3.11-slim | ||
|
||
ENV DEVCONTAINER=true | ||
|
||
COPY ./container /container | ||
COPY ./install /install | ||
|
||
ARG OS_VARIANT CONTAINER_TYPE | ||
RUN \ | ||
bash /install/init.sh \ | ||
&& bash /install/container.sh \ | ||
&& bash /install/integration.sh \ | ||
&& bash /install/cleanup.sh | ||
|
||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
make --file /opt/container/container.mk "${*:-"help"}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MAKEFLAGS += --no-print-directory | ||
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) | ||
.DEFAULT_GOAL := help | ||
|
||
include /opt/container/makefiles/*.mk | ||
|
||
help: ## Show help | ||
@printf " \033[1m%s\033[0m\n %s\033[32m\033[0m\n %s\033[32m\033[0m \n\n" "container" "Custom CLI used in this container" "https://github.com/ludeeus/container"; | ||
@printf " \033[1m%s\033[0m\n %s\033[32m\033[0m \n\n" "usage:" "container [command]"; | ||
@printf " \033[1m%s\033[0m\n" "where [command] is one of:"; | ||
@awk 'BEGIN {FS = ":.*##";} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m container %-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST); | ||
@echo |
3 changes: 3 additions & 0 deletions
3
.devcontainer/container/helpers/common/homeassistant/check-config.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
hass -c /config --script check_config |
8 changes: 8 additions & 0 deletions
8
.devcontainer/container/helpers/common/homeassistant/set-version.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
read -p 'Set Home Assistant version: ' -r version | ||
python3 -m pip --disable-pip-version-check install --upgrade homeassistant=="$version" | ||
|
||
if [[ -n "$POST_SET_VERSION_HOOK" ]]; then | ||
"$POST_SET_VERSION_HOOK" "$version" | ||
fi |
40 changes: 40 additions & 0 deletions
40
.devcontainer/container/helpers/common/homeassistant/start.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck source=/dev/null | ||
|
||
source /opt/container/helpers/common/paths.sh | ||
mkdir -p /config | ||
|
||
if test -f ".devcontainer/configuration.yaml"; then | ||
echo "Copy configuration.yaml" | ||
ln -sf "$(workspacePath).devcontainer/configuration.yaml" /config/configuration.yaml || echo ".devcontainer/configuration.yaml are missing" | ||
fi | ||
|
||
if test -f ".devcontainer/ui-lovelace.yaml"; then | ||
echo "Copy ui-lovelace.yaml" | ||
ln -sf "$(workspacePath).devcontainer/ui-lovelace.yaml" /config/ui-lovelace.yaml || echo "" | ||
fi | ||
|
||
if test -f ".devcontainer/secrets.yaml"; then | ||
echo "Copy secrets.yaml" | ||
ln -sf "$(workspacePath).devcontainer/secrets.yaml" /config/secrets.yaml || echo "" | ||
fi | ||
|
||
if test -d "custom_components"; then | ||
echo "Symlink the custom component directory" | ||
|
||
if test -d "custom_components"; then | ||
rm -R /config/custom_components | ||
fi | ||
|
||
ln -sf "$(workspacePath)custom_components/" /config/custom_components || echo "Could not copy the custom_component" exit 1 | ||
elif test -f "__init__.py"; then | ||
echo "Having the component in the root is currently not supported" | ||
fi | ||
|
||
echo "Start Home Assistant" | ||
if ! [ -x "$(command -v hass)" ]; then | ||
echo "Home Assistant is not installed, running installation." | ||
python3 -m pip --disable-pip-version-check install --upgrade git+https://github.com/home-assistant/home-assistant.git@dev | ||
fi | ||
hass --script ensure_config -c /config | ||
hass -c /config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
function workspacePath { | ||
if [[ -n "$WORKSPACE_DIRECTORY" ]]; then | ||
echo "${WORKSPACE_DIRECTORY}/" | ||
else | ||
echo "$(find /workspaces -mindepth 1 -maxdepth 1 -type d | tail -1)/" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck source=/dev/null | ||
|
||
source /opt/container/helpers/common/paths.sh | ||
|
||
|
||
if test -d "$(GetWorkspaceName).git"; then | ||
echo ".git exsist in $(GetWorkspaceName), existing initializing" | ||
exit 1 | ||
fi | ||
|
||
echo "Initializing dev env for integration" | ||
rm -R /tmp/init > /dev/null 2>&1 | ||
|
||
git clone https://github.com/custom-components/integration-blueprint.git /tmp/init | ||
|
||
rm -R /tmp/init/.git | ||
rm -R /tmp/init/.devcontainer | ||
cp -a /tmp/init/. "$(GetWorkspaceName)" | ||
cd "$(GetWorkspaceName)" || exit 1 | ||
git init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
start: ## Start Home Assistant with the integration loaded | ||
@bash /opt/container/helpers/common/homeassistant/start.sh | ||
|
||
set-version: ## Set Home Assistant version | ||
@bash /opt/container/helpers/common/homeassistant/set-version.sh | ||
|
||
install: ## Install Home Assistant dev in the container | ||
@python3 -m pip --disable-pip-version-check install --upgrade git+https://github.com/home-assistant/home-assistant.git@dev | ||
|
||
upgrade: ## Upgrade Home Assistant to latest dev in the container | ||
install | ||
|
||
run: | ||
start | ||
|
||
check-config: ## Check Home Assistant config | ||
@hass -c /config --script check_config | ||
|
||
init: ## Initialize the dev env | ||
@bash /opt/container/helpers/integration/init.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo -e "\\033[0;34mRunning cleanup script 'cleanup.sh'\\033[0m" | ||
|
||
apt-get clean -y | ||
rm -fr /var/lib/apt/lists/* | ||
rm -fr /tmp/* /var/{cache,log}/* | ||
|
||
rm -fr /container | ||
rm -fr /install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
echo -e "\\033[0;34mRunning install script 'container.sh'\\033[0m" | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
make | ||
|
||
mkdir -p /opt/container/makefiles | ||
mkdir -p /opt/container/helpers | ||
touch /opt/container/makefiles/dummy.mk | ||
|
||
cp /container/container.mk /opt/container/container.mk | ||
cp -r /container/helpers/common /opt/container/helpers/common | ||
|
||
cp /container/container /usr/bin/container | ||
chmod +x /usr/bin/container | ||
|
||
cp /container/makefiles/integration.mk /opt/container/makefiles/integration.mk | ||
cp -r /container/helpers/integration /opt/container/helpers/integration | ||
|
||
container help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env sh | ||
|
||
uname -m | ||
printenv | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
echo -e "\\033[0;34mRunning install script 'integration.sh'\\033[0m" | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
ffmpeg \ | ||
gcc \ | ||
git \ | ||
jq \ | ||
libavcodec-dev \ | ||
libavdevice-dev \ | ||
libavfilter-dev \ | ||
libavformat-dev \ | ||
libavutil-dev \ | ||
libbz2-dev \ | ||
libcap-dev \ | ||
libffi-dev \ | ||
libjpeg-dev \ | ||
liblzma-dev \ | ||
libncurses5-dev \ | ||
libncursesw5-dev \ | ||
libpcap-dev \ | ||
libreadline-dev \ | ||
libsqlite3-dev \ | ||
libssl-dev \ | ||
libswresample-dev \ | ||
libswscale-dev \ | ||
llvm \ | ||
shellcheck \ | ||
tar \ | ||
tk-dev \ | ||
wget \ | ||
xz-utils \ | ||
zlib1g-dev | ||
|
||
|
||
mkdir -p /config/custom_components | ||
|
||
python3 -m pip --disable-pip-version-check install --upgrade \ | ||
git+https://github.com/home-assistant/home-assistant.git@dev | ||
python3 -m pip --disable-pip-version-check install --upgrade wheel setuptools | ||
|
||
# Fix issue https://github.com/home-assistant/core/issues/95192 | ||
python3 -m pip --disable-pip-version-check install --upgrade git+https://github.com/boto/botocore urllib3~=1.26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters