google広告

リサーチパネル

AWS WorkSpaces で急造テレワーク環境! 続き6(redmine設定編)

2021年2月25日

ファイルの共有としてowncloud、リアルタイムのコミニケーションツールとしてrocket.chatを整備しました。
今回はタスクや進捗や各種報告管理のためにプロジェクト管理ツールのredmineを整備します。
redmineは開発プロジェクト管理としてチケット駆動管理とガントチャートでスケジュールを管理するイメージが強いですが、
あえてチケットをガントチャートを無視してチケットに特化したりするとロケーションがバラバラでも日々のタスクの発生率、
それにどれだけの工数を使っているかなどフォーカス次第で日報・週報の変わりや、分析にも使えます。

正直、顔を合わせない仕事のスタイルになるほどエクセル管理やメールにベタやテキストベースの「中身のない出されて嬉しい」
報告書というのは今まで以上に意味がなくってくると思ってます。
個人的にはgoogleドライブとgoogleスプレッドシート使えるならそっちでやればいいんじゃないとも思ってます。
絶対エクセルマンでも理解できて、共有編集できるんますからそこまで人数多くなければ便利なんですけど。
残念ながら、業務でgoogleサービスダメ絶対文化でなかなかできないんですよね。

redmineは使うのに慣れがいるので、最初はとっつきずらいかもしれませんがメールでエクセル添付の連絡網形式でリレー編集とか不毛だろ?
と感じる感性があるならトライしていただくことを薦めます。

redmine用データベースの準備

コンテナでredmineを扱う場合は対応しているMySQLMariaDB、PostgreSQLのコンテナの設定がセットを利用するケースが多いです。
redmineのコンテナを単体で使う場合はsqliteが利用されます。
でもAWS上で使うので、せっかくなのでowncloudと同様に今回はRDSを利用したいと思います。
RDSの作成は以下の「1.owncloud用 Amazon RDS postgreSQLの作成」を参照してください。利用するバージョンは10.x系で作成します。
※2020年9月12日現在で10.13-R1が最新です。
ALBも2.owncloudコンテナの作成を参照し作成してください。指定するポートは後述のdocker-compose.ymlの portのホスト側ポートを指定してください。

RDSを作成したら、以下の情報を控えておきましょう
 1. RDSのエンドポイント
 2.RDSのマスターユーザ/マスターユーザパスワード
 3. RDSの初期DB

作成したディレクトリ /volume/redmine に移動しdocker-compose.ymlを作成します
volumes: の#(コメントアウト部分)仕込みです。
とりあえずは
 /volume/redmine_pub/data:/usr/src/data
ここだけ有効化しておきます。

version: '3.1'

services:

#  postgresql:
#   image: postgres:10.11
#   restart: always
#   environment:
#     POSTGRES_USER: 【RDSのマスターユーザ】
#     POSTGRES_PASSWORD: 【RDSのマスターユーザパスワード】
#     POSTGRES_DB: 【RDSの初期データベース名】

  redmine:
   image: redmine:4.1.1
#   depends_on:
#   - postgresql
   restart: always
   ports:
   - 10083:3000
   environment:
     REDMINE_DB_POSTGRE: 【RDSのエンドポイント】
     REDMINE_DB_DATABASE: 【RDSの初期データベース名】
     REDMINE_DB_USERNAME: 【RDSのマスターユーザ】
     REDMINE_DB_PASSWORD: 【RDSの初期データベース名】
   volumes:
    - /volume/redmine/data:/usr/src/data
#    - /volume/redmine/plugin:/usr/src/redmine/plugins
#    - /volume/redmine/config:/usr/src/redmine/config
#    - /volume/redmine/themes:/usr/src/redmine/public/themes

docker-compose.ymlを作成したら、/volume/redmine でdocker-compose up -dを実行します。
ここで、公式のredmineイメージを使ってコンテナではにDBを利用をすると仕込みが必要になってきます。
dockerの思想からすると、本来はdockerイメージカスタマイズするか、自前で作れよが正解なんですけどまあライトに行くことにします。

以下のコマンドでdockerイメージにコンソール接続できます。

docket-compose exec redmine /bin/bash

以下のようにDatabase接続の設定を確認します。

cat /usr/src/redmine/config/database.yml

production:
  adapter: "sqlite3"
  host: "localhost"
  username: "redmine"
  password: "Ks+001265"
  database: "redmine_production"
  encoding: "utf8"

うーーん、docker-compose.ymlのREDMINE_DB_POSTGREが効いてないのよね・・・
このままだとsqliteで作られてしまいます。
またプラグインやテーマ、設定定義もコンテナ腹もちになるので迂闊に停止・起動すると設定飛びます。

