Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
827 views
in Technique[技术] by (71.8m points)

ruby-on-rails - 在docker-compose up --build之后,Webpacker manifest.json恢复为旧资产引用(Webpacker manifest.json reverts to old asset references after docker-compose up --build)

I've been noticing a strange problem in my dockerised development environment, where the javascript assets result in a 404 error as the webpacker manifest.json is pointing to a pack that does not exist.

(我一直在dockerized开发环境中注意到一个奇怪的问题,因为webpacker manifest.json指向一个不存在的包,因此javascript资产导致404错误。)

I've documented the problem which arises after a rebuild of the Docker container.

(我已经记录了重建Docker容器后出现的问题。)

In all cases below I am referring to the hashed version of admin.js

(在下面的所有情况下,我指的是admin.js的哈希版本)

Initial state with javascript assets loading as expected:

(符合预期的javascript资产载入状态:)

public/packs/manifest.json

"admin.js": "/packs/admin-xxxxxxc629.js", 

the file ending c629.js is present in public/packs

(在public/packs存在以c629.js结尾的文件)

If I now rebuild Docker containers with docker-compose up --build

(如果我现在使用docker-compose up --build重建Docker容器)
I get the following output in the logs:

(我在日志中得到以下输出:)

webpacker docker日志

With the hash now ending e105 and the manifest.json updated accordingly

(随着哈希现在结束, e105并相应地更新了manifest.json)

public/packs/manifest.json

"admin.js": "/packs/admin-xxxxxxe105.js", 

the file ending e105.js is NOT present in public/packs and so when I refresh the browser I get a 404 error for the admin-xxxxxxe105.js file.

(public/packs不存在以e105.js结尾的文件,因此当我刷新浏览器时,admin-xxxxxxe105.js文件出现404错误。)


This section may be a red herring or may be a clue:

(本节可能是红色鲱鱼,也可能是线索:)

I feel that my normal webpacker flow is a bit odd as changes to the original admin.js file result in webpacker compilation that updates the manifest.json but does not create the corresponding file in public/packs

(我觉得我的正常webpacker流程有点奇怪,因为对原始admin.js文件的更改导致webpacker编译会更新manifest.json,但不会在public / packs中创建相应的文件)

This doesn't cause a problem as when I refresh the browser it triggers another compile that then refreshes manifest.json with a new hashed version and also creates the file in public/packs

(这不会造成问题,因为当我刷新浏览器时,它会触发另一个编译,然后使用新的哈希版本刷新manifest.json并在public / packs中创建文件)

I'm only left with the stranded e105.js after a docker rebuild.

(码头工人重建后,我只剩下滞留的e105.js.)


Here's my docker-compose.yml file

(这是我docker-compose.yml文件)

version: '3'
services:
  webpacker:
    build: .
    environment: 
      - WEBPACKER_DEV_SERVER_PUBLIC=localhost:3035
      - WEBPACKER_DEV_SERVER_HOST=localhost
    command: ./bin/webpack-dev-server --inline true
    volumes:
      - .:/myapp
    ports:
      - '3035:3035'
  db:
    image: postgres
    ports: 
      - "5433:5432"
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
  web:
    build: .
    environment: 
      - RAILS_ENV=development
      - NODE_ENV=development
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
      - redis
      - webpacker
      #- elasticsearch
  redis:
    image: redis:alpine

and here is my Dockerfile:

(这是我的Dockerfile:)

FROM ruby:2.3.7
ENV BUNDLER_VERSION=1.17.3
RUN gem install bundler -v "$BUNDLER_VERSION" --no-document
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -  
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -   
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list   
RUN apt-get update -qq && apt-get install -y nodejs yarn build-essential libpq-dev postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
ENV RAILS_ENV docker    
ENV WEBPACKER_DEV_SERVER_PUBLIC localhost:3035  
ENV WEBPACKER_DEV_SERVER_HOST localhost 
RUN git config --global url."https://github.com/".insteadOf [email protected]:
RUN git config --global url."https://".insteadOf git://
COPY package.json *yarn* ./
RUN bundle install
RUN yarn install
COPY . /myapp

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

and this is docker section of my webpacker.yml:

(这是我的webpacker.yml的docker部分:)

docker:
  <<: *default
  compile: true

  # Verifies that versions and hashed value of the package contents in the project's package.json
  check_yarn_integrity: false

  # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: webpacker
    port: 3035
    public: localhost:3035
    hmr: true
    # Inline should be set to true if using HMR
    inline: true
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false
    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: /node_modules/

I've got no idea how my Docker container keeps holding on to this reference to admin-xxxxxxe105.js and would ideally like to fix my dev environment so that I don't have to force a change to admin.js everytime I rebuild a container.

(我不知道我的Docker容器如何继续保持对admin-xxxxxxe105.js引用,并且理想情况下是要修复我的开发环境,这样我每次重建A时都不必强制更改admin.js。容器。)

  ask by whatapalaver translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this in config/ YOUR_ENVIRONMENT .rb

(在config / YOUR_ENVIRONMENT .rb中尝试)

# Disable serving static files from the /public folder by default since # Apache or NGINX already handles this.

(#默认情况下,禁止从/public文件夹提供静态文件,因为#Apache或NGINX已经处理了此问题。)

config.public_file_server.enabled = true

(config.public_file_server.enabled = true)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...