Coder Social home page Coder Social logo

redmine_development_docker's Introduction

VSCode Remote ContainerでRedmineのDocker開発環境にVSCodeから接続する

前提条件

  • Docker Desktopを起動している
  • Visual Studio Codeが利用できる

利用手順

  • このリポジトリを手元にClone
$ git clone --config=core.autocrlf=input https://github.com/ishikawa999/redmine_development_docker.git
$ cd ./redmine_development_docker
  • .envを書き換える
# RedmineのリポジトリのURL。後から変えることも可能
REPOSITORY_URL=https://github.com/redmine/redmine.git
# リポジトリのブランチ名。
REPOSITORY_BRANCH=
# VSCodeで表示する名前。バージョンごとに作るときは変えた方が良いかも
APP_NAME=Redmine
# 開発中のRedmineに http://localhost:8000 でアクセス出来るようになる。8000を既に使っている場合は変える
APP_PORT=8000
# Seleniumのテストを実行するとき以外はそのまま
SELENIUM_PORT_1=4444
SELENIUM_PORT_2=5900
# Redmineから送信したメールを http://localhost:1080 で確認出来るようになる。1080を既に使っている場合は変える
MAILCATCHER_PORT=1080
# 開発するRedmineの推奨Rubyバージョンに応じて変える
RUBY_VERSION=3.0
# mysqlやsqlite3に変えても良い。mysqlの場合、docker-compose.ymlのMySQL関連のコメントアウトを外す
RAILS_DB_ADAPTER=postgresql
  • update_devcontainer_setting.shを実行
$ bash update_devcontainer_setting.sh
  • そのアプリケーション独自の設定や、自分の開発環境用のカスタマイズがしたい場合はscripts/custom_shell.shに書く(entrypointで実行される)

  • VScodeに拡張機能Remote-Containersをインストール

  • VScodeで/your/path/redmine_development_docker を開いた状態で、VSCodeのコマンドパレットからRemote Containers: Rebuild and Reopen in Container(もしくは右下に出てくるポップアップのReopen in Container)を選択 => ビルドが始まるはず

ScreenShot 2020-09-24 11 16 27

  • VSCodeの左側のバーが赤くなり、左側のファイルツリーも表示されたらコンテナ内に入れている状態

ScreenShot 2020-09-24 11 59 24

  • ターミナルのタブを追加し、
$ bundle install
$ rails s -b 0.0.0.0

ScreenShot 2020-09-24 11 59 51

  • テストの実行
$ bundle exec rake test RAILS_ENV=test

おまけ

リポジトリを https://github.com/redmine/redmine.git から自分のリポジトリに変えたい

コンテナ内に入っている状態で、

$ git remote set-url origin <リポジトリのURL>
$ git fetch origin
$ git reset --hard origin/master

もしくは、コンテナから出て.envのREPOSITORY_URLを変更してから既存のappディレクトリを削除し、update_devcontainer_setting.shを再実行

VSCodeの拡張機能を増やしたい

.devcontainer/devcontainer.jsonのextensionsに拡張機能を追加し、VSCodeのコマンドパレットからRebuild and Reopen container

Redmineから送信されるメールの内容をチェック

http://localhost:[.envで指定したMAILCATCHER_PORT] でにアクセスするとメールキャッチャーを開ける

test/systemのテストを実行する場合

docker-compose.yml内のchrome:の塊のコメントアウトを外し、VSCodeのコマンドパレットからRebuild and Reopen container

selenium/standalone-chrome-debugイメージから持ってきたchromeを動かすためにCapybara周りで下のように設定を追加する。 app == docker-composeでrailsアプリケーションが動いているところのサービス名 chrome:4444 == docker-compose selenium/standalone-chrome-debugイメージのサービス名 + port

diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb
index 1a1e0cb4a..fedbe7d15 100644
--- a/test/application_system_test_case.rb
+++ b/test/application_system_test_case.rb
@@ -43,13 +43,17 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
                     }
                   }
                 )
-
+  options[:browser] = :remote
+  Capybara.server_host = 'app'
+  Capybara.server_port = <.envのAPP_PORT(デフォルト8000)に入れた値に書き換える>
   driven_by(
     :selenium, using: :chrome, screen_size: [1024, 900],
     options: options
   )
 
   setup do
