feat: add resolve absolute path util (#5836)
Add a new util called `resolveAbsolutePath` to allow providing absolute path for environment variable like `STORAGE_LOCAL_PATH`. If the path in the env start with `/` we'll not prefix it with `process.cwd()`. Also we're using a static path for the old `db_initialized` file now named `db_status` and stop using the env variable for this file as this one shouldn't ne stored in the `STORAGE_LOCAL_PATH`. Fix #4794 --------- Co-authored-by: Quentin Galliano <qgalliano@gmail.com>
This commit is contained in:
@ -2,10 +2,22 @@ version: "3.9"
|
|||||||
name: twenty
|
name: twenty
|
||||||
|
|
||||||
services:
|
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:
|
server:
|
||||||
image: twentycrm/twenty:${TAG}
|
image: twentycrm/twenty:${TAG}
|
||||||
volumes:
|
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:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
environment:
|
environment:
|
||||||
@ -27,6 +39,8 @@ services:
|
|||||||
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
|
||||||
FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
|
FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
|
||||||
depends_on:
|
depends_on:
|
||||||
|
change-vol-ownership:
|
||||||
|
condition: service_completed_successfully
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@ -38,8 +52,6 @@ services:
|
|||||||
|
|
||||||
worker:
|
worker:
|
||||||
image: twentycrm/twenty:${TAG}
|
image: twentycrm/twenty:${TAG}
|
||||||
volumes:
|
|
||||||
- worker-local-data:/app/${STORAGE_LOCAL_PATH:-.local-storage}
|
|
||||||
command: ["yarn", "worker:prod"]
|
command: ["yarn", "worker:prod"]
|
||||||
environment:
|
environment:
|
||||||
PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
|
PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
|
||||||
@ -47,7 +59,7 @@ services:
|
|||||||
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
|
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
|
||||||
MESSAGE_QUEUE_TYPE: ${MESSAGE_QUEUE_TYPE}
|
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_TYPE: ${STORAGE_TYPE}
|
||||||
STORAGE_S3_REGION: ${STORAGE_S3_REGION}
|
STORAGE_S3_REGION: ${STORAGE_S3_REGION}
|
||||||
@ -60,6 +72,8 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
server:
|
||||||
|
condition: service_healthy
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
db:
|
db:
|
||||||
@ -76,6 +90,6 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
docker-data:
|
||||||
db-data:
|
db-data:
|
||||||
server-local-data:
|
server-local-data:
|
||||||
worker-local-data:
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Check if the initialization has already been done and that we enabled automatic migration
|
# 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..."
|
echo "Running database setup and migrations..."
|
||||||
|
|
||||||
# Run setup and migration scripts
|
# Run setup and migration scripts
|
||||||
@ -10,7 +10,7 @@ if [ "${ENABLE_DB_MIGRATIONS}" = "true" ] && [ ! -f /app/${STORAGE_LOCAL_PATH:-.
|
|||||||
|
|
||||||
# Mark initialization as done
|
# Mark initialization as done
|
||||||
echo "Successfuly migrated DB!"
|
echo "Successfuly migrated DB!"
|
||||||
touch /app/${STORAGE_LOCAL_PATH:-.local-storage}/db_initialized
|
touch /app/docker-data/db_status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Continue with the original Docker command
|
# Continue with the original Docker command
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
FileStorageModuleOptions,
|
FileStorageModuleOptions,
|
||||||
StorageDriverType,
|
StorageDriverType,
|
||||||
} from 'src/engine/integrations/file-storage/interfaces';
|
} from 'src/engine/integrations/file-storage/interfaces';
|
||||||
|
import { resolveAbsolutePath } from 'src/utils/resolve-absolute-path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileStorage Module factory
|
* FileStorage Module factory
|
||||||
@ -23,7 +24,7 @@ export const fileStorageModuleFactory = async (
|
|||||||
return {
|
return {
|
||||||
type: StorageDriverType.Local,
|
type: StorageDriverType.Local,
|
||||||
options: {
|
options: {
|
||||||
storagePath: process.cwd() + '/' + storagePath,
|
storagePath: resolveAbsolutePath(storagePath),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
export const resolveAbsolutePath = (path: string): string => {
|
||||||
|
return path.startsWith('/') ? path : process.cwd() + '/' + path;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user