Remove unnecessary npm packages from Docker image#709
Open
fetburner wants to merge 2 commits intol3tnun:masterfrom
Open
Remove unnecessary npm packages from Docker image#709fetburner wants to merge 2 commits intol3tnun:masterfrom
fetburner wants to merge 2 commits intol3tnun:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
現在、l3tnun/epgstation で配布されている Docker イメージには ESLint 等のビルド時以外には不要な npm パッケージが含まれており、非圧縮状態で server と client 合わせて実に 410MB ほどイメージサイズを押し上げる結果となっています。
せっかく軽量なベースイメージを採用しているのに node_modules だけでイメージを重くしてしまうのは勿体無いので、配布イメージにはビルド時以外不要な npm パッケージを含まないようにしたいです。
What
各 Dockerfile でサーバーをビルド後、最終イメージへそれをコピーする前に
npm prune --omit=devを行って devDependencies を削除します。加えて、クライアント側については
vue-cli-service buildでバンドルが行われており node_modules 自体が不要なことから、最終イメージへコピーする前に削除を行います。これにより、配布イメージにビルド時以外不要な npm パッケージを含まないようにできるかと思います。
動作確認
mirakc 2.4.9 と MySQL 互換 DB(TiDB Serverless)を使ってサーバー側の devDependencies とクライアント側の node_modules を削除した alpine ベースのコンテナでも x64 環境でストリーミング、録画、録画の視聴、番組表の閲覧、更新といった一通りの動作を行えることを確認しました。
とはいえ FFmpeg を自前で用意する都合上、完全に同一の Dockerfile で検証できた訳ではないです。