---
title: Cloud FoundryのJava BuildpackでAmazon Correttoを使う
tags: ["Cloud Foundry", "Java", "Amazon Corretto"]
categories: ["Dev", "PaaS", "CloudFoundry"]
date: 2019-02-08T06:08:25Z
updated: 2019-08-13T17:29:47Z
---

[Amazon Corretto 8](https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)がGAになったので、
Cloud FoundryのJava Buildpackで使ってみます。


> 2019-08-13 1.8.0_222, 11.0.4_11を追加<br>
> 2019-02-16 [Amazon Corretto 11](https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html)に対応しました。

Java Buildpackで用意されているOpenJDKではなく、任意のJDKを使う場合は、次のような`index.yml`を作成してHTTPサーバーでホストして、URLを指定すれば良いです。

``` yaml
1.8.0_202: "https://d2znqt9b1bc64u.cloudfront.net/amazon-corretto-8.202.08.2-linux-x64.tar.gz"
1.8.0_222: "https://d3pxv6yz143wms.cloudfront.net/8.222.10.1/amazon-corretto-8.222.10.1-linux-x64.tar.gz"
11.0.2_09: "https://d3pxv6yz143wms.cloudfront.net/11.0.2.9.3/amazon-corretto-11.0.2.9.3-linux-x64.tar.gz"
11.0.4_11: "https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/amazon-corretto-11.0.4.11.1-linux-x64.tar.gz"
```

