Skip to content

Commit

Permalink
Revert changes from #112496 so this PR can be merged independently
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Mar 15, 2024
1 parent 534474b commit bca0dc6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 65 deletions.
30 changes: 11 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,47 @@ FROM ${BUILD_FROM}

# Synchronize with homeassistant/core.py:async_stop
ENV \
S6_SERVICES_GRACETIME=240000 \
UV_EXTRA_INDEX_URL="https://wheels.home-assistant.io/musllinux-index/" \
UV_NO_CACHE=true \
PATH="$PATH:/root/.cargo/bin" \
UV_SYSTEM_PYTHON=true
S6_SERVICES_GRACETIME=240000

ARG QEMU_CPU

# Set shell
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
# Install uv
RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.21/uv-installer.sh | sh

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN \
uv pip install \
--no-build \
pip3 install \
--only-binary=:all: \
-r homeassistant/requirements.txt

COPY requirements_all.txt home_assistant_frontend-* home_assistant_intents-* homeassistant/
RUN \
if ls homeassistant/home_assistant_frontend*.whl 1> /dev/null 2>&1; then \
uv pip install homeassistant/home_assistant_frontend-*.whl; \
pip3 install homeassistant/home_assistant_frontend-*.whl; \
fi \
&& if ls homeassistant/home_assistant_intents*.whl 1> /dev/null 2>&1; then \
uv pip install homeassistant/home_assistant_intents-*.whl; \
pip3 install homeassistant/home_assistant_intents-*.whl; \
fi \
&& if [ "${BUILD_ARCH}" = "i386" ]; then \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
linux32 uv pip install \
--no-build \
linux32 pip3 install \
--only-binary=:all: \
-r homeassistant/requirements_all.txt; \
else \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
uv pip install \
--no-build \
pip3 install \
--only-binary=:all: \
-r homeassistant/requirements_all.txt; \
fi

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
uv pip install \
pip3 install \
--only-binary=:all: \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ types-pytz==2023.3.1.1
types-PyYAML==6.0.12.12
types-requests==2.31.0.3
types-xmltodict==0.13.0.3
uv==0.1.21
uv==0.1.17
57 changes: 12 additions & 45 deletions script/hassfest/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from homeassistant.util import executor, thread

from .model import Config, Integration
from .requirements import PACKAGE_REGEX, PIP_VERSION_RANGE_SEPARATOR

DOCKERFILE_TEMPLATE = r"""# Automatically generated by hassfest.
#
Expand All @@ -14,55 +13,47 @@
# Synchronize with homeassistant/core.py:async_stop
ENV \
S6_SERVICES_GRACETIME={timeout} \
UV_EXTRA_INDEX_URL="https://wheels.home-assistant.io/musllinux-index/" \
UV_NO_CACHE=true \
PATH="$PATH:/root/.cargo/bin" \
UV_SYSTEM_PYTHON=true
S6_SERVICES_GRACETIME={timeout}
ARG QEMU_CPU
# Set shell
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
# Install uv
RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/{uv_version}/uv-installer.sh | sh
WORKDIR /usr/src
## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN \
uv pip install \
--no-build \
pip3 install \
--only-binary=:all: \
-r homeassistant/requirements.txt
COPY requirements_all.txt home_assistant_frontend-* home_assistant_intents-* homeassistant/
RUN \
if ls homeassistant/home_assistant_frontend*.whl 1> /dev/null 2>&1; then \
uv pip install homeassistant/home_assistant_frontend-*.whl; \
pip3 install homeassistant/home_assistant_frontend-*.whl; \
fi \
&& if ls homeassistant/home_assistant_intents*.whl 1> /dev/null 2>&1; then \
uv pip install homeassistant/home_assistant_intents-*.whl; \
pip3 install homeassistant/home_assistant_intents-*.whl; \
fi \
&& if [ "${{BUILD_ARCH}}" = "i386" ]; then \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
linux32 uv pip install \
--no-build \
linux32 pip3 install \
--only-binary=:all: \
-r homeassistant/requirements_all.txt; \
else \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
uv pip install \
--no-build \
pip3 install \
--only-binary=:all: \
-r homeassistant/requirements_all.txt; \
fi
## Setup Home Assistant Core
COPY . homeassistant/
RUN \
uv pip install \
pip3 install \
--only-binary=:all: \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand All @@ -74,28 +65,6 @@
"""


def _get_uv_version() -> str:
with open("requirements_test.txt") as fp:
for _, line in enumerate(fp):
if match := PACKAGE_REGEX.match(line):
pkg, sep, version = match.groups()

if pkg != "uv":
continue

if sep != "==" or not version:
raise RuntimeError(
'Requirement uv need to be pinned "uv==<version>".'
)

for part in version.split(";", 1)[0].split(","):
version_part = PIP_VERSION_RANGE_SEPARATOR.match(part)
if version_part:
return version_part.group(2)

raise RuntimeError("Invalid uv requirement in requirements_test.txt")


def _generate_dockerfile() -> str:
timeout = (
core.STOPPING_STAGE_SHUTDOWN_TIMEOUT
Expand All @@ -106,9 +75,7 @@ def _generate_dockerfile() -> str:
+ thread.THREADING_SHUTDOWN_TIMEOUT
+ 10
)
return DOCKERFILE_TEMPLATE.format(
timeout=timeout * 1000, uv_version=_get_uv_version()
)
return DOCKERFILE_TEMPLATE.format(timeout=timeout * 1000)


def validate(integrations: dict[str, Integration], config: Config) -> None:
Expand Down

0 comments on commit bca0dc6

Please sign in to comment.