Skip to content

Commit

Permalink
Update Node.js, reorganize node scripts, and make postinstall skippable
Browse files Browse the repository at this point in the history
The sharp library needs scripts to work, but with the  Docker image, we want to still separate the compilation from the install to have more caching.

This also resolves some unnoticed order dependencies between scripts better.
  • Loading branch information
smarr committed May 7, 2023
1 parent cb61cf2 commit ebe4a58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Add Node.js repo
RUN curl -sL https://deb.nodesource.com/setup_19.x | bash -
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -

RUN sh -c 'echo "deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/" > /etc/apt/sources.list.d/r-project.list' && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'
Expand All @@ -29,14 +29,13 @@ COPY ./src/stats/install.R /project/src/stats/
# Installing R libraries
RUN Rscript /project/src/stats/install.R


# Copy only package.json to enable caching
COPY ./package.json ./package-lock.json /project/

# Set the working dir to the project & install and compile all dependency
WORKDIR /project/

RUN npm ci --ignore-scripts .
RUN SKIP_COMPILE=true npm ci --ignore-scripts=false --foreground-scripts

ENV POSTGRES_PASSWORD=docker
ENV POSTGRES_USER=docker
Expand Down
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,25 @@
]
},
"scripts": {
"postinstall": "npm run compile",
"postinstall": "if [ -z \"${SKIP_COMPILE}\" ]; then npm run compile; fi",

"precompile": "npm run prep-folders && npm run compile-uplot",
"prep-folders": "mkdir -p tmp/interm tmp/knit resources/reports resources/exp-data",
"compile-uplot": "terser --module --ecma 2018 --compress --mangle -o ./resources/uPlot.esm.min.js -- node_modules/uplot/dist/uPlot.esm.js",
"compile": "tsc",
"postcompile": " npm run prep-static",
"prep-static": "cp dist/src/views/*.js ./resources/",

"start": "node --enable-source-maps --experimental-json-modules ./dist/src/index.js",
"nodemon": "DEV=true nodemon --enable-source-maps --experimental-json-modules ./dist/src/index.js --watch ./dist/src --watch ./dist/package.json --watch ./src/views/ --ext js,json,html",
"precompile": "terser --module --ecma 2018 --compress --mangle -o ./resources/uPlot.esm.min.js -- node_modules/uplot/dist/uPlot.esm.js",
"compile": "tsc && npm run prep-reports && npm run prep-static",
"prep-static": "cp dist/src/views/*.js ./resources/",
"prep-reports": "mkdir -p tmp/interm tmp/knit resources/reports resources/exp-data",

"format": "prettier --config .prettierrc '{src,tests}/**/*.ts' --write",
"verify": "npm run lint",
"lint": "eslint . --ext .ts,.tsx",

"update": "git pull && npm install . && pm2 restart 0",
"watch": "tsc -w",

"pretest": "(cd tests; bzip2 -d -f -k large-payload.json.bz2)",
"test": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js"
}
Expand Down

0 comments on commit ebe4a58

Please sign in to comment.