From 40d34438a55b3424a1310c0ddb9463a41ab655a4 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Sat, 30 Jul 2022 15:45:02 +0000 Subject: [PATCH 1/8] =?UTF-8?q?Add=20VSCode=20devcontainer=E7=94=A8?= =?UTF-8?q?=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/.env | 5 + .devcontainer/devcontainer.json | 41 ++++++ .../overwrite_files/.vscode/launch.json | 17 +++ .devcontainer/overwrite_files/Gemfile.local | 16 +++ .../overwrite_files/additional_environment.rb | 4 + .../overwrite_files/configuration.yml | 10 ++ .devcontainer/overwrite_files/database.yml | 23 ++++ .devcontainer/scripts/entrypoint.sh | 11 ++ .devcontainer/scripts/postStartCommand.sh | 8 ++ .gitignore | 2 + Dockerfile-for-redmine-dev-mirror | 34 +++++ README.md | 119 +++++++++++++++++- 12 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/.env create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/overwrite_files/.vscode/launch.json create mode 100644 .devcontainer/overwrite_files/Gemfile.local create mode 100644 .devcontainer/overwrite_files/additional_environment.rb create mode 100644 .devcontainer/overwrite_files/configuration.yml create mode 100644 .devcontainer/overwrite_files/database.yml create mode 100644 .devcontainer/scripts/entrypoint.sh create mode 100644 .devcontainer/scripts/postStartCommand.sh create mode 100644 Dockerfile-for-redmine-dev-mirror diff --git a/.devcontainer/.env b/.devcontainer/.env new file mode 100644 index 0000000000..e287b6e88b --- /dev/null +++ b/.devcontainer/.env @@ -0,0 +1,5 @@ +APP_PORT=8000 +SELENIUM_PORT_1=4444 +SELENIUM_PORT_2=5900 +MAILCATCHER_PORT=1080 +RAILS_DB_ADAPTER=postgresql diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..b9a8eb06ac --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,41 @@ +// Update the VARIANT arg in docker-compose.yml to pick a Ruby version +{ + "name": "Redmine dev mirror", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/var/lib/redmine", + "shutdownAction": "stopCompose", + "postStartCommand": "bash ./.devcontainer/scripts/postStartCommand.sh", + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "rebornix.ruby", + "eamodio.gitlens", + "kaiwood.endwise", + "mtxr.sqltools", + "mtxr.sqltools-driver-pg", + "ms-vsliveshare.vsliveshare" + ], + "settings": { + "workbench.colorCustomizations": { + "activityBar.background": "#ab3e3e" + }, + "sqltools.connections": [ + { + "previewLimit": 50, + "server": "postgresdb", + "port": 5432, + "driver": "PostgreSQL", + "name": "app_development", + "database": "app_development", + "username": "db_user", + "password": "password" + } + ] + } + } + } +} \ No newline at end of file diff --git a/.devcontainer/overwrite_files/.vscode/launch.json b/.devcontainer/overwrite_files/.vscode/launch.json new file mode 100644 index 0000000000..95285ae0cd --- /dev/null +++ b/.devcontainer/overwrite_files/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Rails server", + "type": "Ruby", + "request": "launch", + "cwd": "${workspaceRoot}", + "program": "${workspaceRoot}/bin/rails", + "args": [ + "server", + "-b", + "0" + ] + } + ] +} diff --git a/.devcontainer/overwrite_files/Gemfile.local b/.devcontainer/overwrite_files/Gemfile.local new file mode 100644 index 0000000000..ddfc5cca2b --- /dev/null +++ b/.devcontainer/overwrite_files/Gemfile.local @@ -0,0 +1,16 @@ +gem 'pry-rails' +gem 'pry-byebug' +gem 'binding_of_caller' +gem 'better_errors' +gem 'view_source_map' +gem 'parallel_tests' +gem 'benchmark-ips' +gem 'activeresource' +gem 'timecop' +if Gem.ruby_version < Gem::Version.new('3.1.0') + gem 'ruby-debug-ide' + gem 'debase', '~> 0.2.5beta2' +end +if Gem.ruby_version >= Gem::Version.new('2.7.0') + gem 'debug' +end diff --git a/.devcontainer/overwrite_files/additional_environment.rb b/.devcontainer/overwrite_files/additional_environment.rb new file mode 100644 index 0000000000..e82846f4c3 --- /dev/null +++ b/.devcontainer/overwrite_files/additional_environment.rb @@ -0,0 +1,4 @@ +# redmine-dev-mirror用ファイル + +# ログの保存箇所をvolumesの対象外にして同期による負かを軽くする +config.logger = Logger.new('../redmine.log', 2, 1000000) diff --git a/.devcontainer/overwrite_files/configuration.yml b/.devcontainer/overwrite_files/configuration.yml new file mode 100644 index 0000000000..6053be2184 --- /dev/null +++ b/.devcontainer/overwrite_files/configuration.yml @@ -0,0 +1,10 @@ +# redmine-dev-mirror + +development: + email_delivery: + delivery_method: :smtp + smtp_settings: + address: 'smtp' + port: 1025 +test: +production: diff --git a/.devcontainer/overwrite_files/database.yml b/.devcontainer/overwrite_files/database.yml new file mode 100644 index 0000000000..929f9f4d0b --- /dev/null +++ b/.devcontainer/overwrite_files/database.yml @@ -0,0 +1,23 @@ +# redmine-dev-mirror + +production: + adapter: <%= ENV['RAILS_DB_ADAPTER'] %> + database: <%= ENV['RAILS_DB'] %> + username: <%= ENV['RAILS_DB_USERNAME'] %> + password: <%= ENV['RAILS_DB_PASSWORD'] %> + host: <%= ENV['RAILS_DB_HOST'] %> + encoding: <%= ENV['RAILS_DB_ENCODING'] %> +development: + adapter: <%= ENV['RAILS_DB_ADAPTER'] %> + database: <%= ENV['RAILS_DB'] %>_development + username: <%= ENV['RAILS_DB_USERNAME'] %> + password: <%= ENV['RAILS_DB_PASSWORD'] %> + host: <%= ENV['RAILS_DB_HOST'] %> + encoding: <%= ENV['RAILS_DB_ENCODING'] %> +test: + adapter: <%= ENV['RAILS_DB_ADAPTER'] %> + database: <%= ENV['RAILS_DB'] %>_test + username: <%= ENV['RAILS_DB_USERNAME'] %> + password: <%= ENV['RAILS_DB_PASSWORD'] %> + host: <%= ENV['RAILS_DB_HOST'] %> + encoding: <%= ENV['RAILS_DB_ENCODING'] %> \ No newline at end of file diff --git a/.devcontainer/scripts/entrypoint.sh b/.devcontainer/scripts/entrypoint.sh new file mode 100644 index 0000000000..8338caf91d --- /dev/null +++ b/.devcontainer/scripts/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +bundle install +rake generate_secret_token + +rake db:create +rake db:migrate +rake redmine:plugins:migrate +rake log:clear + +exec "$@" diff --git a/.devcontainer/scripts/postStartCommand.sh b/.devcontainer/scripts/postStartCommand.sh new file mode 100644 index 0000000000..0bf9ff5fc6 --- /dev/null +++ b/.devcontainer/scripts/postStartCommand.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /var/lib/redmine +cp .devcontainer/overwrite_files/Gemfile.local Gemfile.local +cp .devcontainer/overwrite_files/database.yml config/database.yml +cp .devcontainer/overwrite_files/configuration.yml config/configuration.yml +cp .devcontainer/overwrite_files/additional_environment.rb config/additional_environment.rb +cp -r .devcontainer/overwrite_files/.vscode .vscode diff --git a/.gitignore b/.gitignore index d90a44f348..067820597a 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ yarn-error.log docker-compose.yml + +/.vscode \ No newline at end of file diff --git a/Dockerfile-for-redmine-dev-mirror b/Dockerfile-for-redmine-dev-mirror new file mode 100644 index 0000000000..819a53587e --- /dev/null +++ b/Dockerfile-for-redmine-dev-mirror @@ -0,0 +1,34 @@ +# Supported ruby versions: 3, 3.0, 3-bullseye, 3.0-bullseye, 3-buster, 3.0-buster, 2, 2.7, 2-bullseye, 2.7-bullseye, 2-buster, 2.7-buster, 2.6, 2.6-bullseye, 2.6-buster +# 3.0系以外のRubyで動作検証やテストをしたい場合は3の部分を上の候補のうちのどれかに書き換えてください +FROM mcr.microsoft.com/vscode/devcontainers/ruby:3 +ARG APP_HOME +ARG APP_PORT +ENV LANG C.UTF-8 + +ENV DEBIAN_FRONTEND noninteractive +RUN set -eux; \ + apt update && \ + apt install -y --no-install-recommends \ + bzr gsfonts imagemagick libmagick++-dev \ + ; \ + curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ + apt install -y nodejs && \ + apt clean && \ + rm -rf /var/lib/apt/lists/*; +ENV DEBIAN_FRONTEND dialog + +WORKDIR /var/lib/redmine +ADD . /var/lib/redmine + +COPY ./.devcontainer/scripts/. / +RUN chmod +x /entrypoint.sh; \ + chmod +x /postStartCommand.sh; + +RUN /postStartCommand.sh +RUN bundle update +RUN bundle install + +EXPOSE $APP_PORT + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/bin/bash"] diff --git a/README.md b/README.md index 2e0ca56282..af285a9534 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,121 @@ https://redmine-patch.connpass.com/ ### 4. イベントの時間になったらDiscordを開いて、ボイスチャンネルに参加しよう! -(時間になったら他の参加者も参加しているはず) \ No newline at end of file +(時間になったら他の参加者も参加しているはず) + +## VSCode Remote ContainerによるRedmineの開発環境の作り方 / 機能 + +Redmineの開発環境を作るやり方のうちの一つです。開発環境がすでにある人はこの手順を使わなくても大丈夫です。 + +### 前提条件 + +* Docker Desktopを起動している +* Visual Studio Codeが利用できる + +### 利用手順 + +* このリポジトリを手元にClone + +```bash session +$ git clone --config=core.autocrlf=input https://github.com/redmine-patch-meetup/redmine-dev-mirror.git +$ cd ./redmine-dev-mirror +``` + +* 必要に応じて.envを書き換える(portの衝突がなければデフォルトでも動きます) + +```bash +# 開発中のRedmineに http://localhost:8000 でアクセス出来るようになる。8000を既に使っている場合は変える +APP_PORT=8000 +# Seleniumのテストを実行するときに利用するポート。4444, 5900を既に使っている場合は変える +SELENIUM_PORT_1=4444 +SELENIUM_PORT_2=5900 +# Redmineから送信したメールを http://localhost:1080 で確認出来るようになる。1080を既に使っている場合は変える +MAILCATCHER_PORT=1080 +# mysqlやsqlite3に変えても良い。mysqlの場合、.devcontainer/docker-compose.ymlのMySQL関連のコメントアウトを外す +RAILS_DB_ADAPTER=postgresql +``` + +* VScodeに拡張機能[Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)をインストール + +* VScodeで/your/path/redmine-dev-mirror を開いた状態で、VSCodeのコマンドパレットからRemote Containers: Rebuild and Reopen in Container(もしくは右下に出てくるポップアップのReopen in Container)を選択 => ビルドが始まるはず + +スクリーンショット 2022-07-31 12 35 51 + +* VSCodeの左側のバーが赤くなり、左側のファイルツリーも表示されたらコンテナ内に入れている状態 + +画面下のターミナルに"Press any key"と表示されるため、「キー入力を行い(ターミナルが閉じる)、メニューからターミナルを開く」か 「"Press any key"を放置したままターミナル右上のプラスを押す」 という流れでコマンドを入力できるようにする。 + +スクリーンショット 2022-07-31 12 37 54 +↓ +スクリーンショット 2022-07-31 12 41 52 + +* 画面下のターミナル内で +```bash +$ rails s -b 0.0.0.0 +``` +* 少し待つと、ブラウザから http://localhost:[.envで指定したAPP_PORT] でRedmineにアクセスできるようになる。 + +スクリーンショット 2022-07-31 12 42 01 + +* テストの実行 +```bash +$ bundle exec rake test RAILS_ENV=test +``` + +### おまけ + +#### 1. VSCodeの拡張機能を増やしたい + +.devcontainer/devcontainer.jsonのextensionsに拡張機能を追加し、VSCodeのコマンドパレットからRebuild and Reopen container + +#### 2. Redmineから送信されるメールの内容をチェック + +http://localhost:[.envで指定したMAILCATCHER_PORT] でにアクセスするとメールキャッチャーを開ける + +#### 3. Ruby3.0系以外のバージョンで動作検証やテストをしたい + +Dockerfile-for-redmine-dev-mirrorファイルの ``FROM mcr.microsoft.com/vscode/devcontainers/ruby:3` の3部分を利用したいバージョンに書き換えて、VSCodeのコマンドパレットからRebuild and Reopen container + +#### 4. test/systemのテストを実行する場合 + +.devcontainer/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 +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` と入れる) From 5a050c0c4a5b1b29cd7acf166d5bc0eefd9391d0 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Sun, 31 Jul 2022 13:53:50 +0900 Subject: [PATCH 2/8] Add docker-compose.yml --- .devcontainer/docker-compose.yml | 63 ++++++++++++++++++++++++++++++++ .gitignore | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000000..1f532e664e --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,63 @@ +version: '3' +services: + + # PostgreSQL + postgresdb: + image: postgres:11 + restart: on-failure:5 + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: db_user + + # MySQL + # mysqldb: + # image: mysql:5 + # restart: on-failure:5 + # environment: + # MYSQL_ROOT_PASSWORD: password + # MYSQL_PASSWORD: password + # MYSQL_USER: db_user + + app: + build: + context: .. + dockerfile: Dockerfile-for-redmine-dev-mirror + args: + APP_HOME: /var/lib/redmine + APP_PORT: $APP_PORT + environment: + RAILS_DB_ADAPTER: postgresql + RAILS_DB_HOST: postgresdb + RAILS_DB: app + RAILS_DB_USERNAME: db_user + RAILS_DB_PASSWORD: password + RAILS_DB_ENCODING: utf8 + RAILS_ENV: development + env_file: .env + tty: true + ports: + - $APP_PORT:3000 + depends_on: + - postgresdb + # - mysqldb + volumes: + - ../.:/var/lib/redmine:cached + # 全体を同期すると速度が遅くなるため、上の1行を消して下の4行のコメントアウトを外してもいい + # その場合、同期場所がgitの履歴とtmpディレクトリのみになるため、git commitしたもの + shareディレクトリに入れたファイル以外はコンテナのキャッシュが消えたときに消える + # - ../.git:/var/lib/redmine/.git + # - ../tmp:/var/lib/redmine/tmp + # - ../public:/var/lib/redmine/public + # - ../plugins:/var/lib/redmine/plugins + + # For selenium test + # chrome: + # M1の場合はselenium/standalone-chrome-debugが動かないため、seleniarm/standalone-chromium:latestを代わりに使うこと。 + # image: selenium/standalone-chrome-debug:3.141.59-20210913 + # ports: + # - $SELENIUM_PORT_1:4444 + # - $SELENIUM_PORT_2:5900 + + smtp: + image: schickling/mailcatcher + ports: + - $MAILCATCHER_PORT:1080 diff --git a/.gitignore b/.gitignore index 067820597a..f3e4ea2546 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,6 @@ /node_modules yarn-error.log -docker-compose.yml +/docker-compose.yml /.vscode \ No newline at end of file From 45d00d8b863450b15df636a9cf9f811f843635e5 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Mon, 1 Aug 2022 09:34:20 +0000 Subject: [PATCH 3/8] Clean up --- .devcontainer/create-db-user.sql | 2 + .devcontainer/devcontainer.json | 7 +-- .devcontainer/docker-compose.yml | 29 +++++++----- .../.vscode/launch.json | 0 .../{overwrite_files => files}/Gemfile.local | 0 .../additional_environment.rb | 2 +- .../configuration.yml | 0 .../{overwrite_files => files}/database.yml | 0 .devcontainer/scripts/entrypoint.sh | 1 + .devcontainer/scripts/move_files.sh | 7 +++ .devcontainer/scripts/postStartCommand.sh | 8 ---- Dockerfile-for-redmine-dev-mirror | 47 +++++++++---------- 12 files changed, 55 insertions(+), 48 deletions(-) create mode 100644 .devcontainer/create-db-user.sql rename .devcontainer/{overwrite_files => files}/.vscode/launch.json (100%) rename .devcontainer/{overwrite_files => files}/Gemfile.local (100%) rename .devcontainer/{overwrite_files => files}/additional_environment.rb (67%) rename .devcontainer/{overwrite_files => files}/configuration.yml (100%) rename .devcontainer/{overwrite_files => files}/database.yml (100%) create mode 100644 .devcontainer/scripts/move_files.sh delete mode 100644 .devcontainer/scripts/postStartCommand.sh diff --git a/.devcontainer/create-db-user.sql b/.devcontainer/create-db-user.sql new file mode 100644 index 0000000000..24417a9bd4 --- /dev/null +++ b/.devcontainer/create-db-user.sql @@ -0,0 +1,2 @@ +CREATE USER vscode CREATEDB; +CREATE DATABASE vscode WITH OWNER vscode; \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b9a8eb06ac..4ff690ce96 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,9 +3,8 @@ "name": "Redmine dev mirror", "dockerComposeFile": "docker-compose.yml", "service": "app", - "workspaceFolder": "/var/lib/redmine", + "workspaceFolder": "/workspace", "shutdownAction": "stopCompose", - "postStartCommand": "bash ./.devcontainer/scripts/postStartCommand.sh", // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. @@ -37,5 +36,7 @@ ] } } - } + }, + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 1f532e664e..40cde62ef4 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -3,11 +3,13 @@ services: # PostgreSQL postgresdb: - image: postgres:11 + image: postgres:14 restart: on-failure:5 + volumes: + - ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql environment: - POSTGRES_PASSWORD: password - POSTGRES_USER: db_user + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres # MySQL # mysqldb: @@ -23,14 +25,19 @@ services: context: .. dockerfile: Dockerfile-for-redmine-dev-mirror args: - APP_HOME: /var/lib/redmine APP_PORT: $APP_PORT + # Update 'VARIANT' to pick a version of Ruby: 3, 3.1, 3.0, 2, 2.7, 2.6 + # Append -bullseye or -buster to pin to an OS version. + # Use -bullseye variants on local arm64/Apple Silicon. + VARIANT: "3.0-bullseye" + # Optional Node.js version to install + NODE_VERSION: "14" environment: RAILS_DB_ADAPTER: postgresql RAILS_DB_HOST: postgresdb RAILS_DB: app - RAILS_DB_USERNAME: db_user - RAILS_DB_PASSWORD: password + RAILS_DB_USERNAME: postgres + RAILS_DB_PASSWORD: postgres RAILS_DB_ENCODING: utf8 RAILS_ENV: development env_file: .env @@ -41,13 +48,13 @@ services: - postgresdb # - mysqldb volumes: - - ../.:/var/lib/redmine:cached + - ..:/workspace:cached # 全体を同期すると速度が遅くなるため、上の1行を消して下の4行のコメントアウトを外してもいい # その場合、同期場所がgitの履歴とtmpディレクトリのみになるため、git commitしたもの + shareディレクトリに入れたファイル以外はコンテナのキャッシュが消えたときに消える - # - ../.git:/var/lib/redmine/.git - # - ../tmp:/var/lib/redmine/tmp - # - ../public:/var/lib/redmine/public - # - ../plugins:/var/lib/redmine/plugins + # - ../.git:/workspace/.git + # - ../tmp:/workspace/tmp + # - ../public:/workspace/public + # - ../plugins:/workspace/plugins # For selenium test # chrome: diff --git a/.devcontainer/overwrite_files/.vscode/launch.json b/.devcontainer/files/.vscode/launch.json similarity index 100% rename from .devcontainer/overwrite_files/.vscode/launch.json rename to .devcontainer/files/.vscode/launch.json diff --git a/.devcontainer/overwrite_files/Gemfile.local b/.devcontainer/files/Gemfile.local similarity index 100% rename from .devcontainer/overwrite_files/Gemfile.local rename to .devcontainer/files/Gemfile.local diff --git a/.devcontainer/overwrite_files/additional_environment.rb b/.devcontainer/files/additional_environment.rb similarity index 67% rename from .devcontainer/overwrite_files/additional_environment.rb rename to .devcontainer/files/additional_environment.rb index e82846f4c3..bd5a6dde92 100644 --- a/.devcontainer/overwrite_files/additional_environment.rb +++ b/.devcontainer/files/additional_environment.rb @@ -1,4 +1,4 @@ # redmine-dev-mirror用ファイル # ログの保存箇所をvolumesの対象外にして同期による負かを軽くする -config.logger = Logger.new('../redmine.log', 2, 1000000) +config.logger = Logger.new('../logs/redmine.log', 2, 1000000) diff --git a/.devcontainer/overwrite_files/configuration.yml b/.devcontainer/files/configuration.yml similarity index 100% rename from .devcontainer/overwrite_files/configuration.yml rename to .devcontainer/files/configuration.yml diff --git a/.devcontainer/overwrite_files/database.yml b/.devcontainer/files/database.yml similarity index 100% rename from .devcontainer/overwrite_files/database.yml rename to .devcontainer/files/database.yml diff --git a/.devcontainer/scripts/entrypoint.sh b/.devcontainer/scripts/entrypoint.sh index 8338caf91d..856aba8e08 100644 --- a/.devcontainer/scripts/entrypoint.sh +++ b/.devcontainer/scripts/entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash +/move_files.sh bundle install rake generate_secret_token diff --git a/.devcontainer/scripts/move_files.sh b/.devcontainer/scripts/move_files.sh new file mode 100644 index 0000000000..78dd39ff10 --- /dev/null +++ b/.devcontainer/scripts/move_files.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cp .devcontainer/files/Gemfile.local Gemfile.local +cp .devcontainer/files/database.yml config/database.yml +cp .devcontainer/files/configuration.yml config/configuration.yml +cp .devcontainer/files/additional_environment.rb config/additional_environment.rb +cp -r .devcontainer/files/.vscode .vscode diff --git a/.devcontainer/scripts/postStartCommand.sh b/.devcontainer/scripts/postStartCommand.sh deleted file mode 100644 index 0bf9ff5fc6..0000000000 --- a/.devcontainer/scripts/postStartCommand.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cd /var/lib/redmine -cp .devcontainer/overwrite_files/Gemfile.local Gemfile.local -cp .devcontainer/overwrite_files/database.yml config/database.yml -cp .devcontainer/overwrite_files/configuration.yml config/configuration.yml -cp .devcontainer/overwrite_files/additional_environment.rb config/additional_environment.rb -cp -r .devcontainer/overwrite_files/.vscode .vscode diff --git a/Dockerfile-for-redmine-dev-mirror b/Dockerfile-for-redmine-dev-mirror index 819a53587e..83c617adc9 100644 --- a/Dockerfile-for-redmine-dev-mirror +++ b/Dockerfile-for-redmine-dev-mirror @@ -1,34 +1,31 @@ -# Supported ruby versions: 3, 3.0, 3-bullseye, 3.0-bullseye, 3-buster, 3.0-buster, 2, 2.7, 2-bullseye, 2.7-bullseye, 2-buster, 2.7-buster, 2.6, 2.6-bullseye, 2.6-buster -# 3.0系以外のRubyで動作検証やテストをしたい場合は3の部分を上の候補のうちのどれかに書き換えてください -FROM mcr.microsoft.com/vscode/devcontainers/ruby:3 -ARG APP_HOME -ARG APP_PORT -ENV LANG C.UTF-8 +# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster +ARG VARIANT=3.1-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/ruby:${VARIANT} -ENV DEBIAN_FRONTEND noninteractive -RUN set -eux; \ - apt update && \ - apt install -y --no-install-recommends \ - bzr gsfonts imagemagick libmagick++-dev \ - ; \ - curl -sL https://deb.nodesource.com/setup_14.x | bash - && \ - apt install -y nodejs && \ - apt clean && \ - rm -rf /var/lib/apt/lists/*; -ENV DEBIAN_FRONTEND dialog +# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service +# The value is a comma-separated list of allowed domains +ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev" -WORKDIR /var/lib/redmine -ADD . /var/lib/redmine +# [Choice] Node.js version: lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="lts/*" +RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1" + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends bzr gsfonts imagemagick libmagick++-dev + +WORKDIR /workspace +ADD . /workspace COPY ./.devcontainer/scripts/. / RUN chmod +x /entrypoint.sh; \ - chmod +x /postStartCommand.sh; - -RUN /postStartCommand.sh -RUN bundle update -RUN bundle install + chmod +x /move_files.sh; \ + /move_files.sh; \ + mkdir /logs; touch /logs/redmine.log; chown -R vscode /logs; \ + bundle update; \ + bundle install; EXPOSE $APP_PORT ENTRYPOINT ["/entrypoint.sh"] -CMD ["/bin/bash"] +CMD ["/bin/bash"] \ No newline at end of file From f73bf1c8a55e026aa3a1e4796d1858f99e8f3401 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Mon, 1 Aug 2022 13:33:34 +0000 Subject: [PATCH 4/8] Move Dockerfile-for-redmine-dev-mirror to .devcontainer/Dockerfile --- .../Dockerfile | 14 -------------- .devcontainer/devcontainer.json | 2 ++ .devcontainer/docker-compose.yml | 3 ++- .devcontainer/files/additional_environment.rb | 2 +- .../{move_files.sh => postCreateCommand.sh} | 8 ++++++++ .../scripts/{entrypoint.sh => postStartCommand.sh} | 7 ++----- 6 files changed, 15 insertions(+), 21 deletions(-) rename Dockerfile-for-redmine-dev-mirror => .devcontainer/Dockerfile (75%) rename .devcontainer/scripts/{move_files.sh => postCreateCommand.sh} (74%) rename .devcontainer/scripts/{entrypoint.sh => postStartCommand.sh} (64%) diff --git a/Dockerfile-for-redmine-dev-mirror b/.devcontainer/Dockerfile similarity index 75% rename from Dockerfile-for-redmine-dev-mirror rename to .devcontainer/Dockerfile index 83c617adc9..f4adf9bb64 100644 --- a/Dockerfile-for-redmine-dev-mirror +++ b/.devcontainer/Dockerfile @@ -14,18 +14,4 @@ RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSI RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends bzr gsfonts imagemagick libmagick++-dev -WORKDIR /workspace -ADD . /workspace - -COPY ./.devcontainer/scripts/. / -RUN chmod +x /entrypoint.sh; \ - chmod +x /move_files.sh; \ - /move_files.sh; \ - mkdir /logs; touch /logs/redmine.log; chown -R vscode /logs; \ - bundle update; \ - bundle install; - EXPOSE $APP_PORT - -ENTRYPOINT ["/entrypoint.sh"] -CMD ["/bin/bash"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4ff690ce96..eb4acf502c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,6 +37,8 @@ } } }, + "postCreateCommand": "bash .devcontainer/scripts/postCreateCommand.sh", + "postStartCommand": "bash .devcontainer/scripts/postStartCommand.sh", // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "vscode" } \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 40cde62ef4..5bb61a390b 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -23,7 +23,7 @@ services: app: build: context: .. - dockerfile: Dockerfile-for-redmine-dev-mirror + dockerfile: .devcontainer/Dockerfile args: APP_PORT: $APP_PORT # Update 'VARIANT' to pick a version of Ruby: 3, 3.1, 3.0, 2, 2.7, 2.6 @@ -47,6 +47,7 @@ services: depends_on: - postgresdb # - mysqldb + command: sleep infinity volumes: - ..:/workspace:cached # 全体を同期すると速度が遅くなるため、上の1行を消して下の4行のコメントアウトを外してもいい diff --git a/.devcontainer/files/additional_environment.rb b/.devcontainer/files/additional_environment.rb index bd5a6dde92..cb4d7a099e 100644 --- a/.devcontainer/files/additional_environment.rb +++ b/.devcontainer/files/additional_environment.rb @@ -1,4 +1,4 @@ # redmine-dev-mirror用ファイル # ログの保存箇所をvolumesの対象外にして同期による負かを軽くする -config.logger = Logger.new('../logs/redmine.log', 2, 1000000) +config.logger = Logger.new('/logs/redmine.log', 2, 1000000) diff --git a/.devcontainer/scripts/move_files.sh b/.devcontainer/scripts/postCreateCommand.sh similarity index 74% rename from .devcontainer/scripts/move_files.sh rename to .devcontainer/scripts/postCreateCommand.sh index 78dd39ff10..391fa1ecf5 100644 --- a/.devcontainer/scripts/move_files.sh +++ b/.devcontainer/scripts/postCreateCommand.sh @@ -5,3 +5,11 @@ cp .devcontainer/files/database.yml config/database.yml cp .devcontainer/files/configuration.yml config/configuration.yml cp .devcontainer/files/additional_environment.rb config/additional_environment.rb cp -r .devcontainer/files/.vscode .vscode + +sudo mkdir /logs +sudo touch /logs/redmine.log +sudo chown -R vscode /logs + +bundle install + +rake db:create diff --git a/.devcontainer/scripts/entrypoint.sh b/.devcontainer/scripts/postStartCommand.sh similarity index 64% rename from .devcontainer/scripts/entrypoint.sh rename to .devcontainer/scripts/postStartCommand.sh index 856aba8e08..53b70d08ac 100644 --- a/.devcontainer/scripts/entrypoint.sh +++ b/.devcontainer/scripts/postStartCommand.sh @@ -1,12 +1,9 @@ #!/bin/bash -/move_files.sh -bundle install +bundle update rake generate_secret_token -rake db:create rake db:migrate rake redmine:plugins:migrate -rake log:clear -exec "$@" +rake log:clear From 22dcf36bd9bab89e2ddc4c25df8f36c70a59212e Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Mon, 1 Aug 2022 14:32:26 +0000 Subject: [PATCH 5/8] =?UTF-8?q?Fix=20Ruby=E3=81=AE=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E5=A4=89=E6=9B=B4=E3=81=AE=E6=89=8B?= =?UTF-8?q?=E9=A0=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af285a9534..ef71ec5807 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ http://localhost:[.envで指定したMAILCATCHER_PORT] でにアクセスする #### 3. Ruby3.0系以外のバージョンで動作検証やテストをしたい -Dockerfile-for-redmine-dev-mirrorファイルの ``FROM mcr.microsoft.com/vscode/devcontainers/ruby:3` の3部分を利用したいバージョンに書き換えて、VSCodeのコマンドパレットからRebuild and Reopen container +.devcontainer/docker-compose.yml ファイルの `VARIANT: "3.0-bullseye"` の3.0-bulleseye 部分を利用したいバージョンに書き換えて、VSCodeのコマンドパレットからRebuild and Reopen container #### 4. test/systemのテストを実行する場合 From d2626caaaa722d87ecd18c6be15a5e033f5943f8 Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Wed, 3 Aug 2022 18:21:32 +0900 Subject: [PATCH 6/8] Update README.md --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ef71ec5807..7895a2911b 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,11 @@ Redmineの開発環境を作るやり方のうちの一つです。開発環境 * このリポジトリを手元にClone ```bash session -$ git clone --config=core.autocrlf=input https://github.com/redmine-patch-meetup/redmine-dev-mirror.git -$ cd ./redmine-dev-mirror +git clone --config=core.autocrlf=input https://github.com/redmine-patch-meetup/redmine-dev-mirror.git +cd ./redmine-dev-mirror ``` -* 必要に応じて.envを書き換える(portの衝突がなければデフォルトでも動きます) +* 必要に応じて.devcontainer/.envを書き換える(portの衝突がなければデフォルトでも動きます) ```bash # 開発中のRedmineに http://localhost:8000 でアクセス出来るようになる。8000を既に使っている場合は変える @@ -74,29 +74,33 @@ RAILS_DB_ADAPTER=postgresql * VScodeに拡張機能[Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)をインストール -* VScodeで/your/path/redmine-dev-mirror を開いた状態で、VSCodeのコマンドパレットからRemote Containers: Rebuild and Reopen in Container(もしくは右下に出てくるポップアップのReopen in Container)を選択 => ビルドが始まるはず +* VScodeで/your/path/redmine-dev-mirror を開く -スクリーンショット 2022-07-31 12 35 51 +フォルダを開く様子 + +* 右下に出てくるポップアップのReopen in Containerを選択(出てこなかったらVSCodeのコマンドパレットからRemote Containers: Rebuild and Reopen in Containerを選択) => ビルドが始まるはず + +Reopen in Containerボタン * VSCodeの左側のバーが赤くなり、左側のファイルツリーも表示されたらコンテナ内に入れている状態 画面下のターミナルに"Press any key"と表示されるため、「キー入力を行い(ターミナルが閉じる)、メニューからターミナルを開く」か 「"Press any key"を放置したままターミナル右上のプラスを押す」 という流れでコマンドを入力できるようにする。 -スクリーンショット 2022-07-31 12 37 54 +Press any keyと表示されている画面 ↓ -スクリーンショット 2022-07-31 12 41 52 +コマンドを入力可能になった画面 * 画面下のターミナル内で ```bash -$ rails s -b 0.0.0.0 +rails s -b 0.0.0.0 ``` -* 少し待つと、ブラウザから http://localhost:[.envで指定したAPP_PORT] でRedmineにアクセスできるようになる。 +* 少し待つと、ブラウザから http://localhost:[.devcontainer/.envで指定したAPP_PORT] でRedmineにアクセスできるようになる。 -スクリーンショット 2022-07-31 12 42 01 +Railsアプリケーションを起動できた画面 * テストの実行 ```bash -$ bundle exec rake test RAILS_ENV=test +bundle exec rake test RAILS_ENV=test ``` ### おまけ @@ -107,7 +111,7 @@ $ bundle exec rake test RAILS_ENV=test #### 2. Redmineから送信されるメールの内容をチェック -http://localhost:[.envで指定したMAILCATCHER_PORT] でにアクセスするとメールキャッチャーを開ける +http://localhost:[.devcontainer/.envで指定したMAILCATCHER_PORT] でにアクセスするとメールキャッチャーを開ける #### 3. Ruby3.0系以外のバージョンで動作検証やテストをしたい @@ -133,7 +137,7 @@ index 1a1e0cb4a..fedbe7d15 100644 - + options[:browser] = :remote + Capybara.server_host = 'app' -+ Capybara.server_port = <.envのAPP_PORT(デフォルト8000)に入れた値に書き換える> ++ Capybara.server_port = <.devcontainer/.envのAPP_PORT(デフォルト8000)に入れた値に書き換える> driven_by( :selenium, using: :chrome, screen_size: [1024, 900], options: options From 93f0915b9e54470576e51c2db2180006736cc8f1 Mon Sep 17 00:00:00 2001 From: Mizuki Ishikawa Date: Fri, 5 Aug 2022 11:14:34 +0900 Subject: [PATCH 7/8] =?UTF-8?q?Update=20Dockerfile=E3=81=A7ADD=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=9F=E3=81=93=E3=81=A8?= =?UTF-8?q?=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=E6=A9=9F=E8=83=BD=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/docker-compose.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 5bb61a390b..95615f853a 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -50,12 +50,6 @@ services: command: sleep infinity volumes: - ..:/workspace:cached - # 全体を同期すると速度が遅くなるため、上の1行を消して下の4行のコメントアウトを外してもいい - # その場合、同期場所がgitの履歴とtmpディレクトリのみになるため、git commitしたもの + shareディレクトリに入れたファイル以外はコンテナのキャッシュが消えたときに消える - # - ../.git:/workspace/.git - # - ../tmp:/workspace/tmp - # - ../public:/workspace/public - # - ../plugins:/workspace/plugins # For selenium test # chrome: From b9f21122fb66229771b41dc45b9e09ee23b8e133 Mon Sep 17 00:00:00 2001 From: Mizuki Ishikawa Date: Mon, 8 Aug 2022 09:39:53 +0900 Subject: [PATCH 8/8] Update docker-compose.yml Resolve chrome container crashing issue --- .devcontainer/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 95615f853a..bd519dda28 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -58,6 +58,7 @@ services: # ports: # - $SELENIUM_PORT_1:4444 # - $SELENIUM_PORT_2:5900 + # shm_size: 2gb smtp: image: schickling/mailcatcher