Skip to content

Commit d03a951

Browse files
Remove the ENVIRONMENT variable and replace it with specific ones
1 parent efe84d6 commit d03a951

17 files changed

Lines changed: 85 additions & 69 deletions

File tree

.env.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ OPS_BLOCKS_SOURCE='FILE'
1515
OPS_BLOCKS_SYNC_MODE=NONE
1616
OPS_ENABLE_HOST_SESSION=false
1717
OPS_EXEC_FILE_MAX_BUFFER_SIZE_MB=
18+
OPS_BLOCK_CACHE_ENABLED=false
19+
OPS_BLOCKS_HOT_RELOAD_ENABLED=true
20+
OPS_FAST_SHUTDOWN_ENABLED=true
21+
OPS_BLOCKS_BUILDER_ENABLED=true
22+
OPS_ENGINE_METADATA_CACHE_ENABLED=false
23+
OPS_SHOW_DEV_MODE_WARNING=true
24+
OPS_SEED_DEV_DATA=true
1825

1926
# QUEUE CONFIGURATION
2027
OPS_QUEUE_MODE=REDIS

packages/server/api/.env.tests

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ OPS_API_KEY=api-key
22
OPS_QUEUE_MODE=MEMORY
33
OPS_DB_TYPE=SQLITE3
44
OPS_ENVIRONMENT=test
5+
OPS_ENGINE_QUEUE_UPDATES_ENABLED=false
6+
OPS_RUN_DB_MIGRATIONS=false
7+
OPS_DB_SYNCHRONIZE_SCHEMA=true
8+
OPS_REQUIRE_ENGINE_VALIDATE_AUTH=false
59
OPS_ENCRYPTION_KEY=7e19fad4c13eaea8f657afb12e8f9c40
610
OPS_FRONTEND_URL=http://localhost:4200
711
OPS_WEBHOOK_TIMEOUT_SECONDS=30

