Skip to content

Commit ec1d450

Browse files
vigneshrajsbclaude
andauthored
fix(nativeHelm): support OCI repoUrl override for ORG_CHART deploys (#128)
* feat(nativeHelm): add OCI repo URL override and ECR auth support - Support OCI repoUrl override for ORG_CHART deploys - Add HELM_EXPERIMENTAL_OCI=1 to enable OCI support on helm 3.7.x - Add ECR auth init container support for OCI Helm chart deploys Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * use max mode --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 17d7ad7 commit ec1d450

7 files changed

Lines changed: 264 additions & 40 deletions

File tree

‎src/server/lib/kubernetes/jobFactory.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { V1Job } from '@kubernetes/client-node';
1818
import { normalizeKubernetesLabelValue } from './utils';
19+
import { RegistryAuthConfig, createRegistryAuthInitContainer } from 'server/lib/nativeHelm/registryAuth';
1920

2021
export interface JobConfig {
2122
name: string;
@@ -174,6 +175,7 @@ export interface HelmJobConfig {
174175
deployableId: string;
175176
};
176177
includeGitClone?: boolean;
178+
registryAuth?: RegistryAuthConfig;
177179
}
178180

179181
export function createHelmJob(config: HelmJobConfig): V1Job {
@@ -211,6 +213,10 @@ export function createHelmJob(config: HelmJobConfig): V1Job {
211213
});
212214
}
213215

