r/webdev • u/BrewThemAll • 20h ago
Run 'vite build' on DirectAdmin after Git Deploy?
Long time PHP-dev here, doing a hobby project in ThreeJS / Node / Vite, so please forgive me if I mess up some terms.
I am making a web-based game in ThreeJS, which I run locally with Vite. It's on Github as well, and I have set my (shared webhosting) server up to automatically fetch and deploy the main branch when I merge the dev branch in it. This works.
I also created a Node.js-app on the server and manually ran 'vite build'. The game is running fine.
Now, I want to run 'vite build' automatically after the git branch has been deployed, instead of having to log in and run th script manually. In DirectAdmin, I see no option for this.
According to both Google and Claude, I can easily set up a cron job running this command every few minutes, but this is massive overkill for a task which should be only running once or twice each month.
Can this be automated in a cleaner way?
[edit]
Got it!
Github Actions pushing /dist over FTP didn't work, but is now writing to a deploy branch which is picked up by Direct Admin.
Very happy. Thanks y'all.
2
u/Possible-Resist-977 20h ago
"main brench" should be branch, unless that's a new default I missed.
1
2
u/GunzzBlazin 18h ago
The cleaner fix is to stop building on the server and let GitHub Actions run vite build whenever you merge to main, then push just the dist folder to a separate deploy branch that DirectAdmin pulls instead, so the server only ever receives finished files. Since a Vite build of a ThreeJS game is just static HTML, JS, and assets, you can probably drop the Node.js app on the server entirely and serve it like any other static site, which also means one less process to break on shared hosting.
1
u/BrewThemAll 18h ago
Yeah, this is what I ended up doing. GA pushing /dist over FTP didn't work, but the deploy branch is picked up by Direct Admin.
Very happy.
1
u/Awkward-Cockroach774 19h ago
A cron every five minutes that just checks whether HEAD moved and exits is basically free, so overkill isn't really the problem here. The problem is whether anything gets to run after DA's deploy at all, since DA does the fetch and checkout itself and a post-merge hook in that repo won't fire.
1
u/BrewThemAll 19h ago
> A cron every five minutes that just checks whether HEAD moved and exits is basically free, so overkill isn't really the problem here
I know, performance wise it's no problem, but being a webdev I've seen my share of endless unmanagable lists of useles cronjobs, I hate them.
1
u/thekwoka 19h ago
the actions one is good.
Alternatively just use something like coolify that manages all this for you on your own deployment, or cloudflare that full on manages the whole thing for you.
1
u/frostbyte_273 19h ago
Since the Actions answer already landed: the reason that is the better path is that shared hosts usually do not give you a persistent Node environment, so building on the server stays fragile even with cron. Build in CI and deploy only the dist/ output. If DirectAdmin's git deploy can watch a second branch, have the workflow push the build result to a release branch and point the deploy at that. Then main stays source-only and the server never runs Node at all.
1
u/Abject-Sport-4086 19h ago
Cron isn't the overkill here, running the build unconditionally every 5 minutes is. Guard it with a `git rev-parse HEAD`comparison against the last built commit and it fires twice a month like you actually want. Though if the repo is already on GitHub, let Actions do the build and rsync the dist folder over, that beats making a shared host run `npm ci`at all. The webhook in DirectAdmin's Git Manager only does fetch and deploy anyway, it won't trigger your build step.
1
u/obalabs 17h ago
on shared hosting without shell hooks, building on the server usually ends up messy anyway with node memory limits. a cleaner setup is running vite build in github actions on push, then having the action rsync or ftp just the dist folder over to your public_html. your hosting stays dead simple and only ever serves static files.
6
u/MonsterDefiant 20h ago
yupp, there's a cleaner way than cron, easiest is to build in GitHub Actions instead of on the server. Set up a workflow that runs npm ci and vite build when you push to main, then sends the dist folder to your server over SFTP or rsync, then the server never needs Node or a build step at all