From 4bffe3110fef64d027345ddf8ed67e3719d4df14 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 1 Sep 2023 07:22:32 +0200
Subject: [PATCH] fix(datasource/docker): improve label efficiency (#24193)

---
 lib/modules/datasource/docker/index.spec.ts | 18 ++----------------
 lib/modules/datasource/docker/index.ts      | 10 +++++++++-
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/lib/modules/datasource/docker/index.spec.ts b/lib/modules/datasource/docker/index.spec.ts
index 5821751997..6750649a9d 100644
--- a/lib/modules/datasource/docker/index.spec.ts
+++ b/lib/modules/datasource/docker/index.spec.ts
@@ -1086,11 +1086,7 @@ describe('modules/datasource/docker/index', () => {
           {
             link: `<${baseUrl}/library/node/tags/list?n=1&page=2>; rel="next", `,
           }
-        )
-        .get('/')
-        .reply(200)
-        .get('/library/node/manifests/1.0.1')
-        .reply(200);
+        );
 
       const config = {
         datasource: DockerDatasource.id,
@@ -1563,11 +1559,7 @@ describe('modules/datasource/docker/index', () => {
             'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/node:pull"',
         })
         .get('/library/node/tags/list?n=10000')
-        .reply(200, { tags }, {})
-        .get('/')
-        .reply(200)
-        .get('/library/node/manifests/1.0.0')
-        .reply(200);
+        .reply(200, { tags }, {});
       httpMock
         .scope(authUrl)
         .get(
@@ -1606,12 +1598,6 @@ describe('modules/datasource/docker/index', () => {
             },
           ],
         });
-      httpMock
-        .scope(baseUrl)
-        .get('/')
-        .reply(200)
-        .get('/library/node/manifests/1.0.0')
-        .reply(200);
       const res = await getPkgReleases({
         datasource: DockerDatasource.id,
         packageName: 'docker.io/node',
diff --git a/lib/modules/datasource/docker/index.ts b/lib/modules/datasource/docker/index.ts
index 4b6a856ce3..df29be785e 100644
--- a/lib/modules/datasource/docker/index.ts
+++ b/lib/modules/datasource/docker/index.ts
@@ -431,7 +431,7 @@ export class DockerDatasource extends Datasource {
     namespace: 'datasource-docker-labels',
     key: (registryHost: string, dockerRepository: string, tag: string) =>
       `${registryHost}:${dockerRepository}:${tag}`,
-    ttlMinutes: 60,
+    ttlMinutes: 24 * 60,
   })
   public async getLabels(
     registryHost: string,
@@ -439,6 +439,14 @@ export class DockerDatasource extends Datasource {
     tag: string
   ): Promise<Record<string, string> | undefined> {
     logger.debug(`getLabels(${registryHost}, ${dockerRepository}, ${tag})`);
+    // Docker Hub library images don't have labels we need
+    if (
+      registryHost === 'https://index.docker.io' &&
+      dockerRepository.startsWith('library/')
+    ) {
+      logger.debug('Docker Hub library image - skipping label lookup');
+      return {};
+    }
     try {
       let labels: Record<string, string> | undefined = {};
       const manifest = await this.getManifest(
-- 
GitLab