Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/schema/yaml/1.0.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ services:
args:
# @param services.helm.nativeHelm.postRenderer.args[]
- ''
# @param services.helm.skipImageBuild
skipImageBuild: false
# @param services.codefresh
codefresh:
# @param services.codefresh.repository (required)
Expand Down
34 changes: 34 additions & 0 deletions src/server/lib/jsonschema/schemas/1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,40 @@
}
}
}
},
"skipImageBuild": {
"type": "boolean",
"default": false,
"description": "Skip image building for a native Helm service that uses prebuilt images in its chart values. Requires deploymentMethod: native and no docker configuration."
}
},
"if": {
"properties": {
"skipImageBuild": {
"enum": [
true
]
}
},
"required": [
"skipImageBuild"
]
},
"then": {
"properties": {
"deploymentMethod": {
"enum": [
"native"
]
}
},
"required": [
"deploymentMethod"
],
"not": {
"required": [
"docker"
]
}
}
},
Expand Down
55 changes: 55 additions & 0 deletions src/server/lib/nativeHelm/__tests__/helm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jest.mock('server/lib/nativeBuild/utils', () => {
return {
...originalModule,
waitForJobAndGetLogs: jest.fn(),
getGitHubToken: jest.fn().mockResolvedValue('test-github-token'),
};
});
jest.mock('server/services/logArchival', () => ({
Expand Down Expand Up @@ -1868,6 +1869,60 @@ describe('Native Helm', () => {
});

describe('generateHelmManifest', () => {
it('checks out the pinned chart revision and deploys a local chart with image building disabled', async () => {
mockGetAllConfigs.mockResolvedValue({});
(nativeHelmUtils.determineChartType as jest.Mock).mockImplementation(
jest.requireActual('../utils').determineChartType
);
(nativeHelmUtils.mergeHelmConfigWithGlobal as jest.Mock).mockImplementation(
jest.requireActual('../utils').mergeHelmConfigWithGlobal
);
const deploy = {
uuid: 'gateway-preview',
sha: 'accepted-chart-commit',
branchName: 'chart-main',
id: 42,
deployableId: 99,
deployable: {
name: 'gateway',
repository: { fullName: 'example-org/chart-repo' },
helm: {
deploymentMethod: 'native',
skipImageBuild: true,
args: '--dependency-update',
chart: { name: './charts/gateway' },
},
},
build: { uuid: 'preview', namespace: 'env-preview', isStatic: false },
$fetchGraph: jest.fn().mockResolvedValue(undefined),
} as any;

const manifest = await generateHelmManifest(
deploy,
'test-job',
{ namespace: 'env-preview' },
{
chartType: ChartType.LOCAL,
customValues: [],
helmSecretRefs: [],
secretSetFiles: [],
valuesFiles: ['charts/gateway/values-preview.yaml'],
chartPath: './charts/gateway',
releaseName: 'gateway-preview',
helmVersion: '3.18.6',
}
);
const job = yaml.load(manifest) as any;
const clone = job.spec.template.spec.initContainers.find((container) => container.name === 'clone-repo');
expect(clone).toBeDefined();
expect(JSON.stringify(clone)).toContain('example-org/chart-repo');
expect(JSON.stringify(clone)).toContain('accepted-chart-commit');
const runner = job.spec.template.spec.containers.find((container) => container.name === 'helm-deploy');
expect(runner.args[0]).toContain('helm upgrade --install gateway-preview ./charts/gateway');
expect(runner.args[0]).toContain('-f ./charts/gateway/values-preview.yaml');
expect(runner.args[0]).toContain('--dependency-update');
});

it('builds the expected manifest for plain native Helm without a renderer', async () => {
mockGetAllConfigs.mockResolvedValue({
publicChart: { block: false },
Expand Down
17 changes: 17 additions & 0 deletions src/server/lib/yamlSchemas/schema_1_0_0/schema_1_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ const schema_1_0_0 = {
helm: {
type: 'object',
additionalProperties: true,
if: {
properties: { skipImageBuild: { enum: [true] } },
required: ['skipImageBuild'],
},
then: {
properties: {
deploymentMethod: { enum: ['native'] },
},
required: ['deploymentMethod'],
not: { required: ['docker'] },
},
properties: {
cfStepType: { type: 'string' },
type: { type: 'string' },
Expand All @@ -176,6 +187,12 @@ const schema_1_0_0 = {
repository: { type: 'string' },
branchName: { type: 'string' },
deploymentMethod: { type: 'string', enum: ['native', 'ci'] },
skipImageBuild: {
type: 'boolean',
default: false,
description:
'Skip image building for a native Helm service that uses prebuilt images in its chart values. Requires deploymentMethod: native and no docker configuration.',
},
chart: {
type: 'object',
additionalProperties: false,
Expand Down
9 changes: 9 additions & 0 deletions src/server/models/yaml/YamlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export interface Helm {
readonly builder?: Builder;
readonly envLens?: boolean;
readonly deploymentMethod?: 'native' | 'ci';
readonly skipImageBuild?: boolean;
readonly nativeHelm?: NativeHelmConfig;
readonly envMapping?: {
readonly app?: {
Expand Down Expand Up @@ -573,6 +574,14 @@ export async function getHelmConfigFromYaml(service: Service): Promise<Helm> {

const helmConfig = _.merge({}, helmDefaults, chartConfig, helmService);

// Chart-only services must not inherit Docker build inputs from installation defaults.
if (helmService?.skipImageBuild === true) {
if (helmService.docker) {
throw new Error('helm.skipImageBuild cannot be combined with helm.docker');
}
delete helmConfig.docker;
}

// Preserve value files from service config if specified
if (helmService?.chart?.valueFiles?.length > 0) {
helmConfig.chart.values = helmService.chart.values;
Expand Down
92 changes: 92 additions & 0 deletions src/server/models/yaml/tests/YamlService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,98 @@ services:
});
});

describe('helm.skipImageBuild', () => {
const configFor = (helm = {}) => ({
version: '1.0.0',
services: [
{
name: 'gateway',
helm: {
repository: 'org/chart-repo',
branchName: 'main',
deploymentMethod: 'native',
chart: { name: './charts/gateway' },
...helm,
},
},
],
});

test.each([undefined, false, true])('accepts boolean opt-in %s', (skipImageBuild) => {
expect(() => new YamlConfigValidator().validate_1_0_0(configFor({ skipImageBuild }) as any)).not.toThrow();
});

test.each(['true', 1, null])('rejects non-boolean opt-in %s', (skipImageBuild) => {
expect(() => new YamlConfigValidator().validate_1_0_0(configFor({ skipImageBuild }) as any)).toThrow();
});

test('identifies the missing native deployment method', () => {
expect(() =>
new YamlConfigValidator().validate_1_0_0(
configFor({ skipImageBuild: true, deploymentMethod: undefined }) as any
)
).toThrow('requires property "deploymentMethod"');
});

test('identifies an incompatible deployment method', () => {
expect(() =>
new YamlConfigValidator().validate_1_0_0(configFor({ skipImageBuild: true, deploymentMethod: 'ci' }) as any)
).toThrow('helm.deploymentMethod is not one of enum values: native');
});

test('rejects opt-in combined with a Docker build declaration', () => {
expect(() =>
new YamlConfigValidator().validate_1_0_0(
configFor({
skipImageBuild: true,
docker: { defaultTag: 'main', app: { dockerfilePath: 'Dockerfile' } },
}) as any
)
).toThrow();
});

test.each([undefined, false])('preserves legacy Docker declarations when the option is %s', (skipImageBuild) => {
expect(() =>
new YamlConfigValidator().validate_1_0_0(
configFor({
skipImageBuild,
deploymentMethod: 'ci',
docker: { defaultTag: 'main', app: { dockerfilePath: 'Dockerfile' } },
}) as any
)
).not.toThrow();
});

test('explicit opt-in overrides inherited Docker defaults without mutating them', async () => {
const defaults = {
helmDefaults: { docker: { defaultTag: 'main', app: { dockerfilePath: 'default.Dockerfile' } } },
};
mockGetAllConfigs.mockResolvedValue(defaults);
const service = configFor({ skipImageBuild: true }).services[0];
const helm = await YamlService.getHelmConfigFromYaml(service as any);

expect(helm.skipImageBuild).toBe(true);
expect(helm.chart.name).toBe('./charts/gateway');
expect(helm.docker).toBeUndefined();
expect(defaults.helmDefaults.docker.app.dockerfilePath).toBe('default.Dockerfile');

const legacyHelm = await YamlService.getHelmConfigFromYaml(configFor().services[0] as any);
expect(legacyHelm.docker.app.dockerfilePath).toBe('default.Dockerfile');
});

test('does not discard an explicit Docker declaration when merging an unchecked service', async () => {
mockGetAllConfigs.mockResolvedValue({});
const service = configFor({
skipImageBuild: true,
docker: { defaultTag: 'main', app: { dockerfilePath: 'Dockerfile' } },
}).services[0];

await expect(YamlService.getHelmConfigFromYaml(service as any)).rejects.toThrow(
'helm.skipImageBuild cannot be combined with helm.docker'
);
});
});

describe('hasLifecycleManagedDockerBuild', () => {
test('returns true for github services with docker config', () => {
const parser = new YamlConfigParser();
Expand Down
Loading
Loading