packages/server/api/src/app/app-connection/app-connection-service/validate-auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
AppConnectionValue,
44
ApplicationError,
55
EngineResponseStatus,
6-
EnvironmentType,
76
ErrorCode,
87
ProjectId,
98
} from '@openops/shared';
@@ -14,8 +13,9 @@ import { findBlockByAuthProviderKey } from '../connection-providers-resolver';
1413
export const engineValidateAuth = async (
1514
params: EngineValidateAuthParams,
1615
): Promise<void> => {
17-
const environment = system.getOrThrow(SharedSystemProp.ENVIRONMENT);
18-
if (environment === EnvironmentType.TESTING) {
16+
const shouldValidateAuth =
17+
system.getBoolean(SharedSystemProp.REQUIRE_ENGINE_VALIDATE_AUTH) ?? true;
18+
if (!shouldValidateAuth) {
1919
return;
2020
}
2121
const { authProviderKey, auth, projectId } = params;

packages/server/api/src/app/app.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from '@openops/server-shared';
1919
import {
2020
AppConnectionWithoutSensitiveData,
21-
EnvironmentType,
2221
Flow,
2322
FlowImportTemplate,
2423
FlowRun,
@@ -311,10 +310,11 @@ The application started on ${system.get(
311310
logger.info(`Node version: ${process.version}`);
312311
logger.info(`Blocks will be loaded from source type ${blocksSource}`);
313312

314-
const environment = system.get(SharedSystemProp.ENVIRONMENT);
315-
if (environment === EnvironmentType.DEVELOPMENT) {
313+
const environmentName =
314+
system.get(SharedSystemProp.ENVIRONMENT_NAME) ?? 'unknown';
315+
if (system.getBoolean(SharedSystemProp.SHOW_DEV_MODE_WARNING)) {
316316
logger.warn(
317-
`[WARNING]: The application is running in ${environment} mode.`,
317+
`[WARNING]: The application is running in ${environmentName} mode.`,
318318
);
319319
}
320320
}

packages/server/api/src/app/database/database-connection.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import {
2-
AppSystemProp,
3-
DatabaseType,
4-
SharedSystemProp,
5-
system,
6-
} from '@openops/server-shared';
7-
import { EnvironmentType, isNil } from '@openops/shared';
1+
import { AppSystemProp, DatabaseType, system } from '@openops/server-shared';
2+
import { isNil } from '@openops/shared';
83
import {
94
ArrayContains,
105
DataSource,
@@ -67,13 +62,7 @@ function getEntities(): EntitySchema<unknown>[] {
6762
}
6863

6964
const getSynchronize = (): boolean => {
70-
const env = system.getOrThrow<EnvironmentType>(SharedSystemProp.ENVIRONMENT);
71-
72-
const value: Partial<Record<EnvironmentType, boolean>> = {
73-
[EnvironmentType.TESTING]: true,
74-
};
75-
76-
return value[env] ?? false;
65+
return system.getBoolean(AppSystemProp.DB_SYNCHRONIZE_SCHEMA) ?? false;
7766
};
7867

7968
export const commonProperties = {

packages/server/api/src/app/database/postgres-connection.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
AppSystemProp,
3-
SharedSystemProp,
4-
system,
5-
} from '@openops/server-shared';
6-
import { EnvironmentType, isNil } from '@openops/shared';
1+
import { AppSystemProp, system } from '@openops/server-shared';
2+
import { isNil } from '@openops/shared';
73
import { TlsOptions } from 'node:tls';
84
import { DataSource, MigrationInterface } from 'typeorm';
95
import { commonProperties } from './database-connection';
@@ -90,9 +86,10 @@ const getMigrations = (): (new () => MigrationInterface)[] => {
9086
};
9187

9288
const getMigrationConfig = (): MigrationConfig => {
93-
const env = system.getOrThrow<EnvironmentType>(SharedSystemProp.ENVIRONMENT);
89+
const runDbMigrations =
90+
system.getBoolean(AppSystemProp.RUN_DB_MIGRATIONS) ?? true;
9491

95-
if (env === EnvironmentType.TESTING) {
92+
if (!runDbMigrations) {
9693
return {};
9794
}
9895

packages/server/api/src/app/database/seeds/dev-seeds.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { logger, SharedSystemProp, system } from '@openops/server-shared';
2-
import { EnvironmentType, Provider } from '@openops/shared';
1+
import { AppSystemProp, logger, system } from '@openops/server-shared';
2+
import { Provider } from '@openops/shared';
33
import { getAuthenticationService } from '../../authentication/authentication-service-factory';
44
import { FlagEntity } from '../../flags/flag.entity';
55
import { databaseConnection } from '../database-connection';
66

77
const DEV_DATA_SEEDED_FLAG = 'DEV_DATA_SEEDED';
88

9-
const currentEnvIsNotDev = (): boolean => {
10-
const env = system.get(SharedSystemProp.ENVIRONMENT);
11-
return env !== EnvironmentType.DEVELOPMENT;
9+
const devSeedingEnabled = (): boolean => {
10+
return system.getBoolean(AppSystemProp.SEED_DEV_DATA) ?? false;
1211
};
1312

1413
const devDataAlreadySeeded = async (): Promise<boolean> => {
@@ -49,11 +48,8 @@ const seedDevUser = async (): Promise<void> => {
4948
};
5049

5150
export const seedDevData = async (): Promise<void> => {
52-
if (currentEnvIsNotDev()) {
53-
logger.info(
54-
{ name: 'seedDevData' },
55-
'skip: not in development environment',
56-
);
51+
if (!devSeedingEnabled()) {
52+
logger.info({ name: 'seedDevData' }, 'skip: dev data seeding disabled');
5753
return;
5854
}
5955

packages/server/api/src/app/flags/flag.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const flagService = {
4343
flags.push(
4444
{
4545
id: FlagId.ENVIRONMENT,
46-
value: system.get(SharedSystemProp.ENVIRONMENT),
46+
value: system.get(SharedSystemProp.ENVIRONMENT_NAME),
4747
created,
4848
updated,
4949
},

packages/server/api/src/app/workers/engine-controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
assertNotNullOrUndefined,
1616
EngineHttpResponse,
1717
EnginePrincipal,
18-
EnvironmentType,
1918
ErrorCode,
2019
ExecutionState,
2120
FlowRunId,
@@ -83,8 +82,10 @@ export const flowEngineWorker: FastifyPluginAsyncTypebox = async (app) => {
8382
},
8483
},
8584
async (request) => {
86-
const environment = system.getOrThrow(SharedSystemProp.ENVIRONMENT);
87-
if (environment === EnvironmentType.TESTING) {
85+
const queueUpdatesEnabled =
86+
system.getBoolean(SharedSystemProp.ENGINE_QUEUE_UPDATES_ENABLED) ??
87+
true;
88+
if (!queueUpdatesEnabled) {
8889
return {};
8990
}
9091
const enginePrincipal = request.principal as unknown as EnginePrincipal;

packages/server/shared/src/lib/blocks-builder.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { SharedSystemProp, system } from './system';
2121

2222
const isFileBlocks =
2323
system.getOrThrow(SharedSystemProp.BLOCKS_SOURCE) === 'FILE';
24-
const isDevEnv = system.getOrThrow(SharedSystemProp.ENVIRONMENT) === 'dev';
24+
const blocksBuilderEnabled =
25+
system.getBoolean(SharedSystemProp.BLOCKS_BUILDER_ENABLED) ?? false;
2526

2627
const depBuildCache = loadBuildCache();
2728

@@ -105,14 +106,12 @@ async function analyzeDependencies(): Promise<BuildResult> {
105106
}
106107

107108
export async function blocksBuilder(): Promise<void> {
108-
// Only run this script if the blocks source is file and the environment is dev
109-
if (!isFileBlocks || !isDevEnv) {
109+
// Only run this script if the blocks source is file and incremental building is enabled
110+
if (!isFileBlocks || !blocksBuilderEnabled) {
110111
return;
111112
}
112113

113-
logger.info(
114-
'Development environment detected - using smart incremental building',
115-
);
114+
logger.info('Blocks builder enabled - using smart incremental building');
116115

117116
let lock: Lock | undefined;
118117
try {

0 commit comments

Comments
 (0)