10 ms·
Serving a website from a Git repo without cloning it
- deleted 3y ago[deleted]
- stevefan1999 3y agoCongratulations! That means you basically figured out how the clone procedure works and found a way to do so just in a partial way (also in an unsafe way). But it is a cool idea, nonetheless. Also check out the Scalar [1] project and its predecessor, GVFS [2], both from Microsoft to manage their monorepo via a VFS layer. [1]: https://github.com/microsoft/scalar https://github.com/microsoft/scalar [2]: https://github.com/microsoft/VFSForGit https://github.com/microsoft/VFSForGit
- ttymck 3y agoWhat is unsafe about it?
- est 3y agoI think it means if you serve it to the public, a hacker might eventually find a way to enumerate all of your .git repo.
- TeMPOraL 3y agoAnd then what happens?
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- yau8edq12i 3y agoThen don't put sensitive material in a repo that you decide to essentially make public and serve to the whole world.
- deleted 3y ago[deleted]
- pacifika 3y agoStevefan’s configuration of the website apparently
- vsuperpower2020 3y agoWhy are you congratulating the author? There's no reason to be condescending.
- merlincorey 3y agoWhy not just use Partial or Shallow Clones? [0] [0] https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ https://github.blog/2020-12-21-get-up-to-speed-with-partial-...
- verticalscaler 3y agogit clone --depth=1 is fast because it doesn't grab the full commits history but OP is getting at a specific singular file directly. It is neat, not aware of a git incantation so fine grained. Hope it gets built into Git directly.
- merlincorey 3y agoAh, thank you for the clarification -- as far as I know that is indeed unique. It's a thimbleful sized shallow clone, one could say.
- paulddraper 3y agoYou can do a shallow clone and partial checkout.
- verticalscaler 3y agoCool! Why you gotta tease me like this without busting out a one liner? :) Gemini disagrees with you btw: Unfortunately, directly combining git shallow clone and git partial checkout to grab just one specific file isn't straightforward. Here's why: Shallow clone: This limits the downloaded commit history to a specific depth, but it still fetches all files involved in those commits. While reducing data, it wouldn't restrict files solely based on your needs. Partial checkout: This lets you specify which files to include in your working directory, but it requires a full clone initially. However, you have a few alternative approaches to achieve your goal: 1. Shallow clone + Sparse checkout: Use git clone --depth=<commit_depth> --single-branch=<branch> to shallow clone the specific branch and limit history. Create a .git/info/sparse-checkout file containing only the path to the desired file. Run git read-tree -u to update the index based on the sparse-checkout file. This method downloads a limited history and only keeps the specified file in your working directory. 2. Partial clone with server support (limited availability): Check if the server supports partial clones (currently implemented on Github and some Gitlab self-hosted instances). Use git clone --filter=blob:none <url> for a "blobless" clone that only contains file content, no history or directory structure. Add the desired file path to the .git/info/sparse-checkout file and run git read-tree -u as before. This approach minimizes downloaded data but requires server support and won't work everywhere.
- sho 3y ago> It's fairly common to use git repositories as a vehicle for serving websites. The webdev pushes their changes to some branch of a publicly available git repository This doesn't require the git repo to be public. My go-to "day one" static website deploy strategy is to set up a git remote on some VPS, point nginx at its public html folder, then "deploy" to that with a git push, authed by ssh key. You'd be surprised how far you can get with simple tricks like this. I served about the first 6 months of what would become a multi-hundred-million company with this hilariously simple setup running on a $20/m DO VPS.
- p4bl0 3y agoI've been publishing my personal web page like this for more than 15 years now (the repos log history goes back to early 2009). I use a post-update hook that makes sure on each push that the working directory is on par with the master branch (so that things that are pushed to other branches aren't made public) and then the public site is rebuilt (using a Makefile and custom scripts making heavy use of xml2, 2xml, sed, and the coreutils, but that's another story). I can see why the author of the linked blog post would want to serve directly from the Git repository: it's fun. But I agree that it seems uselessly inefficient compared to (re)generating a static version of the site only when changes occur. If there is no processing needed like in the case of the blog post, a simple post-update hook can easily do the trick: go to the public directory served by the web server, then set the GIT_DIR environment variable to point to the .git directory of your repository, then execute the command `git checkout main-branch -- .` to get all the static files out of the repository). This would then have the exact same external behavior as what is proposed in the linked blog post, but will be way more efficient (except of course if you have no visitors and update your website very very often).
- supriyo-biswas 3y agoThis approach is fine for static websites, but for web applications you should probably block requests to /.git so that people can’t clone your application off of the web.
- p4bl0 3y ago
- RandomWorker 3y agoI just ssh in periodically run a git pull and it’s done. I have a text file with the various things I need to do. Takes less than 2 min of work. I’ve not been convinced automating this process yet would save me much time.
- iamflimflam1 3y agoThe cheapest solution I’ve found for static sites is an S3 bucket with Cloudfront sat in front of it. Costs next to nothing.
- sakopov 3y agoCheapest option I found is a Jekyll site deployed out of a GitHub repo (can be private) to Cloudlfare S̶i̶t̶e̶s̶ Pages. No cost at all even with a custom domain.
- nindalf 3y agoCloudflare Pages, I think. I agree though, it costs nothing. They don't even have my card on file. And nothing is free forever, but my sense is that this is going to stay free longer than most other free options.
- sakopov 3y agoYep, CF Pages indeed! I agree with your sentiment. It always surprised me how much CF offers under their free tier and wouldn't shock me if they start pulling profitability levers and charging for many of these offerings.
- GordonS 3y agoCloudflare Pages is great for static sites! I use it for a Hugo blog, and it "just works" - plus, deployments are really fast, like a few seconds. It's all just so simple and fast that it reminds me of the days of SFTP'ing files to prod. Aaahhh.
- wodenokoto 3y agoWhy add cloud flare to the mix?
- sakopov 3y agoYou're right. GitHub offers all of this at no charge but your repo has to be public. Cloudlfare allows you to use a private repository.
- tsukurimashou 3y agoI serve my cloned repos directly and remove access to . files with RewriteCond %{THE_REQUEST} ^.*/\. RewriteRule ^(.*)$ - [R=404] in my .htaccess
- AndreBaltazar 3y agoI was checking if this would be possible with GitHub, but querying the dumb protocol at https://github.com/<org>/<repo.git>/info/refs https://github.com/<org>/<repo.git>/info/refs just returns the following Please upgrade your git client. GitHub.com no longer supports git over dumb-http: https://github.com/blog/809-git-dumb-http-transport-to-be-turned-off-in-90-days
- vtbassmatt 3y agoIt’s hugged to death now so I can’t re-load the page. But I think the author of this post went groveling into the objects/ directory for their contents. That will work fine until the repo is GC’d, and then those loose objects get moved into a packfile.
- lakomen 3y agoI guess it wasn't such a good idea to do, huh? This site can’t be reached mediocregopher.com took too long to respond. Try: Checking the connection ERR_TIMED_OUT
- Chico75 3y agoGoogle cached version: https://webcache.googleusercontent.com/search?q=cache%3Ahttps%3A%2F%2Fmediocregopher.com%2Fposts%2Fgit-proxy&oq=cache%3Ahttps%3A%2F%2Fmediocregopher.com%2Fposts%2Fgit-proxy&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg60gEINTAyNGowajSoAgCwAgA&sourceid=chrome&ie=UTF-8 https://webcache.googleusercontent.com/search?q=cache%3Ahttp...
- emadda 3y agoI have found Firebase hosting be quite solid for my static sites. I usually have a ./sh directory which is like my "control panel" for the project, then I run ./sh/deploy.sh from the root which builds and does a `firebase deploy`. Firebase handles HTTPS and seems to have the lowest latency of the CDN's I have tried, even though they all claim to be the "fastest". I prefer to have a explicit "button" to deploy rather than working with git commits.
- jasonjmcghee 3y agoI see a ton of different paid solutions in these comments for hosting static sites- why not just use GitHub Pages? I've had stuff on front page a handful of times never had a complaint about slowness / errors- it's just a static site.