なので、とりあえずホスト側へのお引っ越しを行います。
まずは事前にホストとコンテナのマッピング領域に必要なディレクトリをコピーです。

# cd /usr/src/data
# cp -pr /usr/src/redmine/plugins /usr/src/data/.
# cp -pr /usr/src/redmine/public/themes /usr/src/data/.
# cp -pr /usr/src/redmine/config  /usr/src/data/.
#  ls -l
total 0
drwxr-xr-x 5 redmine redmine 312 Sep 12 15:52 config
drwxrwxr-x 2 redmine redmine  20 Apr  6 17:00 plugins
drwxrwxr-x 4 redmine redmine  52 Apr  6 17:00 themes
# exit

exitで一旦、コンテナから抜けたらホスト側のディレクトリを確認します。

# cd /volume/redmine/data
# ls -l 
 ls -l
total 0
drwxr-xr-x 5 libstoragemgmt input 312 Sep 13 01:15 config
drwxrwxr-x 2 libstoragemgmt input  20 Apr  7 02:00 plugins
drwxrwxr-x 4 libstoragemgmt input  52 Apr  7 02:00 themes

格納されたデータを/volume/redmine/ に移動します。

# sudo cp -pr /volume/redmine/data/config /volume/redmine/.
# sudo cp -pr /volume/redmine/data/plugins /volume/redmine/.
# sudo cp -pr /volume/redmine/data/themes /volume/redmine/.
# cd /volume/redmine/
# ls -l 
[ec2-user@ip-10-20-10-10 redmine]$ ls -l
total 4
drwxr-xr-x 5 libstoragemgmt input    312 Sep 13 01:15 config
drwxr-xr-x 5 root           root      49 Sep 13 01:16 data
-rw-rw-r-- 1 ec2-user       ec2-user 761 Sep 13 01:14 docker-compose.yml
drwxrwxr-x 2 libstoragemgmt input     20 Apr  7 02:00 plugins
drwxrwxr-x 4 libstoragemgmt input     52 Apr  7 02:00 themes

ここで一旦、コンテナを docker-compose stop で 停止します。
停止後、docker-compose.ymlのvolumes: 配下の#(コメントアウト)を外します。
その後、以下のようにdatabase.ymlを開き修正します。

sudo vi /volume/redmine/config/database.yml
production:
  adapter: "postgresql"
  host: "【RDSのエンドポイント】"
  username: "【RDSのマスターユーザネーム】"
  password: "【RDSのマスターユーザパスワード】"
  database: "【RDSの初期データベース名】"
  encoding: "utf8"

修正後再度、/volume/redmine/ で docker-compose up -d でコンテナを起動します。
起動後、ブラウザからredmineにアクセスしてください。 
特に設定画面もなく、ログイン画面が表示されます。初期状態であれば、以下でログインします。
初回はログイン時にパスワードの変更を求められるので適宜変更してください。
ユーザ:admin
パスワード:admin

ログイン後、管理>情報を確認してください
以下のようにEnviroment配下のDatabase adapterがPostgreSQLとなっていれば正しくRDSに接続ができているはずです。

うーん、心配だなぁ、ほんとか? という場合にはEC2から直接、RDSに接続して確認してください。

# psql -h 【RDSのエンドポイント】 -U 【RDSのマスターユーザ名】 -d 【RDSの初期データベース名】

パスワードを入力を入力を求められるので、マスターユーザのパスワードを投入してください。
RDSの接続後、 \d を入力し以下のように確認できればredmineのデータベースは正しく作成されています。

psql (9.2.24, server 10.13)
WARNING: psql version 9.2, server version 10.0.
         Some psql features might not work.
