How do you self host your projects in a vps
without relying on any cpanel or vercel,
i have a vps and i usually move the project using git and run yarn build then yarn start
i also sat up a systemd service that handles keeping that website running
so my process of upgrading the site would be to ssh into it and then run yarn build
but after some testing, i found out that while the build is running, i can't access the website, and or if the build fails the website breaks.
i saw something in the vercel cli where it builds it then if the build is successful it outputs it into "out" folder
then it runs it from there.
is there a way to do that without involving needing vercel
24 Replies
have ci that builds a docker image and pushes that to a docker repository ( docker hub / github docker repo or somthing ) then when you want to deploy you restart the docker image on your vps with the new version.
i haven't pushed to a docker repo before,
is it public?
doesn't have to be, pretty sure you have to pay for private ones on dockerhub but private ones are free on gitlab (not sure about github though)
Haven't tried this personally, but it looks promising - https://coolify.io/
or i can just upload the docerfile in github
and build it in the server
you could just put a docker file in your repo yeah
and then clone on your server, but that is more manual
i already have ssh/git setup soo yeah
still not recomened lol
but it works
@hhk Regarding the "run from a custom build folder", you can build a standalone folder which doesn't depend on a node modules folder or .next if that helps
Basically just gives you a folder with all the stuff and a server.js or something like that you can just run with node
This sounds promising. Depending your restart time of your main server you could have a max downtime of a couple secs if your cluster is fast enough
.nextjs folder doesn't have a server.js
Didn't say it did
You have to tell nextjs to be in standalone mode
a meeting came up. i will be active in few minutes
do i need to copy just the standalone folder?
thank you soo much for your help
for anyone intrested i made these two scripts
NOTES:
- add
output: "standalone"
in the next.config,js
- make sure all your images are imported and not just in the public folder and being referenced
if you are referencing them to get the background image working in a div you can actually import it and instead of padding it directly, it has a property called src, which is what you need. ex:
- make sure you ignore the out file.
- if at any point your build fails and somehow lost s1 (in the out folder). you can copy what's on s2 into s1
s2 represents the last successful build.re: script #1, pretty much you can just
source .env
wrt script 2, you can use set -e
at the top to avoid having to use &&
on everything
(the script will exit if something fails,
if something can fail safely, you can use || true
to prevent this)
does the "renaming things into place" strategy work well?Huh til
do you like..
&&
all the things?nah the source on files like .env
š
interesting.. thanks for the tips
pretty sure*
bash is mostly tips and tricks
terminal on steroids