216+
if (config.registryAuth) {
217+
initContainers.push(createRegistryAuthInitContainer(config.registryAuth));
218+
}
219+
214220
const containers = config.containers.map((container) => ({
215221
...container,
216222
resources: container.resources || {

‎src/server/lib/nativeBuild/engines.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const ENGINES: Record<string, BuildEngine> = {
106106
'--output',
107107
`type=image,name=${destination},push=true,registry.insecure=true,oci-mediatypes=false`,
108108
'--export-cache',
109-
`type=registry,ref=${cacheRef},mode=min,compression=zstd,oci-mediatypes=true,insecure=true`,
109+
`type=registry,ref=${cacheRef},mode=max,compression=zstd,oci-mediatypes=true,insecure=true`,
110110
'--import-cache',
111111
`type=registry,ref=${cacheRef},insecure=true`,
112112
];

‎src/server/lib/nativeHelm/__tests__/helm.test.ts‎

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { shouldUseNativeHelm, createHelmContainer } from '../helm';
1818
import { determineChartType, constructHelmCommand, ChartType, constructHelmCustomValues } from '../utils';
19+
import { RegistryAuthConfig } from '../registryAuth';
1920
import Deploy from 'server/models/Deploy';
2021
import GlobalConfigService from 'server/services/globalConfig';
2122

@@ -145,7 +146,7 @@ describe('Native Helm', () => {
145146
const deploy = {
146147
deployable: {
147148
helm: {
148-
chart: { name: 'bitnami/postgresql' },
149+
chart: { name: 'prometheus-community/prometheus' },
149150
},
150151
},
151152
} as Deploy;
@@ -374,10 +375,12 @@ describe('Native Helm', () => {
374375
['values.yaml'],
375376
ChartType.PUBLIC,
376377
undefined,
377-
'oci://registry-1.docker.io/bitnamicharts/postgresql'
378+
'oci://ghcr.io/prometheus-community/helm-charts/prometheus'
378379
);
379380

380-
expect(result).toContain('helm upgrade --install my-release oci://registry-1.docker.io/bitnamicharts/postgresql');
381+
expect(result).toContain(
382+
'helm upgrade --install my-release oci://ghcr.io/prometheus-community/helm-charts/prometheus'
383+
);
381384
expect(result).toContain('--namespace my-namespace');
382385
expect(result).toContain('--set "key=value"');
383386
expect(result).toContain('-f values.yaml');
@@ -409,22 +412,22 @@ describe('Native Helm', () => {
409412
it('should add chart version for PUBLIC charts when version is specified', () => {
410413
const result = constructHelmCommand(
411414
'upgrade --install',
412-
'bitnami/postgresql',
415+
'prometheus-community/prometheus',
413416
'my-release',
414417
'my-namespace',
415-
['auth.username=postgres_user'],
418+
['server.replicaCount=2'],
416419
[],
417420
ChartType.PUBLIC,
418421
undefined,
419-
'https://charts.bitnami.com/bitnami',
422+
'https://prometheus-community.github.io/helm-charts',
420423
undefined,
421-
'12.9.0'
424+
'25.11.0'
422425
);
423426

424-
expect(result).toContain('helm upgrade --install my-release bitnami/postgresql');
427+
expect(result).toContain('helm upgrade --install my-release prometheus-community/prometheus');
425428
expect(result).toContain('--namespace my-namespace');
426-
expect(result).toContain('--version 12.9.0');
427-
expect(result).toContain('--set "auth.username=postgres_user"');
429+
expect(result).toContain('--version 25.11.0');
430+
expect(result).toContain('--set "server.replicaCount=2"');
428431
});
429432

430433
it('should not add chart version for LOCAL charts even when version is specified', () => {
@@ -450,17 +453,17 @@ describe('Native Helm', () => {
450453
it('should not add chart version for PUBLIC charts when version is not specified', () => {
451454
const result = constructHelmCommand(
452455
'upgrade --install',
453-
'bitnami/postgresql',
456+
'prometheus-community/prometheus',
454457
'my-release',
455458
'my-namespace',
456459
[],
457460
[],
458461
ChartType.PUBLIC,
459462
undefined,
460-
'https://charts.bitnami.com/bitnami'
463+
'https://prometheus-community.github.io/helm-charts'
461464
);
462465

463-
expect(result).toContain('helm upgrade --install my-release bitnami/postgresql');
466+
expect(result).toContain('helm upgrade --install my-release prometheus-community/prometheus');
464467
expect(result).toContain('--namespace my-namespace');
465468
expect(result).not.toContain('--version');
466469
});
@@ -527,6 +530,7 @@ describe('Native Helm', () => {
527530
expect(result.env).toEqual([
528531
{ name: 'HELM_CACHE_HOME', value: '/workspace/.helm/cache' },
529532
{ name: 'HELM_CONFIG_HOME', value: '/workspace/.helm/config' },
533+
{ name: 'HELM_EXPERIMENTAL_OCI', value: '1' },
530534
]);
531535
expect(result.command).toEqual(['/bin/sh', '-c']);
532536
expect(result.args).toHaveLength(1);
@@ -756,37 +760,86 @@ describe('Native Helm', () => {
756760
});
757761
});
758762

763+
describe('createHelmContainer with ECR registry auth', () => {
764+
it('should prepend registry login script for ECR OCI charts', async () => {
765+
const registryAuth: RegistryAuthConfig = {
766+
type: 'ecr',
767+
registry: '123456789012.dkr.ecr.us-west-2.amazonaws.com',
768+
region: 'us-west-2',
769+
};
770+
771+
const result = await createHelmContainer(
772+
'no-repo',
773+
'my-chart',
774+
'my-release',
775+
'my-namespace',
776+
'3.12.0',
777+
[],
778+
[],
779+
ChartType.PUBLIC,
780+
undefined,
781+
'oci://123456789012.dkr.ecr.us-west-2.amazonaws.com/my-chart',
782+
undefined,
783+
undefined,
784+
registryAuth
785+
);
786+
787+
expect(result.args[0]).toContain(
788+
'cat /workspace/.helm/ecr-token | helm registry login "123456789012.dkr.ecr.us-west-2.amazonaws.com" --username AWS --password-stdin'
789+
);
790+
expect(result.args[0]).toContain('helm upgrade --install');
791+
});
792+
793+
it('should not include registry login script when registryAuth is absent', async () => {
794+
const result = await createHelmContainer(
795+
'no-repo',
796+
'my-chart',
797+
'my-release',
798+
'my-namespace',
799+
'3.12.0',
800+
[],
801+
[],
802+
ChartType.PUBLIC,
803+
undefined,
804+
'oci://ghcr.io/prometheus-community/helm-charts/prometheus'
805+
);
806+
807+
expect(result.args[0]).not.toContain('helm registry login');
808+
expect(result.args[0]).toContain('helm upgrade --install');
809+
});
810+
});
811+
759812
describe('Chart Version Integration', () => {
760813
it('should include chart version from global config for PUBLIC charts', async () => {
761814
mockGetAllConfigs.mockResolvedValue({
762-
postgresql: {
815+
prometheus: {
763816
version: '3.7.2',
764817
chart: {
765-
name: 'postgresql',
766-
repoUrl: 'https://charts.bitnami.com/bitnami',
767-
version: '12.9.0',
768-
values: ['auth.username=postgres_user'],
818+
name: 'prometheus',
819+
repoUrl: 'https://prometheus-community.github.io/helm-charts',
820+
version: '25.11.0',
821+
values: ['server.replicaCount=2'],
769822
},
770823
},
771824
});
772825

773826
const result = await createHelmContainer(
774827
'no-repo',
775-
'postgresql',
828+
'prometheus',
776829
'test-release',
777830
'test-namespace',
778831
'3.12.0',
779-
['auth.username=postgres_user'],
832+
['server.replicaCount=2'],
780833
[],
781834
ChartType.PUBLIC,
782835
undefined,
783-
'https://charts.bitnami.com/bitnami',
836+
'https://prometheus-community.github.io/helm-charts',
784837
undefined,
785-
'12.9.0'
838+
'25.11.0'
786839
);
787840

788-
expect(result.args[0]).toContain('--version 12.9.0');
789-
expect(result.args[0]).toContain('bitnami/postgresql');
841+
expect(result.args[0]).toContain('--version 25.11.0');
842+
expect(result.args[0]).toContain('helm-charts/prometheus');
790843
});
791844

792845
it('should include chart version from global config for ORG_CHART', async () => {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2025 GoodRx, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { detectRegistryAuth, createRegistryAuthInitContainer, generateRegistryLoginScript } from '../registryAuth';
18+
19+
describe('registryAuth', () => {
20+
describe('detectRegistryAuth', () => {
21+
it('returns ECR config for a valid ECR OCI URL', () => {
22+
const result = detectRegistryAuth('oci://123456789012.dkr.ecr.us-west-2.amazonaws.com/my-chart');
23+
24+
expect(result).toEqual({
25+
type: 'ecr',
26+
registry: '123456789012.dkr.ecr.us-west-2.amazonaws.com',
27+
region: 'us-west-2',
28+
});
29+
});
30+
31+
it('returns undefined for a non-ECR OCI URL', () => {
32+
const result = detectRegistryAuth('oci://registry-1.docker.io/helm-charts/postgresql');
33+
expect(result).toBeUndefined();
34+
});
35+
36+
it('returns undefined for a non-OCI URL', () => {
37+
const result = detectRegistryAuth('https://prometheus-community.github.io/helm-charts');
38+
expect(result).toBeUndefined();
39+
});
40+
41+
it('returns undefined when chartRepoUrl is undefined', () => {
42+
const result = detectRegistryAuth(undefined);
43+
expect(result).toBeUndefined();
44+
});
45+
46+
it('parses the correct region from the ECR URL', () => {
47+
const result = detectRegistryAuth('oci://123456789012.dkr.ecr.eu-west-1.amazonaws.com/charts/my-app');
48+
49+
expect(result?.region).toBe('eu-west-1');
50+
expect(result?.registry).toBe('123456789012.dkr.ecr.eu-west-1.amazonaws.com');
51+
});
52+
});
53+
54+
describe('createRegistryAuthInitContainer', () => {
55+
it('returns the correct init container spec for ECR', () => {
56+
const container = createRegistryAuthInitContainer({
57+
type: 'ecr',
58+
registry: '123456789012.dkr.ecr.us-west-2.amazonaws.com',
59+
region: 'us-west-2',
60+
});
61+
62+
expect(container.name).toBe('ecr-auth');
63+
expect(container.image).toBe('amazon/aws-cli:2.22.0');
64+
expect(container.command).toEqual(['/bin/sh', '-c']);
65+
expect(container.args[0]).toContain('aws ecr get-login-password --region us-west-2');
66+
expect(container.args[0]).toContain('/workspace/.helm/ecr-token');
67+
expect(container.volumeMounts).toEqual([{ name: 'helm-workspace', mountPath: '/workspace' }]);
68+
});
69+
});
70+
71+
describe('generateRegistryLoginScript', () => {
72+
it('returns the correct helm registry login command for ECR', () => {
73+
const script = generateRegistryLoginScript({
74+
type: 'ecr',
75+
registry: '123456789012.dkr.ecr.us-west-2.amazonaws.com',
76+
region: 'us-west-2',
77+
});
78+
79+
expect(script).toBe(
80+
'cat /workspace/.helm/ecr-token | helm registry login "123456789012.dkr.ecr.us-west-2.amazonaws.com" --username AWS --password-stdin'
81+
);
82+
});
83+
});
84+
});

‎src/server/lib/nativeHelm/helm.ts‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
validateHelmConfiguration,
4343
resolveHelmReleaseConflicts,
4444
} from './utils';
45+
import { detectRegistryAuth, RegistryAuthConfig } from './registryAuth';
4546
import { HELM_IMAGE_PREFIX } from './constants';
4647
import {
4748
createCloneScript,
@@ -72,7 +73,8 @@ export async function createHelmContainer(
7273
args?: string,
7374
chartRepoUrl?: string,
7475
defaultArgs?: string,
75-
chartVersion?: string
76+
chartVersion?: string,
77+
registryAuth?: RegistryAuthConfig
7678
): Promise<any> {
7779
const script = generateHelmInstallScript(
7880
repoName,
@@ -85,21 +87,17 @@ export async function createHelmContainer(
8587
args,
8688
chartRepoUrl,
8789
defaultArgs,
88-
chartVersion
90+
chartVersion,
91+
registryAuth
8992
);
9093

9194
return {
9295
name: 'helm-deploy',
9396
image: `${HELM_IMAGE_PREFIX}:${helmVersion}`,
9497
env: [
95-
{
96-
name: 'HELM_CACHE_HOME',
97-
value: '/workspace/.helm/cache',
98-
},
99-
{
100-
name: 'HELM_CONFIG_HOME',
101-
value: '/workspace/.helm/config',
102-
},
98+
{ name: 'HELM_CACHE_HOME', value: '/workspace/.helm/cache' },
99+
{ name: 'HELM_CONFIG_HOME', value: '/workspace/.helm/config' },
100+
{ name: 'HELM_EXPERIMENTAL_OCI', value: '1' },
103101
],
104102
command: ['/bin/sh', '-c'],
105103
args: [script],
@@ -138,6 +136,7 @@ export async function generateHelmManifest(deploy: Deploy, jobId: string, option
138136
const chartVersion = mergedHelmConfig.chart?.version;
139137
const helmArgs = mergedHelmConfig.args;
140138
const defaultArgs = mergedHelmConfig.nativeHelm?.defaultArgs;
139+
const registryAuth = detectRegistryAuth(chartRepoUrl);
141140

142141
const helmContainer = await createHelmContainer(
143142
repository?.fullName || 'no-repo',
@@ -151,7 +150,8 @@ export async function generateHelmManifest(deploy: Deploy, jobId: string, option
151150
helmArgs,
152151
chartRepoUrl,
153152
defaultArgs,
154-
chartVersion
153+
chartVersion,
154+
registryAuth
155155
);
156156

157157
const volumeConfig = {
@@ -191,6 +191,7 @@ export async function generateHelmManifest(deploy: Deploy, jobId: string, option
191191
volumes: volumeConfig.volumes,
192192
deployMetadata,
193193
includeGitClone: shouldIncludeGitClone,
194+
registryAuth,
194195
});
195196

196197
return yaml.dump(job);

0 commit comments

Comments
 (0)