Live data from Hacker News

Shrinking my static site

hampton.pw

51–60 of 107 posts

Re: Shrinking my static site

#51
post #44

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?

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.

Re: Shrinking my static site

#52
post #36

in my eyes this is all madness. deploying sites via github to some docker shit. how about good old ftp and a cheap shared webhost? like its been done for 30 years.

To be honest, GitHub sites have been amazing for me. I just have a simple static website with personal information. HTML and CSS with minimal JS. Purchasing a shared webhost still means extra cost on top of domain registration. With GitHub, I just followed their instructions with my domain, and everything just worked. I'm also not paying anything per month or year besides domain registration which is really nice when…

With GitLab Pages it's even easier, just fork one of the examples in gitlab.com/pages, push a content update in a commit and it's online a minute later thanks to GitLab-CI and GitLab Pages.

Re: Shrinking my static site

#53
post #25

> This docker image resulted in a 419MB final image and took about 3 minutes to build. There are some obvious issues with this. For instance every-time I change any file it must go through and reinstall all of my node_modules. He doesn't tell whether there have been any build time improvements after the changes to the Dockerfile. Will the builder docker images get cached and thus reduce the build and deployment time?

Well, the article mentions an obvious improvement. The node_moduoes won't be rebuilt after any changes to the code, only changes specific to the packages.json. Basically the main step is the COPY . . step (previously COPY . /app) which will invalidate the cache every change to the code. Also that on the builder, the steps beyond npm run are not needed, but well they won't improve much on the performance or space of t…

> The node_moduoes won't be rebuilt after any changes to the code, only changes specific to the packages.json.

But that's only if the builder image gets cached and can be reused, right?

Re: Shrinking my static site

#54
post #44

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.

Re: Shrinking my static site

#55

I have no idea why they need an nginx image in their second FROM, they are just doing some npm.

yeah, that is a mistake. I just did not fully rethink my code when I moved the build layers. I will be removing that tonight along with a few changed suggested here

On a second thought, I also don't understand why do npm in two different images, why not just copy the webpack bundles from the builder image into the nginx image ?

For me the cause of the big image size was in

COPY --from=npmpackages /app /app

From your third Dockerfile, it seems replacing the above with the following would have done the trick without adding an extra stage

COPY --from=npmpackages /app/_site/ /usr/share/nginx/html/

Re: Shrinking my static site

#56
post #19

Static site and docker shouldn’t be seen together.

I understand the sentiment and agree to a point. At the same time, I sometimes use docker for seemingly trivial problems because the most important requirement is build consistency. I don't know how to get around using containers when I need that. I can see a static site generator actually needing a reliable build process. What would you suggest though? Just manually/automatically test builds?

Re: Shrinking my static site

#58
post #25

> This docker image resulted in a 419MB final image and took about 3 minutes to build. There are some obvious issues with this. For instance every-time I change any file it must go through and reinstall all of my node_modules. He doesn't tell whether there have been any build time improvements after the changes to the Dockerfile. Will the builder docker images get cached and thus reduce the build and deployment time?

TBH I have such a setup on yourlabs.io/oss/blog because I like SASS too (SASS, the nice CSS language that integrates nicely with webpack, as long as there's node-gyp which needs python2 and g++ to build CSS, guess I'm not doing it right >... But in my experience it's pretty boring to wait for the whole JS rebuild when you just add a post, I think next time I'm going to remove the JS build from CI and just commit the built things when I change the frontend code, which is not often.

Re: Shrinking my static site

#59

You can probably shrink it even more. The Caddy alpine image is 14MB compressed. https://hub.docker.com/_/caddy/ You also get automatic TLS certificate management and tons of other goodies that nginx doesn't offer out of the box.

So, if you want to host multiple sites on the same port of your server, from the same process, then you can also have Caddy behind Traefik, but then why would you need Caddy ? Traefik got docker load balancing right: watch docker.sock and self configure on the fly.

I missed the whole Caddy thing anyway because the source code was not completely open back in the days I was looking for nginx alternatives that provided with LetsEncrypt automatically.

However, it seems Caddy can be used as an alternative to Traefik if you use a plugin: https://caddyserver.com/v1/docs/docker Apparently it requires swarm though, which I don't need anyway, so, still no reason for me to try Caddy unfortunately because it does look pretty cool now.

Re: Shrinking my static site

#60
post #31

in my eyes this is all madness. deploying sites via github to some docker shit. how about good old ftp and a cheap shared webhost? like its been done for 30 years.

That doesn't have enough buzzwords.

seems to me like some hipster wannabe hackers in need to inflate trivial tasks into rocket science
Post reply on HN