3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

巨大なベースイメージに差分があるときだけデプロイしたい、かも

Last updated at Posted at 2023-02-28

ビジネスロジックを担うアプリより、ベースとなるDockerImageが巨大&ビルド時間が長い場合、fetch & run構成をとることが結構ある。

これをデプロイCIに乗せる上で、Dockerfileなどの変更がないときはイメージのビルドは必要なし、という扱いにしたい。
Docker Imageのキャッシュも考えたが、キャッシュ保持期間や転送料金的な事情もあり今回は別のアプローチを思考実験するメモ。

  • 1 . Dockerfile周辺の可視ファイルをzip化し、ハッシュ値をとる
  • 2 . イメージのリポジトリ(今回はAWS ECR)にそのハッシュ値のタグがないか探す
  • 3 . なければビルド&プッシュする

今回は変更頻度の高いアプリ本体は別でビルドするので、ハッシュ検出はあくまでベースイメージ周辺のファイル群だけでいいはず。無圧縮のzipを使う。


deploy-on-hash-notexist:
	@mkdir -p .build || true; \
	export TAG=$$(zip -rq -0 .build/data.zip ./ -x ".*" && shasum -a 256 .build/data.zip | cut -d ' ' -f 1) && \
	echo "$$TAG" && \
	if aws ecr describe-images --repository-name <リポジトリ名> --image-ids imageTag="$$TAG" > /dev/null 2>&1; then \
		echo "buildしない && deployしない"; \
	else \
		echo "build & deployする"; \
	fi


あくまでfetch & run構成だからできる差分検知ではある。

こういう差分で副作用起こしたいときのケース出しがめんどいから、みんな基本時間かかってもビルドキャッシュ愚直に使ったりbazelみたいなの使ったりするのかもしれない

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?