allow alternate scripts to run in docker, fix performance issue with workers
This commit is contained in:
parent
a7a9b35da6
commit
93dc27b17a
|
@ -109,5 +109,7 @@ ENV SERVE_CLIENT /home/node/app/packages/client
|
|||
ENV SERVE_ADMIN /home/node/app/packages/admin
|
||||
|
||||
EXPOSE 3000
|
||||
# profiler port, only used if profiler is explicity running
|
||||
EXPOSE 9229
|
||||
ENTRYPOINT [ "/bin/sh" ]
|
||||
CMD [ "./docker-start.sh" ]
|
|
@ -9,9 +9,11 @@ services:
|
|||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
# - "9229:9229"
|
||||
environment:
|
||||
- REDIS_HOST=redis://redis
|
||||
- DATABASE_URL=postgres://postgres@postgres/canvas
|
||||
# - SCRIPT_TO_RUN=profiler
|
||||
env_file:
|
||||
- .env.local
|
||||
depends_on:
|
||||
|
|
|
@ -3,5 +3,8 @@
|
|||
# This script runs when the docker image starts
|
||||
# It just forces all migrations to run and then starts lol
|
||||
|
||||
# Allow running of other scripts via environment variable (eg. profiler)
|
||||
SCRIPT_TO_RUN="${SCRIPT_TO_RUN:-start}"
|
||||
|
||||
npx -w packages/server npx prisma migrate deploy
|
||||
npm -w packages/server run start
|
||||
npm -w packages/server run $SCRIPT_TO_RUN
|
|
@ -4,6 +4,7 @@
|
|||
"scripts": {
|
||||
"dev": "DOTENV_CONFIG_PATH=.env.local tsx watch -r dotenv/config src/index.ts",
|
||||
"start": "node --enable-source-maps dist/index.js",
|
||||
"profiler": "node --inspect=0.0.0.0:9229 --enable-source-maps dist/index.js",
|
||||
"build": "tsc",
|
||||
"lint": "eslint .",
|
||||
"prisma:studio": "BROWSER=none prisma studio",
|
||||
|
|
|
@ -5,7 +5,15 @@ import { getLogger } from "../lib/Logger";
|
|||
const Logger = getLogger("WORKER_ROOT");
|
||||
|
||||
export const spawnWorker = (file: string, wkOpts: WorkerOptions = {}) => {
|
||||
if (process.env.NODE_ENV === "production") file = file.replace(".ts", ".js");
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
// when compiled we no longer need ts-node as it's already raw JS
|
||||
// replace the file extension so it can load it directly
|
||||
|
||||
file = path.join(__dirname, file.replace(".ts", ".js"));
|
||||
return new Worker(file, wkOpts);
|
||||
} else {
|
||||
// when in development we just have TS files
|
||||
// this loads TS dynamically when the worker is created
|
||||
|
||||
// https://github.com/TypeStrong/ts-node/issues/676#issuecomment-531620154
|
||||
wkOpts.eval = true;
|
||||
|
@ -23,6 +31,7 @@ export const spawnWorker = (file: string, wkOpts: WorkerOptions = {}) => {
|
|||
`,
|
||||
wkOpts
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const AllWorkers = {
|
||||
|
|
Loading…
Reference in New Issue