# syntax = docker/dockerfile:1 FROM ruby:slim as base ENV VOLTA_HOME=/usr/local FROM base as build RUN apt-get update &&\ apt-get install --yes build-essential git curl RUN curl https://get.volta.sh | bash &&\ volta install node@lts yarn@latest 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 $VOLTA_HOME/bin $VOLTA_HOME/bin COPY --from=build $VOLTA_HOME/tools $VOLTA_HOME/tools 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