Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Weird configuration for dev_server.manifest_host in Rails config #56

Open
govorov opened this issue Sep 17, 2016 · 1 comment
Open

Weird configuration for dev_server.manifest_host in Rails config #56

govorov opened this issue Sep 17, 2016 · 1 comment

Comments

@govorov
Copy link

govorov commented Sep 17, 2016

Hi.
Please add information about Rails configuration options available.
It tooks me some time to find a proper way to configure rails with webpack host on 0.0.0.0.
It is not clear without analyzing sources.
And I think it's reasonable to set manifest_host/port default value to something like
proc { config.webpack.dev_server.host ||= 'localhost' }
instead of localhost, because in most cases dev_server.host and manifest_server.host are equal.
Regards.

@jarongao
Copy link

jarongao commented Nov 27, 2016

I had trouble getting webpack-rails configs working correctly with Docker, but it's working now. Here's my setup in case anyone else is experiencing something similar:

  1. My default generated webpack.config.js is untouched.
  2. I created config/initializers/webpack.rb:
Rails.application.configure do
  config.webpack.dev_server.manifest_host = ENV['WEBPACK_REMOTE_HOST']
  config.webpack.dev_server.manifest_port = ENV['WEBPACK_REMOTE_PORT']
end
  1. I added a webpack container to my docker-compose.yml:
  webpack:
    build: <project location>
    container_name: webpack
    command: ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js --host '0.0.0.0'
    volumes:
      - <host location>:<container location>
    ports:
      - '3808:3808'
  1. Define the new environment variables used in step 2:
WEBPACK_REMOTE_HOST=webpack
WEBPACK_REMOTE_PORT=3808
  1. I updated my project Dockerfile to add Node 7.2 - This version comes with NPM. I previously used apt-get install nodejs npm but then found that this installs an older version that doesn't support ECMA2015. Here is my current setup referencing the latest Node image (official node image link - https:/nodejs/docker-node/blob/718102a587e7f02748402551b51407332384c1b3/7.2/Dockerfile):
FROM ruby:2.3.1
MAINTAINER Jaron Gao <email>

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev

ENV INSTALL_PATH <location>

# Create <location> folder on image
RUN mkdir $INSTALL_PATH
# Set base directory for commands
WORKDIR $INSTALL_PATH

# Add Gemfiles
COPY Gemfile Gemfile.lock ./

# Bundle gems
COPY scripts ./scripts
RUN bash scripts/bundle.sh

# Install Node
# gpg keys listed at https:/nodejs/node
RUN set -ex \
  && for key in \
    9554F04D7259F04124DE6B476D5A82AC7E37093B \
    94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
    0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
    FD3A5288F042B6850C66B31F09FE44734EB7990E \
    71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
    DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
    B9AE9905FFD7803F25714661B63B535A4C206CA9 \
    C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
  ; do \
    gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
  done

ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 7.2.0

RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
  && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
  && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
  && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
  && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
  && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
  && ln -s /usr/local/bin/node /usr/local/bin/nodejs

# Install Node modules
# COPY package.json ./
# RUN npm install

# Add project files
COPY . .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants