From cbafa85acb0f4b02f0bacaf4212c49a41ece7bc1 Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 14:58:56 -0300 Subject: [PATCH 1/6] [CHORE] Initial Dockerfile --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2ddb880 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ + +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 + +# 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 ["bunde", "exec", "rails", "s", "-b", "0.0.0.0", "-p", "3000"] \ No newline at end of file From 8600667a6320c17bb60beccf6a120d8ea8d9edb6 Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 15:19:45 -0300 Subject: [PATCH 2/6] [CHORE] Leverage foreman to run the project --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2ddb880..65bef04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,9 @@ 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/ @@ -31,4 +34,4 @@ EXPOSE 3000 EXPOSE 3035 # Run the app when the container launches -CMD ["bunde", "exec", "rails", "s", "-b", "0.0.0.0", "-p", "3000"] \ No newline at end of file +CMD ["foreman", "start", "-f", "Procfile.dev"] \ No newline at end of file From cc588af53e9daecf550638aa9397c1585de9a392 Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 15:50:07 -0300 Subject: [PATCH 3/6] [CHORE] Simple compose file for ease of use --- compose.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 compose.yml diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..bd843a9 --- /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: \ No newline at end of file From 311ea014392134a11f33bc3c4af2bff836301e10 Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 15:50:21 -0300 Subject: [PATCH 4/6] [CHORE] .env for adding the name of the compose file --- .env | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .env 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 From adff74378f1041c056b55a01c61be3315ba40ddb Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 15:51:38 -0300 Subject: [PATCH 5/6] [CHORE] Enable remote access, as the container is not where the browser will run --- Procfile.dev | 2 +- config/shakapacker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 From c1c236973e872bdeff5ac30fef1dfa124fbfd05a Mon Sep 17 00:00:00 2001 From: Igor Britto Date: Sat, 8 Jun 2024 16:08:03 -0300 Subject: [PATCH 6/6] [CHORE] Add line ends --- Dockerfile | 3 +-- compose.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65bef04..7fada88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ - FROM ruby:3.1.2 # Install Node.js @@ -34,4 +33,4 @@ EXPOSE 3000 EXPOSE 3035 # Run the app when the container launches -CMD ["foreman", "start", "-f", "Procfile.dev"] \ No newline at end of file +CMD ["foreman", "start", "-f", "Procfile.dev"] diff --git a/compose.yml b/compose.yml index bd843a9..aed12ef 100644 --- a/compose.yml +++ b/compose.yml @@ -10,4 +10,4 @@ services: - 3035:3035 volumes: - node_modules: \ No newline at end of file + node_modules: