Skip to content

Comment on Shrinking my static site

Comments

This approach is akin to installing all of the build tooling inside of Docker, then generating the build artifact. I'd think it'd be even slimmer to generate the build artifact first, then just copy that into the container.

Is there an advantage to building inside of Docker?

Wouldn't the advantage be consistent build fragments? If you use the build tools outside of docker, you won't get the same repeatable build artifact across different machines (or as your own host system changes). Maybe I'm not understanding you though.

I'd think it'd be even slimmer to generate the build artifact first, then just copy that into the container.

That's what this is doing. It creates builder containers, uses them to make the artifact and copies it in:

    FROM nginx:1.17.10-alpine
    RUN rm -r /usr/share/nginx/html/
    COPY --from=builder /app/_site/ /usr/share/nginx/html/

    EXPOSE 80 
The final image is nginx with the static files copied over.

We've found one advantage to be more reproducible builds since you don't have to worry about different versions of build tooling affecting the artifact.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.