Commit 93dc27b1 authored by Grant's avatar Grant
Browse files

allow alternate scripts to run in docker, fix performance issue with workers

parent a7a9b35d
Loading
Loading
Loading
Loading
+2 −0
Changes for Dockerfile: 2 added lines, 0 removed lines.
Original line number Original line Diff line number Diff line
@@ -109,5 +109,7 @@ ENV SERVE_CLIENT /home/node/app/packages/client
ENV SERVE_ADMIN /home/node/app/packages/admin
ENV SERVE_ADMIN /home/node/app/packages/admin


EXPOSE 3000
EXPOSE 3000
# profiler port, only used if profiler is explicity running
EXPOSE 9229
ENTRYPOINT [ "/bin/sh" ]
ENTRYPOINT [ "/bin/sh" ]
CMD [ "./docker-start.sh" ]
CMD [ "./docker-start.sh" ]
 No newline at end of file
+2 −0
Changes for docker-compose.yml: 2 added lines, 0 removed lines.
Original line number Original line Diff line number Diff line
@@ -9,9 +9,11 @@ services:
    build: .
    build: .
    ports:
    ports:
      - "3000:3000"
      - "3000:3000"
      # - "9229:9229"
    environment:
    environment:
      - REDIS_HOST=redis://redis
      - REDIS_HOST=redis://redis
      - DATABASE_URL=postgres://postgres@postgres/canvas
      - DATABASE_URL=postgres://postgres@postgres/canvas
      # - SCRIPT_TO_RUN=profiler
    env_file:
    env_file:
      - .env.local
      - .env.local
    depends_on:
    depends_on:
+4 −1
Changes for docker-start.sh: 4 added lines, 1 removed line.
Original line number Original line Diff line number Diff line
@@ -3,5 +3,8 @@
# This script runs when the docker image starts
# This script runs when the docker image starts
# It just forces all migrations to run and then starts lol
# 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
npx -w packages/server npx prisma migrate deploy
npm -w packages/server run start
npm -w packages/server run $SCRIPT_TO_RUN
 No newline at end of file
 No newline at end of file
+1 −0
Changes for packages/server/package.json: 1 added line, 0 removed lines.
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@
  "scripts": {
  "scripts": {
    "dev": "DOTENV_CONFIG_PATH=.env.local tsx watch -r dotenv/config src/index.ts",
    "dev": "DOTENV_CONFIG_PATH=.env.local tsx watch -r dotenv/config src/index.ts",
    "start": "node --enable-source-maps dist/index.js",
    "start": "node --enable-source-maps dist/index.js",
    "profiler": "node --inspect=0.0.0.0:9229 --enable-source-maps dist/index.js",
    "build": "tsc",
    "build": "tsc",
    "lint": "eslint .",
    "lint": "eslint .",
    "prisma:studio": "BROWSER=none prisma studio",
    "prisma:studio": "BROWSER=none prisma studio",
+10 −1
Changes for packages/server/src/workers/worker.ts: 10 added lines, 1 removed line.
Original line number Original line Diff line number Diff line
@@ -5,7 +5,15 @@ import { getLogger } from "../lib/Logger";
const Logger = getLogger("WORKER_ROOT");
const Logger = getLogger("WORKER_ROOT");


export const spawnWorker = (file: string, wkOpts: WorkerOptions = {}) => {
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
    // https://github.com/TypeStrong/ts-node/issues/676#issuecomment-531620154
    wkOpts.eval = true;
    wkOpts.eval = true;
@@ -23,6 +31,7 @@ export const spawnWorker = (file: string, wkOpts: WorkerOptions = {}) => {
      `,
      `,
      wkOpts
      wkOpts
    );
    );
  }
};
};


const AllWorkers = {
const AllWorkers = {