move dependencies install higher to optimize rebuild
+ 19
- 17
@@ -61,8 +61,25 @@ ENV PORT=${PORT}
 ARG HOST="0.0.0.0"
 ENV HOST=${HOST}
 
-RUN apt-get update && \
-    apt-get install -y --no-install-recommends git openssl && \
+# Install required dependencies
+RUN apt-get update -y && \
+    apt-get install --no-install-recommends \
+        git-core git openssl openssh-server gnupg sudo curl jq ca-certificates wget -y && \
+    rm -rf /var/lib/apt/lists/*
+
+# Install Node 20.0.0 from nodesource
+RUN mkdir -p /etc/apt/keyrings && \
+    wget --output-document - --quiet https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
+        | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
+    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" \
+        | tee /etc/apt/sources.list.d/nodesource.list && \
+    wget --output-document - --quiet https://dl.yarnpkg.com/debian/pubkey.gpg \
+        | gpg --dearmor -o /etc/apt/keyrings/yarn-archive-keyring.gpg && \
+    echo "deb [signed-by=/etc/apt/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" \
+        | tee /etc/apt/sources.list.d/yarn.list && \
+    apt-get -qq update && \
+    apt-get -qq -y install --no-install-recommends \
+      yarn nodejs=$(apt-cache show nodejs | grep -F 'Version: 20.0.0' | cut -f 2 -d ' ') && \
     rm -rf /var/lib/apt/lists/*
 
 WORKDIR /app

...
@@ -85,21 +102,6 @@ RUN git rev-parse HEAD > .gitstamp
 COPY ./.gitstamp    /app/.gitstamp
 RUN rm -rf /app/.git
 
-# Install required dependencies
-RUN apt-get update -y && apt-get install git-core openssh-server gnupg sudo curl jq ca-certificates wget -y
-RUN mkdir -p /etc/apt/keyrings && \
-    wget --output-document - --quiet https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
-        | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
-    echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" \
-        | tee /etc/apt/sources.list.d/nodesource.list && \
-    wget --output-document - --quiet https://dl.yarnpkg.com/debian/pubkey.gpg \
-        | gpg --dearmor -o /etc/apt/keyrings/yarn-archive-keyring.gpg && \
-    echo "deb [signed-by=/etc/apt/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" \
-        | tee /etc/apt/sources.list.d/yarn.list && \
-    apt-get -qq update && \
-    apt-get -qq -y install --no-install-recommends \
-      yarn nodejs=$(apt-cache show nodejs | grep -F 'Version: 20.0.0' | cut -f 2 -d ' ')
-
 # Add git-shell to system shells
 RUN echo "/usr/bin/git-shell" >> /etc/shells
 # RUN chsh -s /usr/bin/git-shell