From 3168958f8aca892b447ea490fa2427def142788d Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:25:36 +0100 Subject: [PATCH] Allow `APP_VERSION` to be empty string + dockerFile fix (#10900) # Introduction No choice but to allow APP_VERSION to be an empty string as it's though to dynamically define dockerfile env vars --- packages/twenty-docker/twenty/Dockerfile | 1 + packages/twenty-docker/twenty/entrypoint.sh | 5 ----- .../decorators/is-optional-or-empty-string.decorator.ts | 7 +++++++ .../core-modules/environment/environment-variables.ts | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 packages/twenty-server/src/engine/core-modules/environment/decorators/is-optional-or-empty-string.decorator.ts diff --git a/packages/twenty-docker/twenty/Dockerfile b/packages/twenty-docker/twenty/Dockerfile index 93c1d6d33..ade105358 100644 --- a/packages/twenty-docker/twenty/Dockerfile +++ b/packages/twenty-docker/twenty/Dockerfile @@ -67,6 +67,7 @@ ARG SENTRY_RELEASE ENV SENTRY_RELEASE $SENTRY_RELEASE ARG APP_VERSION +ENV APP_VERSION $APP_VERSION # Copy built applications from previous stages COPY --chown=1000 --from=twenty-server-build /app /app diff --git a/packages/twenty-docker/twenty/entrypoint.sh b/packages/twenty-docker/twenty/entrypoint.sh index 2520a29c1..2b6985a30 100755 --- a/packages/twenty-docker/twenty/entrypoint.sh +++ b/packages/twenty-docker/twenty/entrypoint.sh @@ -1,11 +1,6 @@ #!/bin/sh set -e -# Set APP_VERSION only if it has a value -if [ ! -z "${APP_VERSION}" ]; then - export APP_VERSION="${APP_VERSION}" -fi - # Check if the initialization has already been done and that we enabled automatic migration if [ "${DISABLE_DB_MIGRATIONS}" != "true" ] && [ ! -f /app/docker-data/db_status ]; then echo "Running database setup and migrations..." diff --git a/packages/twenty-server/src/engine/core-modules/environment/decorators/is-optional-or-empty-string.decorator.ts b/packages/twenty-server/src/engine/core-modules/environment/decorators/is-optional-or-empty-string.decorator.ts new file mode 100644 index 000000000..0030cac32 --- /dev/null +++ b/packages/twenty-server/src/engine/core-modules/environment/decorators/is-optional-or-empty-string.decorator.ts @@ -0,0 +1,7 @@ +import { ValidateIf, ValidationOptions, isDefined } from 'class-validator'; + +export function IsOptionalOrEmptyString(validationOptions?: ValidationOptions) { + return ValidateIf((_obj, value) => { + return isDefined(value) && value !== ''; + }, validationOptions); +} diff --git a/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts b/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts index 4dd6cc255..d07bb35fd 100644 --- a/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts +++ b/packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts @@ -28,6 +28,7 @@ import { CastToPositiveNumber } from 'src/engine/core-modules/environment/decora import { EnvironmentVariablesMetadata } from 'src/engine/core-modules/environment/decorators/environment-variables-metadata.decorator'; import { IsAWSRegion } from 'src/engine/core-modules/environment/decorators/is-aws-region.decorator'; import { IsDuration } from 'src/engine/core-modules/environment/decorators/is-duration.decorator'; +import { IsOptionalOrEmptyString } from 'src/engine/core-modules/environment/decorators/is-optional-or-empty-string.decorator'; import { IsStrictlyLowerThan } from 'src/engine/core-modules/environment/decorators/is-strictly-lower-than.decorator'; import { EnvironmentVariablesGroup } from 'src/engine/core-modules/environment/enums/environment-variables-group.enum'; import { ExceptionHandlerDriver } from 'src/engine/core-modules/exception-handler/interfaces'; @@ -984,7 +985,7 @@ export class EnvironmentVariables { group: EnvironmentVariablesGroup.ServerConfig, description: 'Twenty server version', }) - @IsOptional() + @IsOptionalOrEmptyString() @IsSemVer() APP_VERSION?: string; }