diff --git a/.env b/.env new file mode 100644 index 0000000..c6d4998 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +# Provides the name of the project for docker +COMPOSE_PROJECT_NAME=ror_ssr_hmr diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7fada88 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM ruby:3.1.2 + +# Install Node.js +RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - +RUN apt-get install -y nodejs + +# Install yarn version 3.2.1 +RUN node -v && npm i -g yarn && yarn set version 3.2.1 +# Set the working directory in the container +WORKDIR /app + +# Install foreman to leverage Procfile +RUN gem install foreman + +# Copy node package maps +COPY .yarnrc.yml package.json yarn.lock /app/ +COPY .yarn/ /app/.yarn/ + +COPY Gemfile* /app +# Install Gemfile +RUN bundle install + +# Install node modules +RUN yarn install + +# Copy the current directory contents into the container at /app +COPY . /app + +# Expose the rails app to outside the container +EXPOSE 3000 + +# Expose hmr server to outside the container +EXPOSE 3035 + +# Run the app when the container launches +CMD ["foreman", "start", "-f", "Procfile.dev"] diff --git a/Procfile.dev b/Procfile.dev index 4aa1033..f94f410 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,5 +1,5 @@ # Procfile for development using HMR # You can run these commands in separate shells -rails: bundle exec rails s -p 3000 +rails: bundle exec rails s -b 0.0.0.0 -p 3000 wp-client: bin/shakapacker-dev-server wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..aed12ef --- /dev/null +++ b/compose.yml @@ -0,0 +1,13 @@ +services: + rails: + build: . + image: ror_ssr_hmr:1.0.0 + volumes: + - node_modules:/app/node_modules + - .:/app + ports: + - 3000:3000 + - 3035:3035 + +volumes: + node_modules: diff --git a/config/shakapacker.yml b/config/shakapacker.yml index 43ae61b..6621841 100644 --- a/config/shakapacker.yml +++ b/config/shakapacker.yml @@ -23,7 +23,7 @@ development: # Reference: https://webpack.js.org/configuration/dev-server/ dev_server: https: false - host: localhost + host: 0.0.0.0 port: 3035 # Hot Module Replacement updates modules while the application is running without a full reload hmr: true