Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast follows on 0.34 #9034

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions packages/twenty-docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ PG_DATABASE_HOST=db:5432
REDIS_URL=redis://redis:6379

SERVER_URL=http://localhost:3000
FRONT_DOMAIN=localhost
FRONT_PORT=3000
FRONT_PROTOCOL=http

# Use openssl rand -base64 32 for each secret
# APP_SECRET=replace_me_with_a_random_string
Expand Down
9 changes: 6 additions & 3 deletions packages/twenty-docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ services:
PORT: 3000
PG_DATABASE_URL: postgres://${PGUSER_SUPERUSER:-postgres}:${PGPASSWORD_SUPERUSER:-postgres}@${PG_DATABASE_HOST:-db:5432}/default
SERVER_URL: ${SERVER_URL}
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
FRONT_DOMAIN: ${FRONT_DOMAIN}
Weiko marked this conversation as resolved.
Show resolved Hide resolved
FRONT_PORT: ${FRONT_PORT}
FRONT_PROTOCOL: ${FRONT_PROTOCOL}
Weiko marked this conversation as resolved.
Show resolved Hide resolved
REDIS_URL: ${REDIS_URL:-redis://redis:6379}

ENABLE_DB_MIGRATIONS: "true"
Expand Down Expand Up @@ -54,9 +56,10 @@ services:
environment:
PG_DATABASE_URL: postgres://${PGUSER_SUPERUSER:-postgres}:${PGPASSWORD_SUPERUSER:-postgres}@${PG_DATABASE_HOST:-db:5432}/default
SERVER_URL: ${SERVER_URL}
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
FRONT_DOMAIN: ${FRONT_DOMAIN}
Weiko marked this conversation as resolved.
Show resolved Hide resolved
FRONT_PORT: ${FRONT_PORT}
FRONT_PROTOCOL: ${FRONT_PROTOCOL}
Weiko marked this conversation as resolved.
Show resolved Hide resolved
REDIS_URL: ${REDIS_URL:-redis://redis:6379}

ENABLE_DB_MIGRATIONS: "false" # it already runs on the server

STORAGE_TYPE: ${STORAGE_TYPE}
Expand Down
8 changes: 6 additions & 2 deletions packages/twenty-docker/k8s/manifests/deployment-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ spec:
value: 3000
- name: SERVER_URL
value: "https://crm.example.com:443"
Weiko marked this conversation as resolved.
Show resolved Hide resolved
- name: FRONT_BASE_URL
value: "https://crm.example.com:443"
- name: FRONT_DOMAIN
Weiko marked this conversation as resolved.
Show resolved Hide resolved
value: "crm.example.com"
- name: FRONT_PORT
value: "443"
Weiko marked this conversation as resolved.
Show resolved Hide resolved
- name: FRONT_PROTOCOL
value: "https"
- name: "PG_DATABASE_URL"
value: "postgres://postgres:[email protected]/default"
- name: "REDIS_URL"
Expand Down
8 changes: 6 additions & 2 deletions packages/twenty-docker/k8s/manifests/deployment-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ spec:
env:
- name: SERVER_URL
value: "https://crm.example.com:443"
- name: FRONT_BASE_URL
value: "https://crm.example.com:443"
- name: FRONT_DOMAIN
value: "crm.example.com"
- name: FRONT_PORT
value: "443"
- name: FRONT_PROTOCOL
value: "https"
- name: PG_DATABASE_URL
value: "postgres://postgres:[email protected]/default"
Weiko marked this conversation as resolved.
Show resolved Hide resolved
- name: ENABLE_DB_MIGRATIONS
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-docker/k8s/terraform/deployment-server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ resource "kubernetes_deployment" "twentycrm_server" {
}

env {
name = "FRONT_BASE_URL"
name = "FRONT_DOMAIN"
value = var.twentycrm_app_hostname
Weiko marked this conversation as resolved.
Show resolved Hide resolved
}
Weiko marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-docker/k8s/terraform/deployment-worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ resource "kubernetes_deployment" "twentycrm_worker" {
}

env {
name = "FRONT_BASE_URL"
name = "FRONT_DOMAIN"
value = var.twentycrm_app_hostname
}

Expand Down
5 changes: 5 additions & 0 deletions packages/twenty-docker/k8s/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ variable "twentycrm_app_hostname" {
description = "The protocol, DNS fully qualified hostname, and port used to access TwentyCRM in your environment. Ex: https://crm.example.com:443"
}

variable "front_domain" {
Weiko marked this conversation as resolved.
Show resolved Hide resolved
type = string
description = "The protocol, DNS fully qualified hostname, and port used to access TwentyCRM in your environment. Ex: https://crm.example.com:443"
}
Weiko marked this conversation as resolved.
Show resolved Hide resolved

######################
# Optional Variables #
######################
Expand Down
6 changes: 4 additions & 2 deletions packages/twenty-server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
PG_DATABASE_URL=postgres://postgres:postgres@localhost:5432/default
REDIS_URL=redis://localhost:6379

FRONT_BASE_URL=http://localhost:3001

APP_SECRET=replace_me_with_a_random_string
SIGN_IN_PREFILLED=true

ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access

FRONT_PROTOCOL=http
FRONT_DOMAIN=localhost
FRONT_PORT=3001

# ———————— Optional ————————
# PORT=3000
# DEBUG_MODE=true
Expand Down
1 change: 0 additions & 1 deletion packages/twenty-server/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ REDIS_URL=redis://localhost:6379

DEBUG_MODE=true
DEBUG_PORT=9000
FRONT_BASE_URL=http://localhost:3001
APP_SECRET=replace_me_with_a_random_string
Weiko marked this conversation as resolved.
Show resolved Hide resolved
SIGN_IN_PREFILLED=true
EXCEPTION_HANDLER_DRIVER=console
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Module } from '@nestjs/common';

import { DomainManagerModule } from 'src/engine/core-modules/domain-manager/domain-manager.module';

import { ClientConfigResolver } from './client-config.resolver';

@Module({
imports: [DomainManagerModule],
providers: [ClientConfigResolver],
})
export class ClientConfigModule {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Query, Resolver } from '@nestjs/graphql';

import { DomainManagerService } from 'src/engine/core-modules/domain-manager/service/domain-manager.service';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';

import { ClientConfig } from './client-config.entity';

@Resolver()
export class ClientConfigResolver {
constructor(private environmentService: EnvironmentService) {}
constructor(
private environmentService: EnvironmentService,
private domainManagerService: DomainManagerService,
) {}

@Query(() => ClientConfig)
async clientConfig(): Promise<ClientConfig> {
Expand All @@ -24,7 +28,7 @@ export class ClientConfigResolver {
'IS_MULTIWORKSPACE_ENABLED',
),
defaultSubdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
frontDomain: this.environmentService.get('FRONT_DOMAIN'),
frontDomain: this.domainManagerService.getFrontUrl().hostname,
debugMode: this.environmentService.get('DEBUG_MODE'),
support: {
supportDriver: this.environmentService.get('SUPPORT_DRIVER'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Module } from '@nestjs/common';

import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm';
import { TypeOrmModule } from '@nestjs/typeorm';

import { DomainManagerService } from 'src/engine/core-modules/domain-manager/service/domain-manager.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';

@Module({
imports: [NestjsQueryTypeOrmModule.forFeature([Workspace], 'core')],
imports: [TypeOrmModule.forFeature([Workspace], 'core')],
providers: [DomainManagerService],
exports: [DomainManagerService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,26 @@ export class DomainManagerService {
private readonly environmentService: EnvironmentService,
) {}

getBaseUrl() {
const baseUrl = new URL(
`${this.environmentService.get('FRONT_PROTOCOL')}://${this.environmentService.get('FRONT_DOMAIN')}`,
);
getFrontUrl() {
let baseUrl: URL;

if (
!this.environmentService.get('FRONT_PROTOCOL') ||
!this.environmentService.get('FRONT_DOMAIN') ||
!this.environmentService.get('FRONT_PORT')
Weiko marked this conversation as resolved.
Show resolved Hide resolved
) {
baseUrl = new URL(this.environmentService.get('SERVER_URL'));
} else {
baseUrl = new URL(
`${this.environmentService.get('FRONT_PROTOCOL')}://${this.environmentService.get('FRONT_DOMAIN')}:${this.environmentService.get('FRONT_PORT')}`,
Weiko marked this conversation as resolved.
Show resolved Hide resolved
);
}

return baseUrl;
}

getBaseUrl(): URL {
const baseUrl = this.getFrontUrl();

if (
this.environmentService.get('IS_MULTIWORKSPACE_ENABLED') &&
Expand All @@ -33,10 +49,6 @@ export class DomainManagerService {
baseUrl.hostname = `${this.environmentService.get('DEFAULT_SUBDOMAIN')}.${baseUrl.hostname}`;
}

if (this.environmentService.get('FRONT_PORT')) {
baseUrl.port = this.environmentService.get('FRONT_PORT').toString();
}

return baseUrl;
}

Expand Down Expand Up @@ -87,10 +99,9 @@ export class DomainManagerService {
getWorkspaceSubdomainByOrigin = (origin: string) => {
const { hostname: originHostname } = new URL(origin);

const subdomain = originHostname.replace(
`.${this.environmentService.get('FRONT_DOMAIN')}`,
'',
);
const frontDomain = this.getFrontUrl().hostname;

const subdomain = originHostname.replace(`.${frontDomain}`, '');

if (this.isDefaultSubdomain(subdomain)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ export class EnvironmentVariables {
// Frontend URL
@IsString()
@IsOptional()
FRONT_DOMAIN = 'localhost';
FRONT_DOMAIN?: string;

@IsString()
@ValidateIf((env) => env.IS_MULTIWORKSPACE_ENABLED)
DEFAULT_SUBDOMAIN = 'app';

@IsString()
@IsOptional()
FRONT_PROTOCOL: 'http' | 'https' = 'http';
FRONT_PROTOCOL?: 'http' | 'https' = 'http';

@CastToPositiveNumber()
@IsNumber()
@IsOptional()
FRONT_PORT = 3001;
FRONT_PORT?: number;

@IsUrl({ require_tld: false, require_protocol: true })
@IsOptional()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ yarn command:prod upgrade-0.34
The `yarn database:migrate:prod` command will apply the migrations to the database structure (core and metadata schemas)
The `yarn command:prod upgrade-0.34` takes care of the data migration of all workspaces.

**Environment Variables**

We have updated the way we handle the frontend URL. If FRONT_DOMAIN or FRONT_PORT are not set, the frontend URL will be set to the server URL.
Weiko marked this conversation as resolved.
Show resolved Hide resolved

- Removed: `FRONT_BASE_URL`
- Added: `FRONT_DOMAIN`, `FRONT_PROTOCOL`, `FRONT_PORT`

### v0.32.0 to v0.33.0

Expand Down
Loading