-
Notifications
You must be signed in to change notification settings - Fork 1
Improve Docker builds #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If using pre-compiled binaries don't forget to install wget:
|
Threw together a sample that doesn't cache cargo dependencies yet.
I'm not sure it is actually worth avoiding using cargo to install trunk and wasm-bindgen as that bit should be cached. |
Sample with cargo-chef for caching project (so far only backend) dependencies:
This builds trunk and wasm-bindgen as that stage will be cached anyways. Only the backend dependencies are cached; not sure how to handle frontend yet. Using the Rust image and building Diesel results in a 1.5GB image as there are no precompiled binaries readily available (diesel 2379). |
|
Dist folder wasn't being copied from the builder, need to change Need to fix up .dockerignore as well, and can just copy . . on final stage. It'll copy unused source files but they use minimal space. |
A related issue is that some .env variables are still required for building the frontend. |
Merged 7ac1b16 which includes the new Dockerfile. It currently only caches the backend. Environment variables are now written to the index.html file when the backend is run. I'll need to figure out a solution that allows de-coupling of the API and web server, though that is currently not possible at this point anyways. |
The issue with caching the frontend has to do with Cargo workspace limitations.
However, when building from the root workspace folder, it does not look at this config file for members. Alternatively, Cargo nightly allows us to force the package target in the member Cargo.toml: rust-lang/cargo#9406. I tested it and it works great, but I don't want to depend on nightly. It appears that the only other option is to move frontend out of the workspace (would need to do an exclude or eliminate workspace altogether). |
It looks like I might be able to build frontend deps using config.toml while building in the frontend folder. Sample (not working) Dockerfile that might demonstrate how it could be done when building with Docker:
|
Missed root Cargo.file in last comment. The following works and built in less than 2 minutes with everything cached:
I attempted to get it working the same way with cargo-chef without success. I may try it again as it is a pretty clean solution. It can be cleaned up a bit (i.e. remove RUN rm). |
Slightly cleaned up version without touch, as I don't think we need it:
It would be nice to not have to rebuild the both if only one was changed. Is this because Docker ignores cache after change was detected at COPY . .? |
Touch is needed otherwise it may use the builds made in the cacher stage. Removed cargo-chef. I'm pretty satisfied with the current state, but I still would like to get a smaller final image. That would require building diesel_cli by ourselves.
|
Addition of shared broke the Dockerbuild, fixed in 5d7778c |
https://docs.rs/diesel_migrations/latest/diesel_migrations/macro.embed_migrations.html can be used in lieu of diesel_cli. It reads the migrations at compile time. |
Dependency caching is not working very well. I find myself rebuilding them most of the time without any changes to Cargo.toml or Cargo.lock. |
In case I want to continue to use diesel_cli but build in builder stage: In builder:
In final image:
libssl.so.1.1 doesn't exist in the bookworm image, but it does in the Rust, so we need to either move it or build it. It might look like this:
|
Docker build speeds can be sped up significantly.
Separate Dockerfiles are not necessary either, especially once caching is properly utilized.
The text was updated successfully, but these errors were encountered: