Skip to content

Commit dd8898a

Browse files
authored
build: upgrade react-router to framework mode (#3722)
Details: * Upgrade some packages * Setup `react-router@v7` to use the framework mode -> see https://reactrouter.com/start/modes for more details about modes. This is what would be `remix` but is now part of react-router. * Some source files have been added to support framework mode. This mostly follows the custom node server template -> https://github.com/remix-run/react-router-templates/tree/main/node-custom-server. * Updated the Dockerfile and other build-related files * The most important change is that the UI container now runs `node` instead of `nginx`. The server is an `express` server set-up to serve the UI and the compiled `storybook`. * A corresponding PR on `renku` is open (only change is the `runAs` user ID). * Server-side routing: * Routes: `client/src/routes.ts` * All routes are rendered from `client/src/routes/catchall.tsx` as client-side routes. * This setup can be updated to handle new routes from the server-side.
1 parent 63b7797 commit dd8898a

34 files changed

Lines changed: 2367 additions & 459 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ client/.rtk/*Api.ts
111111

112112
# stoybook files
113113
client/storybook-static
114+
115+
# react-router files
116+
.react-router/

client/.storybook/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ const config: StorybookConfig = {
99
"@storybook/addon-links",
1010
"@storybook/react-vite",
1111
],
12-
1312
framework: {
1413
name: "@storybook/react-vite",
15-
options: {},
14+
options: {
15+
builder: {
16+
viteConfigPath: "storybook-vite.config.ts",
17+
},
18+
},
1619
},
1720
typescript: {
1821
reactDocgen: "react-docgen-typescript",

client/Dockerfile

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,73 @@ WORKDIR /app
88
COPY package.json package-lock.json /app/
99
RUN npm ci
1010

11-
COPY index.html tsconfig.json tsconfig.node.json vite.config.ts /app/
11+
COPY react-router.config.ts tsconfig.json tsconfig.node.json vite.config.ts /app/
1212
COPY public /app/public
13-
COPY src /app/src/
13+
COPY src /app/src
14+
COPY server /app/server
1415

1516
ENV NODE_OPTIONS="--max-old-space-size=4096"
1617

1718
RUN npm run-script build
1819

20+
COPY storybook-vite.config.ts /app/
1921
COPY .storybook /app/.storybook
2022

2123
RUN npm run storybook-build -- -o storybook-static
2224

23-
FROM nginxinc/nginx-unprivileged:1.27-alpine
25+
FROM node:22 AS dependencies
2426

25-
COPY --from=builder /app/build /usr/share/nginx/html
26-
COPY --from=builder /app/storybook-static /usr/share/nginx/html/storybook
27-
COPY nginx.vh.default.conf /etc/nginx/conf.d/default.conf
27+
RUN apt-get update && apt-get upgrade --quiet --assume-yes
28+
29+
WORKDIR /app
30+
31+
#? Use only required files.
32+
COPY package.json package-lock.json /app/
33+
RUN npm ci --omit=dev
34+
35+
FROM node:22-slim
36+
37+
RUN apt-get update && apt-get upgrade --quiet --assume-yes
38+
39+
USER node
40+
41+
WORKDIR /app
42+
43+
COPY package.json package-lock.json server.js /app/
44+
COPY --from=dependencies /app/node_modules /app/node_modules
45+
COPY --from=builder /app/build /app/build
46+
COPY --from=builder /app/storybook-static /app/storybook-static
2847
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
2948
COPY scripts/generate_sitemap.sh /app/scripts/generate_sitemap.sh
3049

3150
# Set up the config files written by docker-entrypoint
3251
USER root
33-
RUN touch /usr/share/nginx/html/config.json
34-
RUN chmod a+r /usr/share/nginx/html/config.json
35-
RUN chown nginx /usr/share/nginx/html/config.json
36-
37-
RUN touch /usr/share/nginx/html/robots.txt
38-
RUN chmod a+r /usr/share/nginx/html/robots.txt
39-
RUN chown nginx /usr/share/nginx/html/robots.txt
52+
RUN touch /app/build/client/config.json
53+
RUN chmod a+r /app/build/client/config.json
54+
RUN chown node /app/build/client/config.json
4055

41-
RUN touch /usr/share/nginx/html/sitemap.xml
42-
RUN chmod a+r /usr/share/nginx/html/sitemap.xml
43-
RUN chown nginx /usr/share/nginx/html/sitemap.xml
56+
RUN touch /app/build/client/robots.txt
57+
RUN chmod a+r /app/build/client/robots.txt
58+
RUN chown node /app/build/client/robots.txt
4459

45-
RUN touch /usr/share/nginx/html/privacy-statement.md
46-
RUN chmod a+r /usr/share/nginx/html/privacy-statement.md
47-
RUN chown nginx /usr/share/nginx/html/privacy-statement.md
60+
RUN touch /app/build/client/sitemap.xml
61+
RUN chmod a+r /app/build/client/sitemap.xml
62+
RUN chown node /app/build/client/sitemap.xml
4863

49-
RUN touch /usr/share/nginx/html/terms-of-use.md
50-
RUN chmod a+r /usr/share/nginx/html/terms-of-use.md
51-
RUN chown nginx /usr/share/nginx/html/terms-of-use.md
64+
RUN touch /app/build/client/privacy-statement.md
65+
RUN chmod a+r /app/build/client/privacy-statement.md
66+
RUN chown node /app/build/client/privacy-statement.md
5267

53-
USER nginx
68+
RUN touch /app/build/client/terms-of-use.md
69+
RUN chmod a+r /app/build/client/terms-of-use.md
70+
RUN chown node /app/build/client/terms-of-use.md
5471

72+
USER node
5573

56-
HEALTHCHECK --interval=20s --timeout=10s --retries=5 CMD test -e /var/run/nginx.pid
74+
ENV PORT=8080
5775

5876
ARG SHORT_SHA
5977
ENV RENKU_UI_SHORT_SHA=$SHORT_SHA
6078

61-
ENTRYPOINT ["/bin/sh", "/app/docker-entrypoint.sh"]
62-
CMD ["nginx", "-g", "daemon off;"]
79+
ENTRYPOINT ["/bin/bash", "/app/docker-entrypoint.sh"]
80+
CMD ["node", "/app/server.js"]

client/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
export NGINX_PATH=/usr/share/nginx/html
19+
export NGINX_PATH=/app/build/client
2020

2121
echo "Config file contains the following settings:"
2222
echo "==================================================="

client/index.html

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)