【Tekton】Cloud Native Buildpacksの-cache-dirオプションを使ってみる

2022.08.06
2024.03.24
CI/CD
Cloud Native BuildpacksGradleJavaTekton

はじめに

TektonでCloud Native Buildpacksを使ってビルドするときに、-cache-dirを使ってキャッシュを利用してみたいと思います。

TektonでCloud Native Buildpacksを使ってビルドする方法については下記を参照してください。

【Tekton】Cloud Native Buildpacksでビルドする

【Tekton】Cloud Native Buildpacksでビルドする

はじめに **TektonでCloud Native Buildpacksを使ってビルド**をし

-cache-dirオプション

Cloud Native Buildpacksの/cnb/lifecycle/creatorコマンドを使う場合、-cache-dirでキャッシュを格納するディレクトリを指定することができます。

spec/platform.md at platform/v0.9 · buildpacks/spec

spec/platform.md at platform/v0.9 · buildpacks/spec

Specification for Cloud Native Buildpacks. Contribute to buildpacks/spec development by creating an account on GitHub.

いつ使うデータがキャッシュされているか

この-cache-dirに格納されているデータがいつ使われているかですが、BuildpacksのドキュメントやTektonのcatalogには下記のように記載されています。

Directory where cache is stored (OPTIONAL)

https://buildpacks.io/docs/for-platform-operators/how-to/integrate-ci/tekton/

Directory where cache is stored (when no cache image is provided).

catalog/task/buildpacks/0.5/buildpacks.yaml at main · tektoncd/catalog

catalog/task/buildpacks/0.5/buildpacks.yaml at main · tektoncd/catalog

Catalog of shared Tasks and Pipelines. Contribute to tektoncd/catalog development by creating an account on GitHub.

ここを読む限りcreatorで使うデータをキャッシュしているように読み取れます。しかし、creatorが実行するanalyzerdetectorrestorerbuilderexporterのオプションを見ると、-cache-dirオプションはrestorerexporterにしかありません。

【Cloud Native Buildpacks】Lifecycleとは

【Cloud Native Buildpacks】Lifecycleとは

はじめに Cloud Native Buildpacksのコンポーネントから、**Lifecyc

つまり、buildpacksでビルドしているときに使う依存関係をキャッシュしているわけではなさそうです。

このあと、実際に動かして確認してみますが、動かしてみた感じ構築したlayerをキャッシュしているようです。

Gradleアプリをビルドしてみる

Paketo Buildpacksが用意しているGradleのサンプルアプリで、実際に-cache-dirを使ってビルドしてみます。

samples/java/gradle at main · paketo-buildpacks/samples

samples/java/gradle at main · paketo-buildpacks/samples

A collection of samples. Contribute to paketo-buildpacks/samples development by creating an account on GitHub.

用意するファイルは下記の通りです。

1.
2├── buildpacks.yaml
3├── git-clone.yaml
4├── pipeline.yaml
5├── pipelinerun1.yaml
6├── pipelinerun2.yaml
7├── pod.yaml
8├── serviceaccount.yaml
9└── volume.yaml

Secretの作成

Docker Hubにプッシュするときに必要な認証情報を持つSecretを作成します。

1kubectl create secret docker-registry docker-registry \
2                    --docker-server=https://index.docker.io/v1/ \
3                    --docker-username=<DockerHubのアカウント名> \
4                    --docker-password=<DockerHubのパスワード> \
5                    --docker-email=<DockerHubのメールアドレス>

ServiceAccontの作成

先ほどのSecretを利用するServiceAccountを作成します(serviceaccount.yaml)。

1apiVersion: v1
2kind: ServiceAccount
3metadata:
4  name: buildpacks-service-account
5secrets:
6- name: docker-user-pass
1kubectl apply -f serviceaccount.yaml

PVとPVCの作成

キャッシュとアプリのソースコードを配置するworkspaceのためのPersistentVolumeを作成します(volume.yaml)。

