Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable containerized demo #64

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Provides the name of the project for docker
COMPOSE_PROJECT_NAME=ror_ssr_hmr
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

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"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be configured differently, but it is likely a good idea to try to run both bare metal and containers through the same commands to avoid the need to update in multiple places when change comes.

2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable accepting requests from outside the container, like from the browser.

wp-client: bin/shakapacker-dev-server
wp-server: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
13 changes: 13 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ development:
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.0.0.0 is required, as the container is not in the same space as the host.

For truly remote, such as CodeSpaces, one might also need to change the allowed list below

host: 0.0.0.0
port: 3035
# Hot Module Replacement updates modules while the application is running without a full reload
hmr: true
Expand Down
Loading