Comments (12)
If each instance has it's own version of precompiled assets within it's container, there should be no problem, no?
from kamal.
I think each container serves the assets from its own precompiled version, some can be outdated. Not sure how this would work when using a single CDN though without keeping some older refs around.
from kamal.
If each instance has it's own version of precompiled assets within it's container, there should be no problem, no?
Then you make the assumption that a request for a (new) asset lands on the same server. When using a load balancer you should never assume that is the case.
I think each container serves the assets from its own precompiled version, some can be outdated. Not sure how this would work when using a single CDN though without keeping some older refs around.
Thatโs why we use an s3 bucket with all versions. We remove the older versions on each deploy.
from kamal.
Now I understand. We need public/assets folder shared between multiple instances, connected using volumes and containing old and new versions of assets...
from kamal.
I'd solve that by letting your CDN be the cache of the old assets. Not going to introduce the complication of sharing assets between containers into MRSK. Assets are set to live for a year with no need to check the origin. So assets from old versions will continue to live in the CDN.
from kamal.
Actually, I see what you mean. That you serve HTML from a new version of the app, which then triggers a request for a new asset, which hits the CDN, the CDN then hits the app, which then potentially hits an old version that still hasn't been restarted. I think that window is pretty small with these deploys, but if we start doing rolling deploys, it could increase.
One way of dealing with it is using an asset host, then ensuring the asset host points to the first container instance that will be restarted first. But need to document that.
from kamal.
At scale, having an asset host that is restarted first would move the issue from the new version of the app to the old versions of the app. A user hits an old host that has not been restarted, gets an asset from the new app and things might break (old html with new styles, new Javascript referencing non existing fields).
Hence @edwinv solution of having them both available while the deploy is going on, and assuming you have implemented the proper naming/versioning so each version requests their own assets.
I don't see a general solution that mrsk can provide, but at allowing users to add their "custom things" at the proper moments might be enough, so maybe adding some kind of pre-/post-deployment hooks to add custom code to prepar/clean up assets? If generalised, these hooks might even be used for other interesting things.
from kamal.
I don't think there's an issue in the other direction when you use a CDN that'll cache all old assets, and you ensure that the CDN uses the first-to-restart app as the origin for new assets.
But yeah, would be happy to see general callbacks explored. The audit broadcast callback is one such specialized example.
from kamal.
when you use a CDN
and
when using a single CDN though without keeping some older refs around
I personally agree that the CDN should keep old assets around at least long enough for a deploy - if someone has humongous assets that are too expensive too keep they might need a special strategy there to purge as soon as it's safe.
I first thought assuming that folks use a CDN at all might be wrong, but when we're talking about a large deployment like this (not single containers where there is no issue) then I think documenting this somewhere might be good enough?
from kamal.
Yes, that's my view. This is a problem better handled at the CDN. This is how we keep MRSK small and light. Realizing that it's NOT a full-stack deployment framework, if you will. We're not trying to solve all possible deployment scenarios in this box. That's the pursuit for the likes of k8s or others. MRSK will stay lean by leaning on other modern, solutions that work with it.
So going to close this. Feel free to open a PR with documentation on this ๐
from kamal.
I think there is a misunderstanding of how CDNs work.
Just because you configure proper cache headers doesn't mean that CDNs will keep them for the time configured.
The time is not guaranteed, as unpopular assets will be evicted from cache and will require a repopulation from origin.
One would need a push-CDN for the described use-case, where you pay for cache storage size and get that space guaranteed - CDN will then take care about population of the assets - e.g. BunnyCDN offers that with "perma-cache".
An easier solution would be to provide an "asset" volume which has a mechanism in place to keep several versioned old assets.
I think @dhh used Cloudflare in the example on YouTube, which is a Pull CDN which will not behave the same way as e.g. Cloudfront/S3.
from kamal.
Regardless whether your CDN supports a perma cache or not (or maybe you don't use a CDN at all), you could always put your app behind a standard HTTP caching server like Varnish, nginx, Apache+mod_cache.
from kamal.
Related Issues (20)
- No more logs when container fails to pass healthcheck
- Unable to Access http://localhost:3000 for Remix Run App container HOT 7
- Build failure: Docker image cannot be built due to missing Git submodules HOT 2
- /bin/rails assets:precompile" did not complete successfully: exit code: 1 randomly fails
- Is there any way to access a specific container? HOT 2
- Deploy stopped working since v1.7: `docker stderr: context "<name>" does not exist` HOT 6
- Asset is not present in Pipeline HOT 3
- Question about Default Configuration Merge with Destination Config HOT 2
- RubyZip 3.0 Warning Blocking Kamal Deploy HOT 2
- `kamal app exec` disregard the `--destination` option HOT 1
- SSH Connection Timeouts During Full Deployment
- Environment variable from terminal overwriting .env.erb value HOT 2
- Incorrect validation for traefik configuration. HOT 2
- ERROR (Kamal::ConfigurationError): unknown keys HOT 3
- Kakam setup fails on blank aws ubuntu machine HOT 2
- Unsupported Key type `kamal env push`
- [1.7.3] Docker logs error HOT 5
- [1.7.3] undefined method `[]' for nil:NilClass HOT 5
- feat: adding support for docker capabilities HOT 2
- My app is not starting as its depend upon accessories (Redis). How we can start accessories first? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kamal.