1apiVersion: v1
2kind: PersistentVolume
3metadata:
4  name: buildpacks-source-pv
5spec:
6  capacity:
7    storage: 500Mi
8  accessModes:
9  - ReadWriteOnce
10  hostPath:
11    path: /tmp
12    type: Directory
13---
14apiVersion: v1
15kind: PersistentVolumeClaim
16metadata:
17  name: buildpacks-source-pvc
18spec:
19  accessModes:
20  - ReadWriteOnce
21  resources:
22    requests:
23      storage: 500Mi
1kubectl apply -f volume.yaml

git-clone Taskの作成

git-clone TaskはCatalogから下記を利用します。

catalog/task/git-clone/0.7/git-clone.yaml at main · tektoncd/catalog

catalog/task/git-clone/0.7/git-clone.yaml at main · tektoncd/catalog

Catalog of shared Tasks and Pipelines. Contribute to tektoncd/catalog development by creating an account on GitHub.

1kubectl apply -f git-clone.yaml

buildpacks Taskの作成

buildpacks TaskはCatalogから下記を利用します。

catalog/task/buildpacks/0.5/buildpacks.yaml at main · tektoncd/catalog

catalog/task/buildpacks/0.5/buildpacks.yaml at main · tektoncd/catalog

Catalog of shared Tasks and Pipelines. Contribute to tektoncd/catalog development by creating an account on GitHub.

1kubectl apply -f buildpacks.yaml

Pipelineの作成

Pipelineを作成します(pipeline.yaml)。

git-clone Taskでソースコードをクローンし、buildpacks Taskでビルドし、最後に結果を表示するPipelineになります。

buildpacks Taskにcacheというworkspaceをわたすことで-cache-dirが使えます。

1apiVersion: tekton.dev/v1beta1
2kind: Pipeline
3metadata:
4  name: buildpacks-pipeline
5spec:
6  params:
7  - name: image
8    type: string
9    description: image URL to push
10  workspaces:
11  - name: source-workspace
12  - name: cache-workspace # -cache-dir用のworkspace
13  tasks:
14  - name: fetch-repository
15    taskRef:
16      name: git-clone
17    workspaces:
18    - name: output
19      workspace: source-workspace
20    params:
21    - name: url
22      value: https://github.com/paketo-buildpacks/samples
23  - name: build
24    taskRef:
25      name: buildpacks
26    runAfter:
27    - fetch-repository
28    workspaces:
29    - name: source
30      workspace: source-workspace
31    - name: cache # -cache-dir用のworkspace
32      workspace: cache-workspace
33    params:
34    - name: APP_IMAGE
35      value: "$(params.image)"
36    - name: SOURCE_SUBPATH
37      value: "java/gradle"
38    - name: BUILDER_IMAGE
39      value: paketobuildpacks/builder:base
40    - name: SKIP_RESTORE
41      value: "false"
42  - name: display-results
43    runAfter:
44    - build
45    taskSpec:
46      steps:
47      - name: print
48        image: docker.io/library/bash:5.1.4@sha256:b208215a4655538be652b2769d82e576bc4d0a2bb132144c060efc5be8c3f5d6
49        script: |
50          #!/usr/bin/env bash
51          set -e
52          echo "Digest of created app image: $(params.DIGEST)"
53      params:
54      - name: DIGEST
55    params:
56    - name: DIGEST
57      value: $(tasks.build.results.APP_IMAGE_DIGEST)
1kubectl apply -f pipeline.yaml

初回のビルド

PipelineRun(pipelinerun1.yaml)で初回のビルドをします。

