warning
この記事は2年以上前に更新されたものです。情報が古くなっている可能性があります。

projectriff/builder:0.5.0でCommandのアプリケーション(Bash)のOCIイメージを作成します。

BuilderとStackを予めpullしておいてください。

docker pull projectriff/builder:0.5.0
docker pull cloudfoundry/run:base-cnb

次のコマンドで"Hello World"アプリケーションを作成します。
cat

mkdir hello-riff-command
cd hello-riff-command
cat <<'EOF' > hello.sh
#!/bin/bash
xargs -I '{}' echo -n 'Hello {}!'
EOF
chmod +x hello.sh

cat <<'EOF' > riff.toml
artifact = "hello.sh"
EOF

pack buildコマンドでイメージを作成します。

pack build making/pack-riff-command --no-pull --builder projectriff/builder:0.5.0

BuilderとStackを事前にpullしていない場合は--no-pullを外せば、ビルド時にBuilderとStackもpullしますが、ビルドが遅くなります。

次のようなログが出力されます。

===> DETECTING
[detector] io.projectriff.command 0.1.0
===> ANALYZING
[analyzer] Warning: Image "index.docker.io/making/pack-riff-command:latest" not found
===> RESTORING
===> BUILDING
[builder] 
[builder] Command Function Buildpack 0.1.0
[builder]   Command hello.sh: Contributing to layer
[builder]     Writing FUNCTION_URI to launch
[builder]   riff Command Invoker 0.1.0: Contributing to layer
[builder]     Reusing cached download from buildpack
[builder]     Expanding to /layers/io.projectriff.command/riff-invoker-command
[builder]   Process types:
[builder]     function: command-function-invoker
[builder]     web:      command-function-invoker
===> EXPORTING
[exporter] Adding layer 'launcher'
[exporter] Adding layer 'io.projectriff.command:command-function'
[exporter] Adding layer 'io.projectriff.command:riff-invoker-command'
[exporter] Adding 1/1 app layer(s)
[exporter] Adding layer 'config'
[exporter] *** Images (45aa31761e16):
[exporter]       index.docker.io/making/pack-riff-command:latest
Successfully built image making/pack-riff-command

pack build時に--publishオプションをつけると、Docker Registryでのpushを行います。事前にdocker loginが必要です。

作成したイメージをdocker runで起動します。

docker run --rm -p 8080:8080 making/pack-riff-command

アプリケーションにアクセスします。

$ curl localhost:8080 -d World -w '\n'
Hello World!

Docker Imageのサイズを確認します。

$ docker images | grep making/pack-riff-command
making/pack-riff-command             latest              45aa31761e16        40 years ago        87.4MB

pack inspect-imageでイメージを解析します。

$ pack inspect-image making/pack-riff-command
Inspecting image: making/pack-riff-command

REMOTE:
(not present)

LOCAL:

Stack: io.buildpacks.stacks.bionic

Base Image:
  Reference: 40845d52d6fb6d285a320aeac821b61cff0e2863e0ff12e12138c4775aae1828
  Top Layer: sha256:f0d87426c0a82340475d73a9108b063d3d3cfbd92ef3b4af74dcd8f904475a36

Run Images:
  cloudfoundry/run:base-cnb

Buildpacks:
  ID                            VERSION
  io.projectriff.command        0.1.0

Processes:
  TYPE                 SHELL        COMMAND                         ARGS
  web (default)        bash         command-function-invoker        
  function             bash         command-function-invoker     

おわったらDocker Imageを削除します。

docker rmi making/pack-riff-command
Found a mistake? Update the entry.
Share this article: