diff --git a/docker/Dockerfile b/docker/Dockerfile index d3ee219de8..9c3e864e43 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -51,17 +51,17 @@ RUN \ && platformio settings set check_platforms_interval 1000000 \ && mkdir -p /piolibs + + +# ======================= docker-type image ======================= +FROM base AS docker + # First install requirements to leverage caching when requirements don't change COPY requirements.txt requirements_optional.txt docker/platformio_install_deps.py platformio.ini / RUN \ pip3 install --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \ && /platformio_install_deps.py /platformio.ini - - -# ======================= docker-type image ======================= -FROM base AS docker - # Copy esphome and install COPY . /esphome RUN pip3 install --no-cache-dir -e /esphome @@ -104,6 +104,12 @@ ARG BUILD_VERSION=dev # Copy root filesystem COPY docker/hassio-rootfs/ / +# First install requirements to leverage caching when requirements don't change +COPY requirements.txt requirements_optional.txt docker/platformio_install_deps.py platformio.ini / +RUN \ + pip3 install --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \ + && /platformio_install_deps.py /platformio.ini + # Copy esphome and install COPY . /esphome RUN pip3 install --no-cache-dir -e /esphome @@ -141,5 +147,10 @@ RUN \ /var/{cache,log}/* \ /var/lib/apt/lists/* +COPY requirements.txt requirements_optional.txt docker/platformio_install_deps.py platformio.ini / +RUN \ + pip3 install --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \ + && /platformio_install_deps.py /platformio.ini + VOLUME ["/esphome"] WORKDIR /esphome diff --git a/docker/build.py b/docker/build.py index cd8dca3b87..1157d8287a 100755 --- a/docker/build.py +++ b/docker/build.py @@ -109,9 +109,9 @@ def main(): # 1. pull cache image params = DockerParams.for_type_arch(args.build_type, args.arch) cache_tag = { - CHANNEL_DEV: "dev", - CHANNEL_BETA: "beta", - CHANNEL_RELEASE: "latest", + CHANNEL_DEV: "cache-dev", + CHANNEL_BETA: "cache-beta", + CHANNEL_RELEASE: "cache-latest", }[channel] cache_img = f"ghcr.io/{params.build_to}:{cache_tag}" @@ -123,7 +123,7 @@ def main(): "docker", "buildx", "build", "--build-arg", f"BASEIMGTYPE={params.baseimgtype}", "--build-arg", f"BUILD_VERSION={args.tag}", - "--cache-from", cache_img, + "--cache-from", f"type=registry,ref={cache_img}", "--file", "docker/Dockerfile", "--platform", params.platform, "--target", params.target, @@ -131,7 +131,7 @@ def main(): for img in imgs: cmd += ["--tag", img] if args.push: - cmd.append("--push") + cmd += ["--push", "--cache-to", f"type=registry,ref={cache_img},mode=max"] run_command(*cmd, ".") elif args.command == "manifest":