nablarch: nablarch-example-batchをdockerコンテナにする方法

## はじめに
nablarch-example-batchは、nablarchフレームワークのバッチアプリケーション実装例である。

ただし、nablarch-example-batchはdocker用のexampleを提供していない。
このページでは、dockerコンテナでnablarch-example-batchを動かす方法を説明する。


### 結局、どうやったらできるのか

以下の通り。`mvn package`コマンドは[nablarch-example-batch手順](https://github.com/nablarch/nablarch-example-batch)に従って事前に実行する前提とする。

```compose.yml
services:
  backend:
      build: .
```

```dockerfile:Dockerfile
# syntax=docker.io/docker/dockerfile:1
FROM amazoncorretto:8-alpine3.19-jre

WORKDIR /opt/app

# zipの中には、jarファイル(実行ファイル)とlib(ライブラリ)が存在する。
COPY ./target/application-5u24.zip /opt/app/application.zip
# ヒアドキュメントの利用はsyntaxコメントが必要。DockerfileはLF改行必須。
RUN  <<EOF
  unzip /opt/app/application.zip
  chmod 777 /opt/app/nablarch-example-batch-5u24.jar
  chmod 777 -R /opt/app/lib
EOF

# h2の仕様では、相対パスのみが使用される場合現在の作業ディレクトリが開始点として使用されます。
# tomcatコンテナイメージでは、デフォルトの作業ディレクトリは/usr/local/tomcatです。
# env.properties で nablarch.db.url=jdbc:h2:./h2/db/rest_example を設定する場合、/usr/local/tomcat/h2/db/が正しい配置場所です。
COPY ./h2/db/nablarch_example.mv.db /opt/app/h2/db/

# fmtファイルとimputファイルを各ディレクトリに配置する。
COPY ./src/main/format/*.fmt /opt/app/src/main/format/
COPY ./work/input/*.csv /opt/app/work/input/

# この設定がないと、日本語のファイルを読み込めない場合がある。
ENV LANG=ja_JP.UTF-8

# exampleの手順とは、実行時引数の渡し方が違うので注意。
ENTRYPOINT ["/bin/sh", "-c", "java -jar /opt/app/nablarch-example-batch-5u24.jar -exec.mainClass 'nablarch.fw.launcher.Main' -requestPath 'ImportZipCodeFileDataFormatAction/ImportZipCodeFile' -diConfig 'classpath:import-zip-code-file-data-format.xml' -userId '105'"]
```

### 実行手順

```bash
docker compose up -d
```

### 実行結果

```text:stdout.log
2024-05-06 12:30:14 2024-05-06 03:30:14.704 -INFO- null [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] initialized.
2024-05-06 12:30:14     LOGGER = [DEV] NAME REGEX = [DEV] LEVEL = [INFO]
2024-05-06 12:30:14     LOGGER = [PER] NAME REGEX = [PERFORMANCE] LEVEL = [INFO]
2024-05-06 12:30:14     LOGGER = [SQL] NAME REGEX = [SQL] LEVEL = [INFO]
2024-05-06 12:30:14     LOGGER = [ROO] NAME REGEX = [.*] LEVEL = [INFO]
2024-05-06 12:30:14 2024-05-06 03:30:14.712 -INFO- nablarch.fw.launcher.Main [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] @@@@ BEGIN @@@@
2024-05-06 12:30:14     command line options = {
2024-05-06 12:30:14             exec.mainClass = [nablarch.fw.launcher.Main]
2024-05-06 12:30:14             userId = [105]
2024-05-06 12:30:14             requestPath = [ImportZipCodeFileDataFormatAction/ImportZipCodeFile]
2024-05-06 12:30:14             diConfig = [classpath:import-zip-code-file-data-format.xml]
2024-05-06 12:30:14     }
2024-05-06 12:30:14     command line arguments = {
2024-05-06 12:30:14     }
2024-05-06 12:30:14 2024-05-06 03:30:14.857 -WARN- nablarch.core.repository.di.config.xml.XmlComponentDefinitionLoader [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] override component classname was not matched.  replace all component configuration.  component name = commitLogger, defined component definition classname = nablarch.core.log.app.BasicCommitLogger, override component definition classname = nablarch.core.log.app.CompositeCommitLogger
2024-05-06 12:30:15 5 06, 2024 3:30:15 午前 io.micrometer.core.instrument.push.PushMeterRegistry start
2024-05-06 12:30:15 情報: publishing metrics for OtlpMeterRegistry every 2s
2024-05-06 12:30:15 2024-05-06 03:30:15.158 -INFO- com.zaxxer.hikari.HikariDataSource [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] HikariPool-1 - Starting...
2024-05-06 12:30:15 2024-05-06 03:30:15.458 -INFO- com.zaxxer.hikari.HikariDataSource [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] HikariPool-1 - Start completed.
2024-05-06 12:30:15 2024-05-06 03:30:15.486 -INFO- nablarch.fw.launcher.Main [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] @@@@ APPLICATION SETTINGS @@@@
2024-05-06 12:30:15     system settings = {
2024-05-06 12:30:15     }
2024-05-06 12:30:15     business date = [2015-04-15]
2024-05-06 12:30:15 5 06, 2024 3:30:15 午前 org.hibernate.validator.internal.util.Version <clinit>
2024-05-06 12:30:15 INFO: HV000001: Hibernate Validator 5.3.6.Final
2024-05-06 12:30:15 2024-05-06 03:30:15.903 -WARN- com.nablarch.example.app.batch.action.ImportZipCodeFileDataFormatAction [202405060330158900064] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [ImportZipCodeFileDataFormatAction/ImportZipCodeFile] usr_id = [105] validation error has occurred. , error prop=[zipCode7digit],error message=[7文字で入力してください。], line number=[63]
2024-05-06 12:30:15 2024-05-06 03:30:15.906 -INFO- nablarch.fw.action.BatchActionBase [202405060330159060066] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [ImportZipCodeFileDataFormatAction/ImportZipCodeFile] usr_id = [105] 登録完了件数:[62]
2024-05-06 12:30:15 2024-05-06 03:30:15.907 -INFO- nablarch.fw.handler.MultiThreadExecutionHandler [202405060330154870001] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [ImportZipCodeFileDataFormatAction/ImportZipCodeFile] usr_id = [105] 
2024-05-06 12:30:15 Thread Status: normal end.
2024-05-06 12:30:15 Thread Result:[200 Success] The request has succeeded.
2024-05-06 12:30:15 2024-05-06 03:30:15.907 -INFO- nablarch.core.log.app.BasicCommitLogger [202405060330154870001] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [ImportZipCodeFileDataFormatAction/ImportZipCodeFile] usr_id = [105] TOTAL COMMIT COUNT = [65]
2024-05-06 12:30:15 2024-05-06 03:30:15.994 -INFO- nablarch.fw.launcher.Main [null] boot_proc = [] proc_sys = [nablarch-example-batch] req_id = [null] usr_id = [null] @@@@ END @@@@ exit code = [0] execute time(ms) = [1282]
```