ci: Use esbuild to build RTS (#27310)
This fixes RTS build to use `esbuild`. 1. This means the whole `node_modules` won't need to be copied over to the Docker image. There's unused insignifant _test_ files in there, that don't add any value, but are causing irrelevant CVEs to be reported on our Docker image. See example at https://github.com/appsmithorg/appsmith-ee/pull/2349. 2. Much faster. Not that RTS build is our slow point, but still. Perhaps we can move client to `esbuild` too. 🙂 ## Why are we doing this? The current method of loading RTS into the Docker image means that _all_ contents of _all_ dependencies are copied over. The whole `node_modules`. But several of these packages include _test_ files too, that aren't needed at runtime at all. One of such test files is creating a false alert for a CVE on our Docker image. Has absolutely no relevance and impact, but it's there. To fix that, I [had to `rm -rf /opt/appsmith/rts/node_modules/*/test` in the Docker image](https://github.com/appsmithorg/appsmith-ee/pull/2349/files). This felt very hacky, and very dirty. It felt like we're introducing more debt and more duct tape around the current build process. So, `esbuild`. ## Where is `esbuild` coming from? We're using `esbuild` v0.18.20 only, while the latest is v0.19.3. We need to update `design-system`'s storybook dependency, I think, to get a more recent version of `esbuild`. I'm yet to figure this out and can use some help. 🙂
This commit is contained in:
parent
46dcf3a8f0
commit
164d2e6b65
|
|
@ -78,7 +78,7 @@ COPY ${PLUGIN_JARS} backend/plugins/
|
||||||
COPY ./app/client/build editor/
|
COPY ./app/client/build editor/
|
||||||
|
|
||||||
# Add RTS - Application Layer
|
# Add RTS - Application Layer
|
||||||
COPY ./app/client/packages/rts/package.json ./app/client/packages/rts/dist rts/
|
COPY ./app/client/packages/rts/dist rts/
|
||||||
|
|
||||||
RUN cd ./utils && npm install --only=prod && npm install --only=prod -g . && cd - \
|
RUN cd ./utils && npm install --only=prod && npm install --only=prod -g . && cd - \
|
||||||
&& chmod 0644 /etc/cron.d/* \
|
&& chmod 0644 /etc/cron.d/* \
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@
|
||||||
set -o errexit
|
set -o errexit
|
||||||
|
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
rm -rf dist/
|
|
||||||
# This is required for the first time build as node_modules is not present in the image
|
|
||||||
yarn install --immutable
|
|
||||||
yarn tsc && yarn tsc-alias
|
|
||||||
# Install only production dependencies
|
|
||||||
YARN_NM_HOISTING_LIMITS=workspaces yarn workspaces focus --production appsmith-rts
|
|
||||||
|
|
||||||
# Copying node_modules directory into dist as rts server requires production dependencies to run server build properly.
|
root="$(git rev-parse --show-toplevel)"
|
||||||
# This was previously being done in dockerfile which was copying the symlinks to image rather than the whole directory of shared modules (e.g. AST)
|
|
||||||
# Also, we copy node_modules with -L flag in order to follow the symlinks for @shared folder and copy the contents instead of just the symlink
|
|
||||||
cp -RL node_modules ./dist
|
|
||||||
# Delete production dependencies
|
|
||||||
rm -rf node_modules
|
|
||||||
# Restore all dependencies
|
|
||||||
yarn install --immutable
|
yarn install --immutable
|
||||||
|
yarn run tsc --noEmit
|
||||||
|
|
||||||
|
rm -rf dist
|
||||||
|
exec "$root/app/client/node_modules/.bin/esbuild" src/server.ts \
|
||||||
|
--bundle \
|
||||||
|
--minify \
|
||||||
|
--sourcemap \
|
||||||
|
--platform=node \
|
||||||
|
--target="$(node --version | sed s/v/node/)" \
|
||||||
|
--outdir=dist/bundle \
|
||||||
|
--external:dtrace-provider
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import http from "http";
|
import http from "http";
|
||||||
import path from "path";
|
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
import type { LogLevelDesc } from "loglevel";
|
import type { LogLevelDesc } from "loglevel";
|
||||||
|
|
@ -35,16 +34,10 @@ const io = new Server(server, {
|
||||||
path: RTS_BASE_PATH,
|
path: RTS_BASE_PATH,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initializing Sockets
|
|
||||||
initializeSockets(io);
|
initializeSockets(io);
|
||||||
|
|
||||||
// parse incoming json requests
|
// parse incoming json requests
|
||||||
app.use(express.json({ limit: "5mb" }));
|
app.use(express.json({ limit: "5mb" }));
|
||||||
// Initializing Routes
|
|
||||||
app.use(express.static(path.join(__dirname, "static")));
|
|
||||||
app.get("/", (_, res) => {
|
|
||||||
res.redirect("/index.html");
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(`${RTS_BASE_API_PATH}/ast`, ast_routes);
|
app.use(`${RTS_BASE_API_PATH}/ast`, ast_routes);
|
||||||
app.use(`${RTS_BASE_API_PATH}`, health_check_routes);
|
app.use(`${RTS_BASE_API_PATH}`, health_check_routes);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[program:rts]
|
[program:rts]
|
||||||
directory=/opt/appsmith/rts
|
directory=/opt/appsmith/rts/bundle
|
||||||
command=/opt/appsmith/run-with-env.sh node server.js
|
command=/opt/appsmith/run-with-env.sh node server.js
|
||||||
priority=15
|
priority=15
|
||||||
autostart=true
|
autostart=true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user