aws-glue-libs をCI/CD で使いたい

概要

AWS Glue の自動テストで aws-glue-libs コンテナイメージを使いたいが high-uid-error になってしまった。それを回避した話。

前提

AWS Glue の開発を進めやすくするために、amazon から aws-glue-libs というコンテナが公開されている。

https://hub.docker.com/r/amazon/aws-glue-libs

このコンテナを使って、

  • スクリプトの開発
  • Zeppelin, Jupyter などによるNotebook 開発
  • テストの実行・開発

を行うことができる。

今回の事象

今回はglue とpySpark の組み合わせでETL タスクを実装しており、一部のtransform をpytest で書いていた。 local 環境ではdocker-compose でテストを走らせるようにしていて、base image に aws-glue-libs を使っているという形。 local 環境ではうまくテストが実行されたので、CircleCI で自動テストを行おうとした際に、 high-uid-error にぶつかった。

https://circleci.com/docs/2.0/high-uid-error/

問題

high-uid-error は、コンテナ内のファイルやディレクトリのUID/GID の値が指定の値域以上の値が指定されているケースに起こる。 ドキュメントには

The error is caused by a userns remapping failure. CircleCI runs Docker containers with userns enabled in order to securely run customers’ containers. The host machine is configured with a valid UID/GID for remapping. This UID/GID must be in the range of 0 - 65535.

とあり、コンテナ内のUID/GID は 0 ~ 65535 の範囲内にある必要がある。

原因

UID/GID が原因のようなので、コンテナを起動して ls -la などでファイルなどのオーナーを調べる。

# local 環境から amazon/aws-glue-libs:glue_libs_1.0.0_image_01 を起動する
$ docker run -it amazon/aws-glue-libs:glue_libs_1.0.0_image_01 /bin/bash 

# amazon/aws-glue-libs:glue_libs_1.0.0_image_01 内の操作
root@b3219a5e7e66:/# ls -la /home/
total 32
drwxr-xr-x  1 root       root  4096 Jul 21  2020 .
drwxr-xr-x  1 root       root  4096 Jul  5 05:13 ..
drwxr-xr-x  3 root       root  4096 Jul 15  2020 aws
drwxr-xr-x  5 root       root  4096 Jul 21  2020 aws-glue-libs
drwxr-xr-x  3 root       root  4096 Jul 21  2020 jupyter
drwxr-xr-x 25 root       root  4096 Jul 21  2020 livy
drwxr-xr-x 11 2049080342 staff 4096 Sep 17  2019 spark-2.4.3-bin-spark-2.4.3-bin-hadoop2.8
drwxr-xr-x 13 root       root  4096 Jul 21  2020 zeppelin

/home/spark-2.4.3-bin-spark-2.4.3-bin-hadoop2.8 のuid が 2049080342 になっていることが確認できた。

うまくいった対処

今回はCircleCI の代わりにGitHub Actions を使うことでクリアしました。 幸いにもテストを実行するdocker-compose file を用意していたので、そちらをGitHub Actions の中で呼ぶだけで済みました。

他に試みた対処

CircleCI の jobs の中で amazon/aws-glue-libs:glue_libs_1.0.0_image_01image として指定し、 command/home/spark-2.4.3-bin-spark-2.4.3-bin-hadoop2.8 のオーナーを root:root に変更してみた。 これはうまくいかなかった。 そもそも、CircleCI で該当のコンテナをマッピングするときにエラーが起きるので、コマンドまで到達せず、UID/GID を変更するまでに至らなかった。

Docker image を公開しました

CircleCI でも使えるように amazon/aws-glue-libs の Spark を root:root に変更しただけのDocker image とGitHub repository を公開しました。 興味がある人は使ってみてください!

Docker Hub

hub.docker.com

GitHub repository

github.com