Skip to content

The open alternative to Salesforce, designed for AI.

feat: add resolve absolute path util (#5836)

Jérémy M04edf2bf7b22
diff --git a/packages/twenty-docker/docker-compose.yml b/packages/twenty-docker/docker-compose.yml
index 1ca289c9af5..553d8ca6c9f 100644
--- a/packages/twenty-docker/docker-compose.yml
+++ b/packages/twenty-docker/docker-compose.yml
@@ -2,10 +2,22 @@ version: "3.9"
name: twenty
services:
+ change-vol-ownership:
+ image: ubuntu
+ user: root
+ volumes:
+ - server-local-data:/tmp/server-local-data
+ - docker-data:/tmp/docker-data
+ command: >
+ bash -c "
+ chown -R 1000:1000 /tmp/server-local-data
+ && chown -R 1000:1000 /tmp/docker-data"
+
server:
image: twentycrm/twenty:${TAG}
volumes:
- - server-local-data:/app/${STORAGE_LOCAL_PATH:-.local-storage}
+ - server-local-data:/app/packages/twenty-server/${STORAGE_LOCAL_PATH:-.local-storage}
+ - docker-data:/app/docker-data
ports:
- "3000:3000"
environment:
@@ -27,6 +39,8 @@ services:
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
depends_on:
+ change-vol-ownership:
+ condition: service_completed_successfully
db:
condition: service_healthy
healthcheck:
@@ -38,8 +52,6 @@ services:
worker:
image: twentycrm/twenty:${TAG}
- volumes:
- - worker-local-data:/app/${STORAGE_LOCAL_PATH:-.local-storage}
command: ["yarn", "worker:prod"]
environment:
PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
@@ -47,7 +59,7 @@ services:
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}
- ENABLE_DB_MIGRATIONS: "true"
+ ENABLE_DB_MIGRATIONS: "false" # it already runs on the server
STORAGE_TYPE: ${STORAGE_TYPE}
STORAGE_S3_REGION: ${STORAGE_S3_REGION}
@@ -60,6 +72,8 @@ services:
depends_on:
db:
condition: service_healthy
+ server:
+ condition: service_healthy
restart: always
db:
@@ -76,6 +90,6 @@ services:
restart: always
volumes:
+ docker-data:
db-data:
server-local-data:
- worker-local-data:
diff --git a/packages/twenty-docker/twenty/entrypoint.sh b/packages/twenty-docker/twenty/entrypoint.sh
index b3bb5cad57b..da6bffd25ab 100755
--- a/packages/twenty-docker/twenty/entrypoint.sh
+++ b/packages/twenty-docker/twenty/entrypoint.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# Check if the initialization has already been done and that we enabled automatic migration
-if [ "${ENABLE_DB_MIGRATIONS}" = "true" ] && [ ! -f /app/${STORAGE_LOCAL_PATH:-.local-storage}/db_initialized ]; then
+if [ "${ENABLE_DB_MIGRATIONS}" = "true" ] && [ ! -f /app/docker-data/db_status ]; then
echo "Running database setup and migrations..."
# Run setup and migration scripts
@@ -10,7 +10,7 @@ if [ "${ENABLE_DB_MIGRATIONS}" = "true" ] && [ ! -f /app/${STORAGE_LOCAL_PATH:-.
# Mark initialization as done
echo "Successfuly migrated DB!"
- touch /app/${STORAGE_LOCAL_PATH:-.local-storage}/db_initialized
+ touch /app/docker-data/db_status
fi
# Continue with the original Docker command
diff --git a/packages/twenty-server/src/engine/integrations/file-storage/file-storage.module-factory.ts b/packages/twenty-server/src/engine/integrations/file-storage/file-storage.module-factory.ts
index fc625ce89ee..f846dc96df8 100644
--- a/packages/twenty-server/src/engine/integrations/file-storage/file-storage.module-factory.ts
+++ b/packages/twenty-server/src/engine/integrations/file-storage/file-storage.module-factory.ts
@@ -5,6 +5,7 @@ import {
FileStorageModuleOptions,
StorageDriverType,
} from 'src/engine/integrations/file-storage/interfaces';
+import { resolveAbsolutePath } from 'src/utils/resolve-absolute-path';
/**
* FileStorage Module factory
@@ -23,7 +24,7 @@ export const fileStorageModuleFactory = async (
return {
type: StorageDriverType.Local,
options: {
- storagePath: process.cwd() + '/' + storagePath,
+ storagePath: resolveAbsolutePath(storagePath),
},
};
}
diff --git a/packages/twenty-server/src/utils/resolve-absolute-path.ts b/packages/twenty-server/src/utils/resolve-absolute-path.ts
new file mode 100644
index 00000000000..942d4bef4d8
--- /dev/null
+++ b/packages/twenty-server/src/utils/resolve-absolute-path.ts
@@ -0,0 +1,3 @@
+export const resolveAbsolutePath = (path: string): string => {
+ return path.startsWith('/') ? path : process.cwd() + '/' + path;
+};