juhaku/utoipa

support `debug-embed` of rust_embed

cemoktra opened this issue · 13 comments

Hey,

it would be nice to allow to select the debug-embed feature from utoipa-swagger-ui. It's either this or a problem with running the swagger-ui in distroless.

Hello,

This is a good question indeed, I haven't tried with distroless image before, but my rough guess points to how the rust_embed which is the create used underneath handles the embedded files. And it seems like in distroless case it does not find the files or they will never get included.

Snippet from the utoipa-swagger-ui/src/lib.rs

#[derive(RustEmbed)]

#[derive(RustEmbed)]
#[folder = "$UTOIPA_SWAGGER_DIR/$UTOIPA_SWAGGER_UI_VERSION/dist/"]
struct SwaggerUiDist;

And the build.rs file is the bulid script that suppose to set the variables in place where the files will be located.
https://github.com/juhaku/utoipa/blob/59c9c1275f0e07b632c33767cbf38508570b024b/utoipa-swagger-ui/build.rs

The build script is bit tricky to debug since its run at background and does not really give any user output. But it might be that the distroless case is not correctly handled by this build.rs. Where is the distroless image build? Is the configuration somehow special compared to the regular image.

Another thing that comes to my mind is that the rust_embed is being used with feature flag interpolate-folder-path not sure whether the distroless is able to handle the interpolated folder path from environment varialbes like the reqular distroful images are?

Oh as you typed i changed the description cause i think we were using debug builds, meaning it wont be embedded at all

Right, I could add this feature flag available for such a case like this, but will not enable it by default for everyone. So then the utoipa-swagger-ui could be defined with feature features = ["debug-embed"].

Yes that would be nice

Despite this being a good idea. Likely it'ss not the problem as we do not specify --release but the build has debug = false which should make rust_embed, embed the file. So maybe it's its about interpolate-folder-path, but i don't see any deps that might cause problems

Yeah, maybe it's worth debugging the rust_embed itself whether it is able to embed files in distroless environment with or without interpolate-folder-path flag to narrow down the possible source of issue if the feature flag is not helping on this one.

I added the feature and it can be found from master: ab7efd2

Great. I will try this latest next week

Ok I found a minute to check. The 'debug-embed' feature solved the issue. Any plan on doing the next release?

Okay nice, 👍 I could create a new release from utoipa-swagger-ui latest tomorrow with the additional feature flag.

Actually just released it 🙂

awesome, thx

juhaku commented

Relates to #527