# syntax = docker/dockerfile:1 FROM node:slim AS base RUN apt-get update &&\ apt-get install --yes ruby FROM base as build RUN apt-get install --yes ruby-dev build-essential git RUN gem install rails RUN rails new demo --skip-active-record --javascript esbuild WORKDIR demo RUN yarn add react react-dom FROM base WORKDIR demo COPY --from=build /demo /demo COPY --from=build /var/lib/gems /var/lib/gems RUN bin/rails generate controller Time index RUN cat <<-"EOF" >> app/javascript/application.js import "./components/counter" EOF RUN mkdir app/javascript/components COPY <<-"EOF" app/javascript/components/counter.jsx import React, { useState, useEffect, useRef } from 'react'; import { createRoot } from 'react-dom/client'; const Counter = ({ arg }) => { const [count, setCount] = useState(0); const countRef = useRef(count); countRef.current = count; useEffect(() => { const interval = setInterval(() => { setCount(countRef.current + 1); }, 1000); return () => clearInterval(interval); }, []); return