+    Capybara.app_host = "http://#{Capybara.server_host}:#{Capybara.server_port}"
     # Allow defining a custom app host (useful when using a remote Selenium hub)
     if ENV['CAPYBARA_APP_HOST']
       Capybara.configure do |config|
 bundle exec rake test TEST=test/system RAILS_ENV=test

そのときホスト側で

open vnc://localhost:5900

を実行すると実際に動いているChromeの画面を見ることができる。 (パスワードを要求されたら secret と入れる)

redmine_development_docker's People

Contributors

ishikawa999 avatar matobaa avatar sanak avatar sk-ys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

redmine_development_docker's Issues

webdriverのバージョンが衝突している

以下のログが出てビルドに失敗した。

Step 13/18 : RUN bundle update
 ---> Running in 11a0fb879734
[2021-02-14T12:47:28.637Z] [PID 13752] No adapter found in config/database.yml, please configure it first
[2021-02-14T12:47:28.669Z] [PID 13752] No adapter found in config/database.yml, please configure it first

[!] There was an error parsing `Gemfile`:
[!] There was an error parsing `Gemfile.local`: You cannot specify the same gem twice with different version require
ments.
You specified: webdrivers (~> 4.4) and webdrivers (>= 0). Bundler cannot continue.

 #  from /var/lib/redmine/Gemfile.local:10
 #  -------------------------------------------
 #  gem 'timecop'
 >  gem 'webdrivers'
 #  -------------------------------------------
. Bundler cannot continue.

 #  from /var/lib/redmine/Gemfile.local:10
 #  -------------------------------------------
 #  gem 'request_store', '~> 1.5.0'
 >  gem "mini_mime", "~> 1.0.1"
 #  gem "actionpack-xml_parser"
 #  -------------------------------------------

gpg ファイルの作成に失敗する

Dockerfile の FROM mcr.microsoft.com/vscode/devcontainers/ruby:$RUBY_VERSION で取得される最新のイメージでは、OSが Debian GNU/Linux 11 (bullseye) となっており、/etc/apt/keyrings ディレクトリが存在しないために /etc/apt/keyrings/nodesource.gpg の作成に失敗するようです。

エラーログ(抜粋):

8.011 gpg: can't create
[2024-03-03T00:01:57.958Z]  '/etc/apt/keyrings/nodesource.gpg': No such file or directory
8.011 gpg: no valid OpenPGP data found.
8.011 gpg: dearmoring failed: No such file or directory
8.126 (23) Failed writing body
8.131 deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main
8.186 Hit:1 http://deb.debian.org/debian bullseye InRelease
8.209 Hit:2 http://deb.debian.org/debian-security bullseye-security InRelease
8.236 Hit:3 http://deb.debian.org/debian bullseye-updates InRelease
8.277 Hit:4 https://dl.yarnpkg.com/debian stable InRelease
8.313 Get:5 https://deb.nodesource.com/node_20.x nodistro InRelease [12.1 kB]
8.385 Err:5 https://deb.nodesource.com/node_20.x nodistro InRelease
8.385   The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2F59B5F99B1BE0B4
8.388 Reading package lists...
8.671 W: GPG error: https://deb.nodesource.com/node_20.x nodistro InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2F59B5F99B1BE0B4
8.671 E: The repository 'https://deb.nodesource.com/node_20.x nodistro InRelease' is not signed.
------
failed to solve: process "/bin/sh -c /setup.sh" did not complete successfully: exit code: 100

さしあたり /scripts/setup.sh の nodejs インストールコマンド群の前に mkdir /etc/apt/keyrings を挿入することで動くことは確認できたのですが、これが最適解なのかわからないため報告までにいたします。

 scripts/setup.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/setup.sh b/scripts/setup.sh
index 6decb11..eaa9ec2 100644
--- a/scripts/setup.sh
+++ b/scripts/setup.sh
@@ -32,6 +32,7 @@ update-locale
 locale-gen ja_JP.UTF-8
 localedef -f UTF-8 -i ja_JP ja_JP
 
+mkdir /etc/apt/keyrings
 apt-get update && apt-get install -y ca-certificates curl gnupg
 curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
 NODE_MAJOR=20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.