[https://raw.githubusercontent.com/making/amazon-corretto-buildpack/master/index.yml](https://raw.githubusercontent.com/making/amazon-corretto-buildpack/master/index.yml)に置いておきました。

ちなみにデフォルトで利用可能なJDK一覧は[https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/index.yml](https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/index.yml)です。

このJDKリストを指定するには`manifest.yml`に設定します。

``` yml
applications:
- name: demo-correto
  path: target/demo-corretto-0.0.1-SNAPSHOT.jar
  buildpacks:
  - https://github.com/cloudfoundry/java-buildpack.git#v4.17.2
  env:
    JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { repository_root: "https://raw.githubusercontent.com/making/amazon-corretto-buildpack/master" } }'
```

これで`cf push`すれば、Staging中に次のようなログが出力されます。amazon-correttoがダウンロードされていることがわかります。

サンプルアプリは[こちら](https://github.com/making/demo-corretto)です。

```
アプリ demo-correto を作成しています...
経路をマップしています...
ローカル・ファイルをリモート・キャッシュと比較しています...
Packaging files to upload...
ファイルをアップロードしています...
 255.97 KiB / 255.97 KiB [=====================================================================================================================================================================================================================] 100.00% 1s

API がファイルの処理を完了するのを待機しています...

アプリをステージングし、ログをトレースしています...
   Cell d44dd97b-dfa4-45cd-91c9-40edcc692c5b creating container for instance 6dc11676-509f-446c-b580-25de3e399a6c
   Cell d44dd97b-dfa4-45cd-91c9-40edcc692c5b successfully created container for instance 6dc11676-509f-446c-b580-25de3e399a6c
   Downloading app package...
   Downloaded app package (15.4M)
   -----> Java Buildpack v4.17.2 | https://github.com/cloudfoundry/java-buildpack.git#6ce39cf
   -----> Downloading Jvmkill Agent 1.16.0_RELEASE from https://java-buildpack.cloudfoundry.org/jvmkill/bionic/x86_64/jvmkill-1.16.0_RELEASE.so (0.1s)
   -----> Downloading Open Jdk JRE 1.8.0_202 from https://d2znqt9b1bc64u.cloudfront.net/amazon-corretto-8.202.08.2-linux-x64.tar.gz (4.4s)
          Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (2.0s)
          JVM DNS caching disabled in lieu of BOSH DNS caching
   -----> Downloading Open JDK Like Memory Calculator 3.13.0_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/bionic/x86_64/memory-calculator-3.13.0_RELEASE.tar.gz (0.0s)
          Loaded Classes: 16451, Threads: 250
   -----> Downloading Client Certificate Mapper 1.8.0_RELEASE from https://java-buildpack.cloudfoundry.org/client-certificate-mapper/client-certificate-mapper-1.8.0_RELEASE.jar (0.0s)
   -----> Downloading Container Security Provider 1.16.0_RELEASE from https://java-buildpack.cloudfoundry.org/container-security-provider/container-security-provider-1.16.0_RELEASE.jar (0.0s)
   -----> Downloading Spring Auto Reconfiguration 2.5.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-2.5.0_RELEASE.jar (0.0s)
   Exit status 0
   Uploading droplet, build artifacts cache...
   Uploading droplet...
   Uploading build artifacts cache...
   Uploaded build artifacts cache (114.5M)
   Uploaded droplet (130.2M)
   Uploading complete

アプリが開始するのを待機しています...
   Cell d44dd97b-dfa4-45cd-91c9-40edcc692c5b stopping instance 6dc11676-509f-446c-b580-25de3e399a6c
   Cell d44dd97b-dfa4-45cd-91c9-40edcc692c5b destroying container for instance 6dc11676-509f-446c-b580-25de3e399a6c
```

System Propertiesをみると`java.vm.vendor`が`Amazon.com Inc.`になっているのがわかります。

![image](https://user-images.githubusercontent.com/106908/52461620-303daf00-2bb3-11e9-896e-20a8961876ac.png)

Correto 11を使いたい場合は`version`を指定します。Java Buildpack 4.17時点ではデフォルトは8です。

``` yml
applications:
- name: demo-correto
  path: target/demo-corretto-0.0.1-SNAPSHOT.jar
  buildpacks:
  - https://github.com/cloudfoundry/java-buildpack.git#v4.17.2
  env:
    JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+, repository_root: "https://raw.githubusercontent.com/making/amazon-corretto-buildpack/master" } }'
```

こちらで`cf push`するとCorreto 11がダウンロードされます。

```
   Cell a72ed0eb-f16e-4edb-a2e0-17ee5ac2e0a4 creating container for instance 9533720e-6818-4cb6-be9f-19d4b7a3b525
   Cell a72ed0eb-f16e-4edb-a2e0-17ee5ac2e0a4 successfully created container for instance 9533720e-6818-4cb6-be9f-19d4b7a3b525
   Downloading app package...
   Downloading build artifacts cache...
   Downloaded app package (15.4M)
   Downloaded build artifacts cache (114.5M)
   -----> Java Buildpack v4.17.2 | https://github.com/cloudfoundry/java-buildpack.git#6ce39cf
   -----> Downloading Jvmkill Agent 1.16.0_RELEASE from https://java-buildpack.cloudfoundry.org/jvmkill/bionic/x86_64/jvmkill-1.16.0_RELEASE.so (found in cache)
   -----> Downloading Open Jdk JRE 11.0.2_09 from https://d2jnoze5tfhthg.cloudfront.net/amazon-corretto-11.0.2.9.1-linux-x64.tar.gz (6.8s)
          Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (3.3s)
          JVM DNS caching disabled in lieu of BOSH DNS caching
   -----> Downloading Open JDK Like Memory Calculator 3.13.0_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/bionic/x86_64/memory-calculator-3.13.0_RELEASE.tar.gz (found in cache)
          Loaded Classes: 18751, Threads: 250
   -----> Downloading Client Certificate Mapper 1.8.0_RELEASE from https://java-buildpack.cloudfoundry.org/client-certificate-mapper/client-certificate-mapper-1.8.0_RELEASE.jar (found in cache)
   -----> Downloading Container Security Provider 1.16.0_RELEASE from https://java-buildpack.cloudfoundry.org/container-security-provider/container-security-provider-1.16.0_RELEASE.jar (found in cache)
   -----> Downloading Spring Auto Reconfiguration 2.5.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-2.5.0_RELEASE.jar (found in cache)
```

---


Buildpackを使っている限り、Cloud Foundry BuildのOpenJDKを使うので良いと思いますが、
開発もCFもCorrettoで統一したいというレアな要望があればどうぞ。
