Hellowlol / bw_plex

binge watching for plex
MIT License
368 stars 23 forks source link

Shrink docker image & correct CMD #128

Closed antifuchs closed 4 years ago

antifuchs commented 4 years ago

This PR makes a bunch of adjustments to the docker build process that result in a smaller image: From what I can tell, it's about 400MB thinner:

$ docker images | grep bw_plex
hellowlol/bw_plex    latest              4fd99864a050        6 weeks ago         1.87GB
hellowlol/bw_plex    antifuchs           a33789f9b5fb        17 minutes ago      1.4GB

This PR also adjusts the CMD in use to launch bw_plex in the container, as the previous iteration relied on env variables url and token being set, which I believe most people will want to set in the /config ini file instead.

How does this work?

Via https://pythonspeed.com/articles/multi-stage-docker-python/, the technique for getting the multi-stage build to improve the image size is this:

Then, we make a container containing only the runtime libraries needed to run bw_plex (rather than the -dev ones), and copy the venv over. Voila, lots fewer build steps with less caching in between them.

This could still be better

We could still save a bunch more space by not installing those test/dev-looking dependencies, like pytest below and leaving out pandoc. I'll leave that to you to figure out whether that's desired (:

codecov[bot] commented 4 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (master@fc64975). Click here to learn what that means. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #128   +/-   ##
=========================================
  Coverage          ?   82.07%           
=========================================
  Files             ?       10           
  Lines             ?     1328           
  Branches          ?        0           
=========================================
  Hits              ?     1090           
  Misses            ?      238           
  Partials          ?        0           
Impacted Files Coverage Δ
bw_plex/plex.py 76.90% <0.00%> (ø)
bw_plex/video.py 93.75% <0.00%> (ø)
bw_plex/cli.py 100.00% <0.00%> (ø)
bw_plex/audio.py 87.50% <0.00%> (ø)
bw_plex/config.py 84.00% <0.00%> (ø)
bw_plex/hashing.py 73.62% <0.00%> (ø)
bw_plex/misc.py 81.43% <0.00%> (ø)
bw_plex/credits.py 88.48% <0.00%> (ø)
bw_plex/db.py 95.00% <0.00%> (ø)
bw_plex/edl.py 78.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update fc64975...29669f4. Read the comment docs.

Hellowlol commented 4 years ago

Thanks for this PR! and for taking the time to write how this build work. Really great. I'll hold off on for this now. ATM there is no error handling and starting the docker for the first time without the config file edited will fail. (this is when the config is written to disk)

About the dev stuff, lets leave it in. It make things easier to test and verify. Saving 470 MB is great