SSL connection (cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.

redmine_production=> 
redmine_production=> \d
                            List of relations
 Schema |                    Name                    |   Type   |  Owner  
--------+--------------------------------------------+----------+---------
 public | ar_internal_metadata                       | table    | redmine
 public | attachments                                | table    | redmine
 public | attachments_id_seq                         | sequence | redmine
 public | auth_sources                               | table    | redmine
 public | auth_sources_id_seq                        | sequence | redmine
 public | boards                                     | table    | redmine
 public | boards_id_seq                              | sequence | redmine
 public | changes                                    | table    | redmine
 public | changes_id_seq                             | sequence | redmine
 public | changeset_parents                          | table    | redmine
 public | changesets                                 | table    | redmine
 public | changesets_id_seq                          | sequence | redmine
 public | changesets_issues                          | table    | redmine
 public | comments                                   | table    | redmine
 public | comments_id_seq                            | sequence | redmine
 public | custom_field_enumerations                  | table    | redmine
 public | custom_field_enumerations_id_seq           | sequence | redmine
 public | custom_fields                              | table    | redmine
 public | custom_fields_id_seq                       | sequence | redmine
 public | custom_fields_projects                     | table    | redmine
 public | custom_fields_roles                        | table    | redmine
 public | custom_fields_trackers                     | table    | redmine
 public | custom_values                              | table    | redmine
 public | custom_values_id_seq                       | sequence | redmine
 public | documents                                  | table    | redmine
 public | documents_id_seq                           | sequence | redmine
 public | email_addresses                            | table    | redmine
 public | email_addresses_id_seq                     | sequence | redmine
 public | enabled_modules                            | table    | redmine
 public | enabled_modules_id_seq                     | sequence | redmine
 public | enumerations                               | table    | redmine
 public | enumerations_id_seq                        | sequence | redmine
 public | groups_users                               | table    | redmine
 public | import_items                               | table    | redmine
 public | import_items_id_seq                        | sequence | redmine
 public | imports                                    | table    | redmine
 public | imports_id_seq                             | sequence | redmine
 public | issue_categories                           | table    | redmine
 public | issue_categories_id_seq                    | sequence | redmine
 public | issue_relations                            | table    | redmine
 public | issue_relations_id_seq                     | sequence | redmine
 public | issue_statuses                             | table    | redmine
 public | issue_statuses_id_seq                      | sequence | redmine
 public | issues                                     | table    | redmine
 public | issues_id_seq                              | sequence | redmine
 public | journal_details                            | table    | redmine
 public | journal_details_id_seq                     | sequence | redmine
 public | journals                                   | table    | redmine
 public | journals_id_seq                            | sequence | redmine
 public | member_roles                               | table    | redmine
 public | member_roles_id_seq                        | sequence | redmine
 public | members                                    | table    | redmine
 public | members_id_seq                             | sequence | redmine
 public | messages                                   | table    | redmine
 public | messages_id_seq                            | sequence | redmine
 public | news                                       | table    | redmine
 public | news_id_seq                                | sequence | redmine
 public | open_id_authentication_associations        | table    | redmine
 public | open_id_authentication_associations_id_seq | sequence | redmine
 public | open_id_authentication_nonces              | table    | redmine
 public | open_id_authentication_nonces_id_seq       | sequence | redmine
 public | projects                                   | table    | redmine
 public | projects_id_seq                            | sequence | redmine
 public | projects_trackers                          | table    | redmine
 public | queries                                    | table    | redmine
 public | queries_id_seq                             | sequence | redmine
 public | queries_roles                              | table    | redmine
 public | repositories                               | table    | redmine
 public | repositories_id_seq                        | sequence | redmine
 public | roles                                      | table    | redmine
 public | roles_id_seq                               | sequence | redmine
 public | roles_managed_roles                        | table    | redmine
 public | schema_migrations                          | table    | redmine
 public | settings                                   | table    | redmine
 public | settings_id_seq                            | sequence | redmine
 public | time_entries                               | table    | redmine
 public | time_entries_id_seq                        | sequence | redmine
 public | tokens                                     | table    | redmine
 public | tokens_id_seq                              | sequence | redmine
 public | trackers                                   | table    | redmine
 public | trackers_id_seq                            | sequence | redmine
 public | user_preferences                           | table    | redmine
 public | user_preferences_id_seq                    | sequence | redmine
 public | users                                      | table    | redmine
 public | users_id_seq                               | sequence | redmine
 public | versions                                   | table    | redmine
 public | versions_id_seq                            | sequence | redmine
 public | watchers                                   | table    | redmine
 public | watchers_id_seq                            | sequence | redmine
 public | wiki_content_versions                      | table    | redmine
 public | wiki_content_versions_id_seq               | sequence | redmine
 public | wiki_contents                              | table    | redmine
 public | wiki_contents_id_seq                       | sequence | redmine
 public | wiki_pages                                 | table    | redmine
 public | wiki_pages_id_seq                          | sequence | redmine
 public | wiki_redirects                             | table    | redmine
 public | wiki_redirects_id_seq                      | sequence | redmine
 public | wikis                                      | table    | redmine
 public | wikis_id_seq                               | sequence | redmine
 public | workflows                                  | table    | redmine
 public | workflows_id_seq                           | sequence | redmine
(101 rows)

redmine_production=>

\q でログアウトできます。
これでコンテナのredmineとRDSの組み合わせのredmineが使用可能になります。