Przeglądaj źródła

[git-bridge] Cache maven artifacts in base layer (#34424)

* [git-bridge] Cache maven artifacts in base layer

Adds a Dockerfile stage to resolve dependencies in the `base` layer, which is cached for production and e2e/dev builds.

GitOrigin-RevId: 0830a3be0c02e5e09e370cf64cdccc30ebf42d7a
Miguel Serrano 2 miesięcy temu
rodzic
commit
4ba7f01ba4
1 zmienionych plików z 15 dodań i 0 usunięć
  1. 15 0
      services/git-bridge/Dockerfile

+ 15 - 0
services/git-bridge/Dockerfile

@@ -16,6 +16,21 @@ RUN chmod +x /opt/envsubst
 
 RUN useradd --create-home node
 
+ENV MAVEN_OPTS="-Dmaven.repo.local=/home/node/repository"
+
+# Pre-resolve Maven dependencies and plugins into the base image to limit
+# downstream `mvn` invocations hitting Maven Central on every CI build.
+# Uses a stub source and test, since `dependency:go-offline` and `dependency:resolve-plugins`
+# miss lazy-loaded plugins (surefire, maven-assembly, etc.)
+COPY pom.xml /tmp/warmup/pom.xml
+RUN mkdir -p /tmp/warmup/src/main/java/stub /tmp/warmup/src/test/java/stub \
+ && echo 'package stub; public class Stub {}' > /tmp/warmup/src/main/java/stub/Stub.java \
+ && echo 'package stub; public class StubTest { @org.junit.Test public void noop() {} }' \
+      > /tmp/warmup/src/test/java/stub/StubTest.java \
+&& mvn -B --no-transfer-progress -f /tmp/warmup/pom.xml clean package \
+&& chown -R node:node /home/node/repository \
+&& rm -rf /tmp/warmup
+
 FROM base AS builder
 
 COPY . /app