feat(Dockerfile): switch to scratch base image#544
feat(Dockerfile): switch to scratch base image#544paulopontesm wants to merge 1 commit intoflashbots:mainfrom
Conversation
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #544 +/- ##
=======================================
Coverage 33.26% 33.26%
=======================================
Files 24 24
Lines 5090 5090
=======================================
Hits 1693 1693
Misses 3178 3178
Partials 219 219
Flags with carried forward coverage won't be shown. Click here to find out more. |
|
Thanks for proposing this! I recall trying scratch a while ago and not going with it, but don't remember if it was just due to lack of time or any issues I spotted. Open to changing the base image if we can make sure there's no side-effects. |
No problem. I might be missing something, so your input is welcome. What tests could we run to make sure the changes are safe? Got an idea for quick tests?
Got it 😄. I dug into the Git history to try to get more context 🕵️. Let me know if I'm looking wrong at something...
Also, for reference, here are the differences between dynamically vs. statically linked binaries:
Note: We're copying the CA certificates from the builder stage into our image, ensuring that mev-boost-relay can establish secure SSL connections without issues. I believe that this step wasn't necessary with the alpine base image but is required when using scratch. |
📝 Summary
This MR switches the base Docker image from Alpine to
scratch, reducing the image size and eliminating unnecessary dependencies.Again, not changing logic so I didn't open an issue. Let me know if I should. I am making an assumption (explained below) that we don't need this because of the way that we are compiling the binary. I did a simple test of running locally and it works, but I might be missing something.
⛱ Motivation and Context
Why Use Scratch?
scratchimage is an empty layer, meaning it doesn't carry any extra libraries, making the image extremely small in size. Decrease from32MB->22MBscratchmeans shell-based attacks are not applicable.scratch.go.modfile.Why Don't We Need Alpine and Libraries?
Assumption:During thego build ..., we use-linkmode external -extldflags '-static'. These flags instruct the compiler to statically link all dependencies into the binary. As a result, themev-boost-relaybinary should be fully self-contained and not dependent on any shared libraries 🤞. This makes the transition toscratchseamless while making the image more secure and less prone to vulnerabilities.📚 References
✅ I have run these commands
make lintmake test-racego mod tidyCONTRIBUTING.md