Stop rejecting application install when APP_VERSION is wrong (#20443)
as title allows to install https://github.com/JordanChoo/twenty-multi-pipeline locally
This commit is contained in:
+1
-1
@@ -137,7 +137,7 @@ export class ApplicationInstallService {
|
||||
resolvedPackage.packageJson.engines?.['twenty'];
|
||||
|
||||
const versionValidation =
|
||||
this.applicationVersionValidationService.validateServerCompatibility(
|
||||
await this.applicationVersionValidationService.validateServerCompatibility(
|
||||
requiredServerVersion,
|
||||
);
|
||||
|
||||
|
||||
+2
@@ -7,11 +7,13 @@ import { ApplicationEntity } from 'src/engine/core-modules/application/applicati
|
||||
import { FileStorageModule } from 'src/engine/core-modules/file-storage/file-storage.module';
|
||||
import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';
|
||||
import { TwentyConfigModule } from 'src/engine/core-modules/twenty-config/twenty-config.module';
|
||||
import { UpgradeModule } from 'src/engine/core-modules/upgrade/upgrade.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
FileStorageModule,
|
||||
TwentyConfigModule,
|
||||
UpgradeModule,
|
||||
TypeOrmModule.forFeature([FileEntity, ApplicationEntity]),
|
||||
],
|
||||
providers: [
|
||||
|
||||
+15
-10
@@ -2,8 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
|
||||
import semver from 'semver';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
|
||||
export type VersionValidationFailureReason =
|
||||
| 'INVALID_REQUIRED_VERSION'
|
||||
@@ -20,11 +19,13 @@ export type VersionValidationResult =
|
||||
|
||||
@Injectable()
|
||||
export class ApplicationVersionValidationService {
|
||||
constructor(private readonly twentyConfigService: TwentyConfigService) {}
|
||||
constructor(
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
) {}
|
||||
|
||||
validateServerCompatibility(
|
||||
async validateServerCompatibility(
|
||||
requiredServerVersion: string | undefined,
|
||||
): VersionValidationResult {
|
||||
): Promise<VersionValidationResult> {
|
||||
if (!isDefined(requiredServerVersion)) {
|
||||
return { compatible: true };
|
||||
}
|
||||
@@ -37,21 +38,25 @@ export class ApplicationVersionValidationService {
|
||||
};
|
||||
}
|
||||
|
||||
const serverVersion = this.twentyConfigService.get('APP_VERSION');
|
||||
const inferredServerVersion =
|
||||
await this.upgradeMigrationService.getInferredVersion();
|
||||
|
||||
if (!isDefined(serverVersion) || !isDefined(semver.valid(serverVersion))) {
|
||||
if (
|
||||
!isDefined(inferredServerVersion) ||
|
||||
!isDefined(semver.valid(inferredServerVersion))
|
||||
) {
|
||||
return {
|
||||
compatible: false,
|
||||
reason: 'INVALID_SERVER_VERSION',
|
||||
message: `Cannot verify server compatibility: APP_VERSION "${serverVersion ?? 'undefined'}" is not a valid semver version. Self-hosted instances must set a valid APP_VERSION.`,
|
||||
message: `Cannot verify server compatibility: inferred server version "${inferredServerVersion ?? 'undefined'}" is not a valid semver version.`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!semver.satisfies(serverVersion, requiredServerVersion)) {
|
||||
if (!semver.satisfies(inferredServerVersion, requiredServerVersion)) {
|
||||
return {
|
||||
compatible: false,
|
||||
reason: 'INCOMPATIBLE',
|
||||
message: `App requires Twenty server ${requiredServerVersion} but this server is ${serverVersion}.`,
|
||||
message: `App requires Twenty server ${requiredServerVersion} but this server is ${inferredServerVersion}.`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ export class ApplicationTarballService {
|
||||
const requiredServerVersion = packageJson?.engines?.twenty;
|
||||
|
||||
const versionValidation =
|
||||
this.applicationVersionValidationService.validateServerCompatibility(
|
||||
await this.applicationVersionValidationService.validateServerCompatibility(
|
||||
requiredServerVersion,
|
||||
);
|
||||
|
||||
|
||||
+8
@@ -50,6 +50,7 @@ const buildWorkspaceCacheGetMock = (
|
||||
describe('UpgradeStatusService', () => {
|
||||
let service: UpgradeStatusService;
|
||||
let getLastAttemptedInstanceCommand: jest.Mock;
|
||||
let getInferredVersion: jest.Mock;
|
||||
let getWorkspaceLastAttemptedCommandName: jest.Mock;
|
||||
let workspaceFind: jest.Mock;
|
||||
let coreEntityCacheGet: jest.Mock;
|
||||
@@ -68,6 +69,12 @@ describe('UpgradeStatusService', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
getLastAttemptedInstanceCommand = jest.fn();
|
||||
getInferredVersion = jest.fn(async (name?: string) => {
|
||||
if (!name) return null;
|
||||
const idx = name.indexOf('_');
|
||||
|
||||
return idx === -1 ? null : name.substring(0, idx);
|
||||
});
|
||||
getWorkspaceLastAttemptedCommandName = jest.fn();
|
||||
workspaceFind = jest.fn().mockResolvedValue([]);
|
||||
coreEntityCacheGet = jest.fn().mockResolvedValue(null);
|
||||
@@ -84,6 +91,7 @@ describe('UpgradeStatusService', () => {
|
||||
provide: UpgradeMigrationService,
|
||||
useValue: {
|
||||
getLastAttemptedInstanceCommand,
|
||||
getInferredVersion,
|
||||
getWorkspaceLastAttemptedCommandName,
|
||||
},
|
||||
},
|
||||
|
||||
+13
@@ -9,6 +9,7 @@ import {
|
||||
UpgradeMigrationStatus,
|
||||
} from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import { formatUpgradeErrorForStorage } from 'src/engine/core-modules/upgrade/utils/format-upgrade-error-for-storage.util';
|
||||
import { extractVersionFromCommandName } from 'src/engine/core-modules/upgrade/utils/extract-version-from-command-name.util';
|
||||
|
||||
export type WorkspaceLastAttemptedCommand = {
|
||||
workspaceId: string;
|
||||
@@ -27,6 +28,18 @@ export class UpgradeMigrationService {
|
||||
private readonly upgradeMigrationRepository: Repository<UpgradeMigrationEntity>,
|
||||
) {}
|
||||
|
||||
async getInferredVersion(commandName?: string): Promise<string | null> {
|
||||
if (isDefined(commandName)) {
|
||||
return extractVersionFromCommandName(commandName);
|
||||
}
|
||||
|
||||
const migration = await this.getLastAttemptedInstanceCommand();
|
||||
|
||||
return isDefined(migration)
|
||||
? extractVersionFromCommandName(migration.name)
|
||||
: null;
|
||||
}
|
||||
|
||||
async isLastAttemptCompleted({
|
||||
name,
|
||||
workspaceId,
|
||||
|
||||
+20
-13
@@ -10,7 +10,7 @@ import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/service
|
||||
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { UpgradeStatusCacheService } from 'src/engine/core-modules/upgrade/services/upgrade-status-cache.service';
|
||||
import { type UpgradeMigrationStatus } from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import { extractVersionFromCommandName } from 'src/engine/core-modules/upgrade/utils/extract-version-from-command-name.util';
|
||||
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { In, Repository } from 'typeorm';
|
||||
|
||||
@@ -91,7 +91,10 @@ export class UpgradeStatusService {
|
||||
step.kind === 'fast-instance' || step.kind === 'slow-instance',
|
||||
);
|
||||
|
||||
return this.buildCursorStatus(migration, lastInstanceStep?.name ?? null);
|
||||
return await this.buildCursorStatus(
|
||||
migration,
|
||||
lastInstanceStep?.name ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
async getWorkspaceStatuses(
|
||||
@@ -122,14 +125,16 @@ export class UpgradeStatusService {
|
||||
const lastStepName =
|
||||
sequence.length > 0 ? sequence[sequence.length - 1].name : null;
|
||||
|
||||
return workspaces.map((workspace) => ({
|
||||
...this.buildCursorStatus(
|
||||
cursors.get(workspace.id) ?? null,
|
||||
lastStepName,
|
||||
),
|
||||
workspaceId: workspace.id,
|
||||
displayName: workspace.displayName ?? null,
|
||||
}));
|
||||
return Promise.all(
|
||||
workspaces.map(async (workspace) => ({
|
||||
...(await this.buildCursorStatus(
|
||||
cursors.get(workspace.id) ?? null,
|
||||
lastStepName,
|
||||
)),
|
||||
workspaceId: workspace.id,
|
||||
displayName: workspace.displayName ?? null,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
async getInstanceAndAllWorkspacesStatus(): Promise<InstanceAndAllWorkspacesUpgradeStatus> {
|
||||
@@ -209,10 +214,10 @@ export class UpgradeStatusService {
|
||||
await this.upgradeStatusCacheService.invalidate();
|
||||
}
|
||||
|
||||
private buildCursorStatus(
|
||||
private async buildCursorStatus(
|
||||
migration: LatestUpgradeCommand | null,
|
||||
lastExpectedCommandName: string | null,
|
||||
): InstanceUpgradeStatus {
|
||||
): Promise<InstanceUpgradeStatus> {
|
||||
if (!migration) {
|
||||
return {
|
||||
inferredVersion: null,
|
||||
@@ -224,7 +229,9 @@ export class UpgradeStatusService {
|
||||
const health = deriveHealth(migration, lastExpectedCommandName);
|
||||
|
||||
return {
|
||||
inferredVersion: extractVersionFromCommandName(migration.name),
|
||||
inferredVersion: await this.upgradeMigrationService.getInferredVersion(
|
||||
migration.name,
|
||||
),
|
||||
health,
|
||||
latestCommand: {
|
||||
name: migration.name,
|
||||
|
||||
Reference in New Issue
Block a user