From 13fe2a9929c2adc17b33d0d558d101882a77c966 Mon Sep 17 00:00:00 2001
From: Robert Resch <robert@resch.dev>
Date: Tue, 18 Feb 2025 20:31:41 +0100
Subject: [PATCH] Reorder Dockerfile to improve caching (#138789)

---
 Dockerfile                | 36 ++++++++++++++++++------------------
 script/hassfest/docker.py | 36 ++++++++++++++++++------------------
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index a4d882eb8a1..3ab0bb37b9a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,6 +12,24 @@ ENV \
 
 ARG QEMU_CPU
 
+# Home Assistant S6-Overlay
+COPY rootfs /
+
+# Needs to be redefined inside the FROM statement to be set for RUN commands
+ARG BUILD_ARCH
+# Get go2rtc binary
+RUN \
+    case "${BUILD_ARCH}" in \
+        "aarch64") go2rtc_suffix='arm64' ;; \
+        "armhf") go2rtc_suffix='armv6' ;; \
+        "armv7") go2rtc_suffix='arm' ;; \
+        *) go2rtc_suffix=${BUILD_ARCH} ;; \
+    esac \
+    && curl -L https://github.com/AlexxIT/go2rtc/releases/download/v1.9.8/go2rtc_linux_${go2rtc_suffix} --output /bin/go2rtc \
+    && chmod +x /bin/go2rtc \
+    # Verify go2rtc can be executed
+    && go2rtc --version
+
 # Install uv
 RUN pip3 install uv==0.6.1
 
@@ -42,22 +60,4 @@ RUN \
     && python3 -m compileall \
         homeassistant/homeassistant
 
-# Home Assistant S6-Overlay
-COPY rootfs /
-
-# Needs to be redefined inside the FROM statement to be set for RUN commands
-ARG BUILD_ARCH
-# Get go2rtc binary
-RUN \
-    case "${BUILD_ARCH}" in \
-        "aarch64") go2rtc_suffix='arm64' ;; \
-        "armhf") go2rtc_suffix='armv6' ;; \
-        "armv7") go2rtc_suffix='arm' ;; \
-        *) go2rtc_suffix=${BUILD_ARCH} ;; \
-    esac \
-    && curl -L https://github.com/AlexxIT/go2rtc/releases/download/v1.9.8/go2rtc_linux_${go2rtc_suffix} --output /bin/go2rtc \
-    && chmod +x /bin/go2rtc \
-    # Verify go2rtc can be executed
-    && go2rtc --version
-
 WORKDIR /config
diff --git a/script/hassfest/docker.py b/script/hassfest/docker.py
index edc47e2f9d7..4bf6c3bb0a6 100644
--- a/script/hassfest/docker.py
+++ b/script/hassfest/docker.py
@@ -26,6 +26,24 @@ ENV \
 
 ARG QEMU_CPU
 
+# Home Assistant S6-Overlay
+COPY rootfs /
+
+# Needs to be redefined inside the FROM statement to be set for RUN commands
+ARG BUILD_ARCH
+# Get go2rtc binary
+RUN \
+    case "${{BUILD_ARCH}}" in \
+        "aarch64") go2rtc_suffix='arm64' ;; \
+        "armhf") go2rtc_suffix='armv6' ;; \
+        "armv7") go2rtc_suffix='arm' ;; \
+        *) go2rtc_suffix=${{BUILD_ARCH}} ;; \
+    esac \
+    && curl -L https://github.com/AlexxIT/go2rtc/releases/download/v{go2rtc}/go2rtc_linux_${{go2rtc_suffix}} --output /bin/go2rtc \
+    && chmod +x /bin/go2rtc \
+    # Verify go2rtc can be executed
+    && go2rtc --version
+
 # Install uv
 RUN pip3 install uv=={uv}
 
@@ -56,24 +74,6 @@ RUN \
     && python3 -m compileall \
         homeassistant/homeassistant
 
-# Home Assistant S6-Overlay
-COPY rootfs /
-
-# Needs to be redefined inside the FROM statement to be set for RUN commands
-ARG BUILD_ARCH
-# Get go2rtc binary
-RUN \
-    case "${{BUILD_ARCH}}" in \
-        "aarch64") go2rtc_suffix='arm64' ;; \
-        "armhf") go2rtc_suffix='armv6' ;; \
-        "armv7") go2rtc_suffix='arm' ;; \
-        *) go2rtc_suffix=${{BUILD_ARCH}} ;; \
-    esac \
-    && curl -L https://github.com/AlexxIT/go2rtc/releases/download/v{go2rtc}/go2rtc_linux_${{go2rtc_suffix}} --output /bin/go2rtc \
-    && chmod +x /bin/go2rtc \
-    # Verify go2rtc can be executed
-    && go2rtc --version
-
 WORKDIR /config
 """
 
-- 
GitLab