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:
Shrikant Sharat Kandula 2023-10-03 07:00:40 +05:30 committed by GitHub
parent 46dcf3a8f0
commit 164d2e6b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 22 deletions

View File

@ -78,7 +78,7 @@ COPY ${PLUGIN_JARS} backend/plugins/
COPY ./app/client/build editor/
# 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 - \
&& chmod 0644 /etc/cron.d/* \

View File

@ -3,18 +3,18 @@
set -o errexit
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.
# 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
root="$(git rev-parse --show-toplevel)"
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

View File

@ -1,5 +1,4 @@
import http from "http";
import path from "path";
import express from "express";
import { Server } from "socket.io";
import type { LogLevelDesc } from "loglevel";
@ -35,16 +34,10 @@ const io = new Server(server, {
path: RTS_BASE_PATH,
});
// Initializing Sockets
initializeSockets(io);
// parse incoming json requests
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}`, health_check_routes);

View File

@ -1,5 +1,5 @@
[program:rts]
directory=/opt/appsmith/rts
directory=/opt/appsmith/rts/bundle
command=/opt/appsmith/run-with-env.sh node server.js
priority=15
autostart=true