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
9 changes: 3 additions & 6 deletions src/server/models/yaml/YamlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,9 @@ export const getDockerBuildPipelineId = (service) =>
service?.helm?.docker?.pipelineId || service?.github?.docker?.pipelineId;

export async function getPublicUrl(service: Service, build: Build): Promise<string> {
const { lifecycleDefaults, domainDefaults } = await GlobalConfigService.getInstance().getAllConfigs();
let host = lifecycleDefaults.defaultUUID;
let { http: httpDomain, grpc: grpcDomain } = domainDefaults;
if (build?.enabledFeatures.includes(FeatureFlags.NO_DEFAULT_ENV_RESOLVE)) {
host = NO_DEFAULT_ENV_UUID;
}
const { domainDefaults } = await GlobalConfigService.getInstance().getAllConfigs();
const host = await getUUID(service, build);
const { http: httpDomain, grpc: grpcDomain } = domainDefaults;

if (DeployTypes.HELM === getDeployType(service)) {
const helmService = (service as unknown as HelmService).helm;
Expand Down
37 changes: 36 additions & 1 deletion src/server/models/yaml/tests/YamlService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mockRedisClient();

import { YamlConfigParser } from 'server/lib/yamlConfigParser';
import { YamlConfigValidator } from 'server/lib/yamlConfigValidator';
import { DeployTypes } from 'shared/constants';
import { Build } from 'server/models';
import { DeployTypes, FeatureFlags, NO_DEFAULT_ENV_UUID } from 'shared/constants';
import * as YamlService from '../index';

const mockGetAllConfigs = jest.fn();
Expand Down Expand Up @@ -587,6 +588,40 @@ services:
});
});

describe('getPublicUrl', () => {
beforeEach(() => {
mockGetAllConfigs.mockResolvedValue({
lifecycleDefaults: { defaultUUID: 'dev-0' },
domainDefaults: { http: 'lifecycle.example.com', grpc: 'lifecycle-grpc.example.com' },
});
});

test('falls back to the global default UUID when the service has none configured', async () => {
const service: YamlService.Service = { name: 'my-service' } as YamlService.Service;
const build = { enabledFeatures: [] } as unknown as Build;

await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual('my-service-dev-0.lifecycle.example.com');
});

test('uses the service-level defaultUUID override when configured', async () => {
const service: YamlService.Service = { name: 'my-service', defaultUUID: 'sandbox' } as YamlService.Service;
const build = { enabledFeatures: [] } as unknown as Build;

await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual(
'my-service-sandbox.lifecycle.example.com'
);
});

test('NO_DEFAULT_ENV_RESOLVE takes priority over a service-level defaultUUID override', async () => {
const service: YamlService.Service = { name: 'my-service', defaultUUID: 'sandbox' } as YamlService.Service;
const build = { enabledFeatures: [FeatureFlags.NO_DEFAULT_ENV_RESOLVE] } as unknown as Build;

await expect(YamlService.getPublicUrl(service, build)).resolves.toEqual(
`my-service-${NO_DEFAULT_ENV_UUID}.lifecycle.example.com`
);
});
});

describe('getEnvironmentVariables', () => {
test('GithubService', () => {
const parser = new YamlConfigParser();
Expand Down
74 changes: 74 additions & 0 deletions src/server/services/__tests__/deployable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jest.mock('server/lib/github', () => ({
}));

import * as YamlService from 'server/models/yaml';
import { Build } from 'server/models';
import { FeatureFlags, NO_DEFAULT_ENV_UUID } from 'shared/constants';
import DeployableService, { DeployableAttributes } from '../deployable';

const lifecycleDefaults = {
Expand Down Expand Up @@ -260,6 +262,78 @@ describe('Deployable Service', () => {
});
});

test('service-level defaultUUID overrides the global default for hostname/URL fallbacks', async () => {
const githubService: YamlService.GithubService = {
name: 'github-app',
defaultUUID: 'sandbox',
github: {
repository: 'example-org/example-service',
branchName: 'unit-test',
docker: {
defaultTag: 'main',
app: {
dockerfilePath: 'app1/app.Dockerfile',
},
},
},
};

const build = { enabledFeatures: [] } as unknown as Build;

// @ts-ignore
const result: DeployableAttributes = await deployableService.generateAttributesFromYamlConfig(
100,
'unit-test-12345',
1234567890,
'unit-test',
githubService,
false,
'',
build
);

expect(result.defaultUUID).toEqual('sandbox');
expect(result.defaultInternalHostname).toEqual('github-app-sandbox');
expect(result.defaultPublicUrl).toEqual(`github-app-sandbox.${domainDefaults.http}`);
expect(result.defaultGrpcHost).toEqual(`github-app-sandbox.${domainDefaults.grpc}`);
});

test('NO_DEFAULT_ENV_RESOLVE takes priority over a service-level defaultUUID override', async () => {
const githubService: YamlService.GithubService = {
name: 'github-app',
defaultUUID: 'sandbox',
github: {
repository: 'example-org/example-service',
branchName: 'unit-test',
docker: {
defaultTag: 'main',
app: {
dockerfilePath: 'app1/app.Dockerfile',
},
},
},
};

const build = { enabledFeatures: [FeatureFlags.NO_DEFAULT_ENV_RESOLVE] } as unknown as Build;

// @ts-ignore
const result: DeployableAttributes = await deployableService.generateAttributesFromYamlConfig(
100,
'unit-test-12345',
1234567890,
'unit-test',
githubService,
false,
'',
build
);

expect(result.defaultUUID).toEqual(NO_DEFAULT_ENV_UUID);
expect(result.defaultInternalHostname).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}`);
expect(result.defaultPublicUrl).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}.${domainDefaults.http}`);
expect(result.defaultGrpcHost).toEqual(`github-app-${NO_DEFAULT_ENV_UUID}.${domainDefaults.grpc}`);
});

test('Generate config should have httpGet port and path', async () => {
const githubService: YamlService.GithubService = {
name: 'github-app',
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/deployable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default class DeployableService extends BaseService {
const { serviceDefaults, lifecycleDefaults, domainDefaults, buildDefaults } =
await GlobalConfigService.getInstance().getAllConfigs();
//TODO check and throw error here?
const defaultUUID = lifecycleDefaults.defaultUUID;
const defaultUUID = await YamlService.getUUID(service, build);
const dockerBuildPipelineName =
YamlService.getDockerBuildPipelineId(service) || lifecycleDefaults.buildPipeline;

Expand Down Expand Up @@ -262,7 +262,7 @@ export default class DeployableService extends BaseService {
deployment?.network?.grpc?.defaultHost ?? `${service.name}-${defaultUUID}.${domainDefaults.grpc}`,

ingressAnnotations: deployment?.network?.ingressAnnotations ?? {},
defaultUUID: await YamlService.getUUID(service, build),
defaultUUID,
serviceDisksYaml: deployment?.serviceDisks ? JSON.stringify(deployment.serviceDisks) : null,

nodeSelector: deployment?.node_selector ?? null,
Expand Down
Loading