この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
こんにちは。サービス部の武田です。
Dockerのプラン値上げなどにより代替ツールを検討している方も多いでしょうか。いくつかのサイトを見ていると次の2個がよく候補に上がっています。
私は今回、Rancher Desktopを使ってみたのですが、CDKでテストを実行するとエラーになってしまいました。このエントリでは具体的な状況と解決方法について紹介します。
環境
次のような環境で確認しています。
- Rancher Desktop 1.6.2
$ sw_vers
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
$ uname -m
arm64
$ docker info
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.9.1)
compose: Docker Compose (Docker Inc., v2.11.1)
Server:
Containers: 22
Running: 11
Paused: 0
Stopped: 11
Images: 27
Server Version: 20.10.18
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc version: 5fd4c4d144137e991c4acebb2146ab1483a97925
init version:
Security Options:
seccomp
Profile: default
Kernel Version: 5.15.64-0-virt
Operating System: Alpine Linux v3.16
OSType: linux
Architecture: aarch64
CPUs: 2
Total Memory: 5.786GiB
Name: lima-rancher-desktop
ID: UDJU:SLDG:LR5E:S2VI:XHK3:S5YM:IQHJ:QFK4:MV33:V5S4:XI4B:7J3G
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
エラーとなるCDKのソースコード
まずエラーの発生条件ですが、CDKのLambda Pythonモジュールを使っている場合です。このモジュールは、PythonをランタイムとしたLambdaのビルドにDockerを使用します。Pythonなのでコンパイルなどはしませんが、依存ライブラリなどをまとめてzipにしてくれます。検証はしていませんが、同じ条件からDockerを使用するLambda NodeJSやLambda Goなどでも発生すると思われます。
ソースコード全体はGitHubに置いてあります。
TAKEDA-Takashi/alt-docker-check
次のような簡単なコードでエラーを発生させることができます。
lib/alt-docker-check-stack.ts
import * as lambdaPython from "@aws-cdk/aws-lambda-python-alpha";
import { aws_lambda as lambda, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as path from "path";
export class AltDockerCheckStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new lambdaPython.PythonFunction(this, "HelloFunction", {
entry: path.resolve(__dirname, "../lambda/src/hello"),
runtime: lambda.Runtime.PYTHON_3_9,
});
}
}
テストを実行するとエラーになります。
$ npm run test
...
RUNS test/alt-docker-check.test.ts
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux FAIL test/alt-docker-check.test.tswas requested
✕ Snapshot Test (785 ms)
● Snapshot Test
Failed to bundle asset AltDockerCheckStack/HelloFunction/Code/Stage, bundle output is located at /private/var/folders/br/6mch43t924v6q739rpwl_20m0000gp/T/cdk.outGrfknR/asset.214a9d294964feebfaecfa77d3421c10c71f9f6da4266a50955572fb22465959-error: Error: docker exited with status 1
10 | super(scope, id, props);
11 |
> 12 | new lambdaPython.PythonFunction(this, "HelloFunction", {
| ^
13 | entry: path.resolve(__dirname, "../lambda/src/hello"),
14 | runtime: lambda.Runtime.PYTHON_3_9,
15 | });
at AssetStaging.bundle (node_modules/aws-cdk-lib/core/lib/asset-staging.js:2:614)
at AssetStaging.stageByBundling (node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:4588)
at stageThisAsset (node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:1949)
at Cache.obtain (node_modules/aws-cdk-lib/core/lib/private/cache.js:1:324)
at new AssetStaging (node_modules/aws-cdk-lib/core/lib/asset-staging.js:1:2344)
at new Asset (node_modules/aws-cdk-lib/aws-s3-assets/lib/asset.js:1:818)
at AssetCode.bind (node_modules/aws-cdk-lib/aws-lambda/lib/code.js:1:4710)
at new Function (node_modules/aws-cdk-lib/aws-lambda/lib/function.js:1:2885)
at new PythonFunction (node_modules/@aws-cdk/aws-lambda-python-alpha/lib/function.ts:73:5)
at new AltDockerCheckStack (lib/alt-docker-check-stack.ts:12:5)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 4.045 s, estimated 5 s
ちなみにnpm run cdk synth
でビルドする分にはエラーになりませんでした。
原因と対策
原因はどうやら共有フォルダーの権限不足だったようです。/private/var/folders
配下にコンテナとの共有フォルダーをマウントし、そこにバンドル結果を出力しようとしている。ところが 書き込み権限がない ため失敗している。というのが原因でした。
Rancher Desktopでは内部的にlimaを使っており、設定の上書きもこれに倣います。設定の上書きは~/Library/Application\ Support/rancher-desktop/lima/_config/override.yaml
を用意します。今回は次のような設定ファイルを追加しました。
~/Library/Application language=Support/rancher-desktop/lima/_config/override.yaml
mounts:
- location: "/private/var/folders"
writable: true
mountType: sshfs
追加できたら仮想マシンを再起動します。
$ rdctl shutdown
$ rdctl start
再起動が成功したら、あらためてCDKのテストを実行してみます。
$ npm run test
...
Bundling asset AltDockerCheckStack/HelloFunction/Code/Stage...
RUNS test/alt-docker-check.test.ts
PASS test/alt-docker-check.test.tsorm (linux/amd64) does not match the detected host platform (linux
✓ Snapshot Test (899 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 1 passed, 1 total
Time: 4.338 s, estimated 5 s
今度は無事に成功しました!
まとめ
Docker Desktopの代替を検討する際に、周辺ツールへの影響も調べる必要がありました。今回はCDKについて調査し、無事解決できました。
めでたし。めでたし。