Docker Compose で Accel Platform 環境を構築する。

この CookBook では、Docker Compose を利用して Accel Platform 環境を構築する手順について紹介しています。
この CookBook では、以下の記事で作成した Docker イメージを利用します。

レシピ

  1. docker-compose.yml ファイルを作成する
  2. docker compose を実行する。
  3. war ファイルを作成する
  4. war ファイルをデプロイする

1. docker-compose.yml ファイルを作成する

以下のような docker-compose.yml ファイルを作成します。

docker-compose.yml
version: '3'
services:
  db:
    image: mypostgresql:9.6
    tty: true
  cassandra:
    image: mycassandra:1.1.12
  solr:
    image: mysolr
  resin:
    image: myresin:4.0.56
    ports:
      - "2222:22"
      - "8080:8080"
      - "8443:8443"
    depends_on:
      - "db"
      - "cassandra"
      - "solr"

上記 CookBook で作成した以下のイメージを利用しています。

  • DB
    • mypostgresql:9.6
  • Cassandra
    • mycassandra:1.1.12
  • Solr
    • mysolr
  • Resin
    • myresin:4.0.56

Resin の Docker コンテナのみ、ssh(2222 ポート)、HTTP(8080 ポート)、HTTPS(8443 ポート)をポートフォワードしています。
HTTPS は resin-admin から war ファイルをデプロイするために開放しています。

2. docker compose を実行する。

以下のコマンドで実行します。

docker-compose up

上記の docker-compose.yml ファイルがあるディレクトリから実行してください。

docker-compose.yml ファイル内の Services に指定した名称で DNS が利用可能です。
例えば、Resin の Docker コンテナ内からは「db」、「cassandra」、「solr」という名称で対応するコンテナのプライベート IP が解決できます。

3. war ファイルを作成する

IM-Juggling プロジェクト配下の各ファイルを以下のように変更します。

Cassandra, Solr, PostgreSQL への接続先をそれぞれ「cassandra」、「solr」、「db」に変更します。
Resin コンテナ内からは「db」、「cassandra」、「solr」という名称で対応するコンテナのプライベート IP が解決できるため、このように設定します。

conf/cassandra-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<cassandra-config xmlns="http://www.intra-mart.jp/imbox/cassandra-config"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.intra-mart.jp/imbox/cassandra-config ../schema/cassandra-config.xsd ">

    <cluster-name>Test Cluster</cluster-name>
    <replication-factor>1</replication-factor>
    <keyspace>default</keyspace>
    <authentication enabled="false">
        <username>admin</username>
        <password>admin_pwd</password>
    </authentication>
    <hosts>
        <host>cassandra:9160</host>
    </hosts>
</cassandra-config>
conf/solr-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<solr-config xmlns="http://intra-mart.co.jp/system/solr/config/solr-config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://intra-mart.co.jp/system/solr/config/solr-config ../schema/solr-config.xsd ">

    <group name="default">
        <searcher>
            <method>POST</method>
            <distribution-policy>FIRST</distribution-policy>
            <servers>
                <url>http://solr:8983/solr/default</url>
            </servers>
        </searcher>
        <indexer>
            <distribution-policy>IDHASH</distribution-policy>
            <servers>
                <url>http://solr:8983/solr/default</url>
            </servers>
        </indexer>
        <extractor ref="im_default" />
    </group>

</solr-config>
resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin">
    <character-encoding>UTF-8</character-encoding>

    <log-handler name="" class="jp.co.intra_mart.common.platform.log.handler.JDKLoggingOverIntramartLoggerHandler"/>
    <logger name="debug.com.sun.portal" level="warning" />

        <!-- im_service(im_asynchronous) -->
        <resource jndi-name="jca/work" type="jp.co.intra_mart.system.asynchronous.impl.executor.work.resin.ResinResourceAdapter" />
        <jsp>
                <recycle-tags>false</recycle-tags>
        </jsp>
        <database jndi-name="jdbc/default">
                <driver>
                        <type>org.postgresql.Driver</type>
                        <url>jdbc:postgresql://db:5432/iap_db</url>
                        <user>imart</user>
                        <password>imart</password>
                        <init-param>
                                <param-name>preparedStatementCacheQueries</param-name>
                                <param-value>0</param-value>
                        </init-param>
                </driver>
                <max-connections>20</max-connections>
                <prepared-statement-cache-size>0</prepared-statement-cache-size>
        </database>
        <session-config>
            <reuse-session-id>false</reuse-session-id>
                <session-timeout>30</session-timeout>
        </session-config>

        <mime-mapping extension=".json" mime-type="application/json"/>
</web-app>

4. war ファイルをデプロイする

https://localhost:8443/resin-admin より、作成した war ファイルをデプロイし、テナントセットアップを行います。
localhost は docker-compose を実行しているマシンの IP アドレスに置き換えてください。

このように、Docker Compose を利用することで瞬時に Accel Platform 環境を構築することができます。
是非ご活用ください。