

環境下ではインターネットに直接接続できないため、以下のような形でインストールをすることになります。

  1. 別の端末でrack-corsをダウンロード
  2. Redmine環境に送信
  3. インストール
  4. CORS設定
  5. 再起動

上記1については以下のURLから.gemをダウンロードしました。  
"gem list"でリストに表示されていることが確認できています。  
[RubyGemsサイト](https://rubygems.org/gems/rack-cors/versions/1.1.1)

3のインストール手順については以下です。  
[gemインストール手順](https://makandat.wordpress.com/2016/10/10/ruby-
gem-%E3%82%92%E6%89%8B%E5%8B%95%E3%81%A7%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/)

ただ起動するとエラーになります。

[code]

    The Gemfile's dependencies are satisfied
    Your Gemfile lists the gem puma (< 6.0.0) more than once.
    You should probably keep only one of them.
    Remove any duplicate entries and specify the gem only once.
    While it's not a problem now, it could cause errors if you change the version of one of them later.
    The Gemfile's dependencies are satisfied
    rake aborted!
    NameError: uninitialized constant Rack::Cors
    /usr/src/redmine/config/initializers/cors.rb:1:in `<top (required)>'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/engine.rb:681:in `block in load_config_initializer'
    /usr/local/bundle/gems/activesupport-6.1.7/lib/active_support/notifications.rb:205:in `instrument'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/engine.rb:680:in `load_config_initializer'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/engine.rb:633:in `each'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/engine.rb:633:in `block in <class:Engine>'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:32:in `instance_exec'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:32:in `run'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:61:in `block in run_initializers'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:50:in `each'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:50:in `tsort_each_child'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/initializable.rb:60:in `run_initializers'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/application.rb:391:in `initialize!'
    /usr/src/redmine/config/environment.rb:16:in `<top (required)>'
    /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
    /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/application.rb:367:in `require_environment!'
    /usr/local/bundle/gems/railties-6.1.7/lib/rails/application.rb:533:in `block in run_tasks_blocks'
    Tasks: TOP => db:migrate => db:load_config => environment
    (See full trace by running task with --trace)
    
[/code]

環境はDockerDesktopです。  
Dockerfileは以下内容です。  
4のCORS設定は"cors.rb"ファイルです。

[code]

    FROM redmine:latest
    
    # CORS
    RUN apt-get update -y
    RUN apt-get install git vim unzip -y
    
    WORKDIR /usr/src/redmine/
    
    # install lib for CORS.
    COPY ./rack-cors-1.1.1.gem /root/
    RUN gem install --local /root/rack-cors-1.1.1.gem
    
    # CORS setting.
    RUN { \
        echo "Rails.application.config.middleware.insert_before 0, Rack::Cors do"; \
        echo "  allow do"; \
        echo "    origins '*'" ; \
        echo "    resource '*', headers: :any, methods: [:get, :post, :patch, :put, :options]" ; \
        echo "  end" ; \
        echo "end" ; \
        echo; \
    } >> /root/cors.rb
    RUN cp /root/cors.rb ./config/initializers/
    
[/code]


CC BY-SA 4.0
2023-01-29T07:58:11.563
93605
2023-01-29T07:58:11.563
53585
question
docker docker-compose redmine cors
Redmineにrack-corsをインストールする方法をご教示ください