1apiVersion: tekton.dev/v1beta1
2kind: PipelineRun
3metadata:
4  name: buildpacks-pipeline-run1
5spec:
6  serviceAccountName: buildpacks-service-account
7  pipelineRef:
8    name: buildpacks-pipeline
9  workspaces:
10  - name: source-workspace
11    subPath: source
12    persistentVolumeClaim:
13      claimName: buildpacks-source-pvc
14  - name: cache-workspace # -cache-dir用のworkspace
15    subPath: cache
16    persistentVolumeClaim:
17      claimName: buildpacks-source-pvc
18  params:
19  - name: image
20    value: monda00/sample-gradle:v1
1kubectl apply -f pipelinerun1.yaml

ログを見てみると、JDKやJREなどビルドに必要な依存関係をダウンロードしていることがわかります。

Contributing to layerとなっているので、それぞれでlayerを作成しているのが確認できます。

1❯ tkn pr logs buildpacks-pipeline-run1
2
3...
4
5[build : create] ===> ANALYZING
6[build : create] Previous image with name "monda00/sample-gradle:v1" not found
7[build : create] ===> RESTORING
8[build : create] ===> BUILDING
9[build : create]
10[build : create] Paketo CA Certificates Buildpack 3.2.5
11[build : create]   https://github.com/paketo-buildpacks/ca-certificates
12[build : create]   Launch Helper: Contributing to layer
13[build : create]     Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
14[build : create]
15[build : create] Paketo BellSoft Liberica Buildpack 9.4.1
16[build : create]   https://github.com/paketo-buildpacks/bellsoft-liberica
17[build : create]   Build Configuration:
18[build : create]     $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
19[build : create]     $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
20[build : create]     $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
21[build : create]     $BP_JVM_VERSION              11                                                           the Java version
22[build : create]   Launch Configuration:
23[build : create]     $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
24[build : create]     $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
25[build : create]     $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
26[build : create]     $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
27[build : create]     $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
28[build : create]     $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
29[build : create]     $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
30[build : create]     $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
31[build : create]     $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
32[build : create]     $BPL_JMX_PORT                5000                                                         configure the JMX port
33[build : create]     $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
34[build : create]     $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
35[build : create]     $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
36[build : create]     $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
37[build : create]     Using buildpack default Java version 11
38[build : create]   BellSoft Liberica JDK 11.0.16: Contributing to layer
39[build : create]     Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16+8/bellsoft-jdk11.0.16+8-linux-amd64.tar.gz
40[build : create]     Verifying checksum
41[build : create]     Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jdk
42[build : create]     Adding 127 container CA certificates to JVM truststore
43[build : create]     Writing env.build/JAVA_HOME.override
44[build : create]     Writing env.build/JDK_HOME.override
45[build : create]   BellSoft Liberica JRE 11.0.16: Contributing to layer
46[build : create]     Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16+8/bellsoft-jre11.0.16+8-linux-amd64.tar.gz
47[build : create]     Verifying checksum
48
49...
50
51[build : create] ===> EXPORTING
52[build : create] Adding layer 'paketo-buildpacks/ca-certificates:helper'
53[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
54[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
55[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
56[build : create] Adding layer 'paketo-buildpacks/executable-jar:classpath'
57[build : create] Adding layer 'paketo-buildpacks/spring-boot:helper'
58[build : create] Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
59[build : create] Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
60[build : create] Adding 5/5 app layer(s)
61[build : create] Adding layer 'launcher'
62[build : create] Adding layer 'config'
63[build : create] Adding layer 'process-types'
64[build : create] Adding label 'io.buildpacks.lifecycle.metadata'
65[build : create] Adding label 'io.buildpacks.build.metadata'
66[build : create] Adding label 'io.buildpacks.project.metadata'
67[build : create] Adding label 'org.springframework.boot.version'
68[build : create] Setting default process type 'web'
69[build : create] Saving monda00/sample-gradle:v1...
70[build : create] *** Images (sha256:80e142c664cbde7c1567cd61d91230870dc651488b091d797b85aad564533251):
71[build : create]       monda00/sample-gradle:v1
72[build : create] Adding cache layer 'paketo-buildpacks/bellsoft-liberica:jdk'
73[build : create] Adding cache layer 'paketo-buildpacks/syft:syft'
74[build : create] Adding cache layer 'paketo-buildpacks/gradle:application'
75[build : create] Adding cache layer 'paketo-buildpacks/gradle:cache'
76
77...
78

2回目のビルド

タグを更新して、もう一度PipelineRun(pipelinerun2.yaml)でビルドしてみます。

1apiVersion: tekton.dev/v1beta1
2kind: PipelineRun
3metadata:
4  name: buildpacks-pipeline-run2
5spec:
6  serviceAccountName: buildpacks-service-account
7  pipelineRef:
8    name: buildpacks-pipeline
9  workspaces:
10  - name: source-workspace
11    subPath: source
12    persistentVolumeClaim:
13      claimName: buildpacks-source-pvc
14  - name: cache-workspace # -cache-dir用のworkspace
15    subPath: cache
16    persistentVolumeClaim:
17      claimName: buildpacks-source-pvc
18  params:
19  - name: image
20    value: monda00/sample-gradle:v2 # タグを更新
1kubectl apply -f pipelinerun2.yaml

ログを見てみると、restorerで復元したcache layerを使っている部分(Reusing cached layer)もありますが、先ほどもダウンロードしていたhttps://github.com/bell-sw/Liberica/releases/download/11.0.16+8/bellsoft-jre11.0.16+8-linux-amd64.tar.gzをもう一度ダウンロードしているのも確認できます。

1❯ tkn pr logs buildpacks-pipeline-run2
2
3...
4
5[build : create] ===> ANALYZING
6[build : create] Previous image with name "monda00/sample-gradle:v2" not found
7[build : create] Restoring metadata for "paketo-buildpacks/bellsoft-liberica:jdk" from cache
8[build : create] Restoring metadata for "paketo-buildpacks/syft:syft" from cache
9[build : create] Restoring metadata for "paketo-buildpacks/gradle:application" from cache
10[build : create] Restoring metadata for "paketo-buildpacks/gradle:cache" from cache
11[build : create] ===> RESTORING
12[build : create] Restoring data for "paketo-buildpacks/bellsoft-liberica:jdk" from cache
13[build : create] Restoring data for "paketo-buildpacks/syft:syft" from cache
14[build : create] Restoring data for "paketo-buildpacks/gradle:application" from cache
15[build : create] Restoring data for "paketo-buildpacks/gradle:cache" from cache
16[build : create] ===> BUILDING
17[build : create]
18[build : create] Paketo CA Certificates Buildpack 3.2.5
19[build : create]   https://github.com/paketo-buildpacks/ca-certificates
20[build : create]   Launch Helper: Contributing to layer
21[build : create]     Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
22[build : create]
23[build : create] Paketo BellSoft Liberica Buildpack 9.4.1
24[build : create]   https://github.com/paketo-buildpacks/bellsoft-liberica
25[build : create]   Build Configuration:
26[build : create]     $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
27[build : create]     $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
28[build : create]     $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
29[build : create]     $BP_JVM_VERSION              11                                                           the Java version
30[build : create]   Launch Configuration:
31[build : create]     $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
32[build : create]     $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
33[build : create]     $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
34[build : create]     $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
35[build : create]     $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
36[build : create]     $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
37[build : create]     $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
38[build : create]     $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
39[build : create]     $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
40[build : create]     $BPL_JMX_PORT                5000                                                         configure the JMX port
41[build : create]     $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
42[build : create]     $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
43[build : create]     $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
44[build : create]     $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
45[build : create]     Using buildpack default Java version 11
46[build : create]   BellSoft Liberica JDK 11.0.16: Reusing cached layer
47[build : create]   BellSoft Liberica JRE 11.0.16: Contributing to layer
48[build : create]     Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16+8/bellsoft-jre11.0.16+8-linux-amd64.tar.gz
49[build : create]     Verifying checksum
50
51...
52
53[build : create] ===> EXPORTING
54[build : create] Adding layer 'paketo-buildpacks/ca-certificates:helper'
55[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
56[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
57[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
58[build : create] Adding layer 'paketo-buildpacks/executable-jar:classpath'
59[build : create] Adding layer 'paketo-buildpacks/spring-boot:helper'
60[build : create] Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
61[build : create] Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
62[build : create] Adding 5/5 app layer(s)
63[build : create] Adding layer 'launcher'
64[build : create] Adding layer 'config'
65[build : create] Adding layer 'process-types'
66[build : create] Adding label 'io.buildpacks.lifecycle.metadata'
67[build : create] Adding label 'io.buildpacks.build.metadata'
68[build : create] Adding label 'io.buildpacks.project.metadata'
69[build : create] Adding label 'org.springframework.boot.version'
70[build : create] Setting default process type 'web'
71[build : create] Saving monda00/sample-gradle:v2...
72[build : create] *** Images (sha256:80e142c664cbde7c1567cd61d91230870dc651488b091d797b85aad564533251):
73[build : create]       monda00/sample-gradle:v2
74[build : create] Reusing cache layer 'paketo-buildpacks/bellsoft-liberica:jdk'
75[build : create] Reusing cache layer 'paketo-buildpacks/syft:syft'
76[build : create] Reusing cache layer 'paketo-buildpacks/gradle:application'
77[build : create] Reusing cache layer 'paketo-buildpacks/gradle:cache'

キャッシュされたデータを確認する

PersistentVolumeに格納されたキャッシュデータを確認してみます。

下記のpod.yamlでPodにキャッシュ用に使ったPVCをマウントして中身を確認します。

1apiVersion: v1
2kind: Pod
3metadata:
4  name: busybox
5spec:
6  containers:
7  - name: busybox
8    image: busybox:latest
9    args:
10      - sleep
11      - "999"
12    volumeMounts:
13    - mountPath: /tmp
14      name: volume-pvc
15  volumes:
16  - name: volume-pvc
17    persistentVolumeClaim:
18      claimName: buildpacks-source-pvc
1kubectl apply -f pod.yaml

コンテナに入り、マウントしたディレクトリを確認してみると、layersディレクトリがキャッシュされており、これがrestorerexporterで使われているようです。

1❯ kubectl exec -it busybox -- /bin/sh
2
3/ # cd tmp/cache/
4
5/tmp/cache # ls
6committed
7
8/tmp/cache/committed # tar -xvf sha256\:5596f3f49be533ca6384724815f85b3f46ce300fe5ba70cc176de61d0982f497.tar
9tar: removing leading '/' from member names
10layers
11layers/paketo-buildpacks_gradle
12layers/paketo-buildpacks_gradle/application
13layers/paketo-buildpacks_gradle/application/application.zip

試しにskip-restoreしてみる

restorerをスキップしてみると-cache-dirはどう動くか試してみます。

まずは、pipeline.yamlSKI_RESTOREをtrueにします。

1    - name: SKIP_RESTORE
2      value: "true"
1kubectl apply -f pipeline.yaml

PipelineRun(pipelinerun3.yaml)でビルドしてみます。

1apiVersion: tekton.dev/v1beta1
2kind: PipelineRun
3metadata:
4  name: buildpacks-pipeline-run3
5spec:
6  serviceAccountName: buildpacks-service-account
7  pipelineRef:
8    name: buildpacks-pipeline
9  workspaces:
10  - name: source-workspace
11    subPath: source
12    persistentVolumeClaim:
13      claimName: buildpacks-source-pvc
14  - name: cache-workspace # -cache-dir用のworkspace
15    subPath: cache
16    persistentVolumeClaim:
17      claimName: buildpacks-source-pvc
18  params:
19  - name: image
20    value: monda00/sample-gradle:v3 # タグを更新
1kubectl apply -f pipelinerun3.yaml

ログをみると、restorerがスキップされ、builderの中でReusing cached layerされている箇所がなくなっています。

つまり、リストア(復元)されたlayerがなく、依存関係のダウンロードからビルドを実行しています。

1❯ tkn pr logs buildpacks-pipeline-run3
2
3...
4
5[build : create] ===> ANALYZING
6[build : create] Previous image with name "monda00/sample-gradle:v3" not found
7[build : create] Skipping buildpack layer analysis
8[build : create] ===> BUILDING
9[build : create]
10[build : create] Paketo CA Certificates Buildpack 3.2.5
11[build : create]   https://github.com/paketo-buildpacks/ca-certificates
12[build : create]   Launch Helper: Contributing to layer
13[build : create]     Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
14[build : create]
15[build : create] Paketo BellSoft Liberica Buildpack 9.4.1
16[build : create]   https://github.com/paketo-buildpacks/bellsoft-liberica
17[build : create]   Build Configuration:
18[build : create]     $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
19[build : create]     $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
20[build : create]     $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
21[build : create]     $BP_JVM_VERSION              11                                                           the Java version
22[build : create]   Launch Configuration:
23[build : create]     $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
24[build : create]     $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
25[build : create]     $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
26[build : create]     $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
27[build : create]     $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
28[build : create]     $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
29[build : create]     $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
30[build : create]     $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
31[build : create]     $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
32[build : create]     $BPL_JMX_PORT                5000                                                         configure the JMX port
33[build : create]     $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
34[build : create]     $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
35[build : create]     $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
36[build : create]     $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
37[build : create]     Using buildpack default Java version 11
38[build : create]   BellSoft Liberica JDK 11.0.16: Contributing to layer
39[build : create]     Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.16+8/bellsoft-jdk11.0.16+8-linux-amd64.tar.gz
40[build : create]     Verifying checksum
41
42...
43
44[build : create] ===> EXPORTING
45[build : create] Adding layer 'paketo-buildpacks/ca-certificates:helper'
46[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
47[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
48[build : create] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
49[build : create] Adding layer 'paketo-buildpacks/executable-jar:classpath'
50[build : create] Adding layer 'paketo-buildpacks/spring-boot:helper'
51[build : create] Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
52[build : create] Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
53[build : create] Adding 5/5 app layer(s)
54[build : create] Adding layer 'launcher'
55[build : create] Adding layer 'config'
56[build : create] Adding layer 'process-types'
57[build : create] Adding label 'io.buildpacks.lifecycle.metadata'
58[build : create] Adding label 'io.buildpacks.build.metadata'
59[build : create] Adding label 'io.buildpacks.project.metadata'
60[build : create] Adding label 'org.springframework.boot.version'
61[build : create] Setting default process type 'web'
62[build : create] Saving monda00/sample-gradle:v3...
63[build : create] *** Images (sha256:80e142c664cbde7c1567cd61d91230870dc651488b091d797b85aad564533251):
64[build : create]       monda00/sample-gradle:v3
65[build : create] Reusing cache layer 'paketo-buildpacks/bellsoft-liberica:jdk'
66[build : create] Reusing cache layer 'paketo-buildpacks/syft:syft'
67[build : create] Adding cache layer 'paketo-buildpacks/gradle:application'
68[build : create] Adding cache layer 'paketo-buildpacks/gradle:cache'

まとめ

  • -cache-dirを使うと指定したディレクトリにlayerがキャッシュされる
  • キャッシュされたlayerはrestorerexporterで利用される
  • restorerで復元されたcache layerがbuilderで使われる

ビルド時の依存関係などはキャッシュされないみたいです。

参考

Support

\ この記事が役に立ったと思ったら、サポートお願いします! /

buy me a coffee
Share

Profile

author

Masa

都内のIT企業で働くエンジニア
自分が学んだことをブログでわかりやすく発信していきながらスキルアップを目指していきます!

buy me a coffee