# syntax = docker/dockerfile:1 FROM node:slim AS node FROM ruby:slim as base COPY --from=node /usr/lib /usr/lib COPY --from=node /usr/local/share /usr/local/share COPY --from=node /usr/local/lib /usr/local/lib COPY --from=node /usr/local/include /usr/local/include COPY --from=node /usr/local/bin /usr/local/bin COPY --from=node /opt /opt FROM base as build RUN apt-get update &&\ apt-get install --yes 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 /usr/local/bundle /usr/local/bundle 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