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
F
Finn364d ago
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.
H
haitam364d ago
i haven't pushed to a docker repo before, is it public?
P
pajaro364d ago
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)
M
Matvey364d ago
Haven't tried this personally, but it looks promising - https://coolify.io/
Coolify
Coolify
An open-source & self-hostable Heroku / Netlify alternative.
H
haitam364d ago
or i can just upload the docerfile in github and build it in the server
F
Finn364d ago
you could just put a docker file in your repo yeah and then clone on your server, but that is more manual
H
haitam364d ago
i already have ssh/git setup soo yeah
F
Finn364d ago
still not recomened lol but it works
B
barry364d ago
@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
P
PotatisMannen364d ago
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
H
haitam364d ago
.nextjs folder doesn't have a server.js
H
haitam364d ago
B
barry364d ago
Didn't say it did You have to tell nextjs to be in standalone mode
H
haitam364d ago
a meeting came up. i will be active in few minutes
H
haitam364d ago
do i need to copy just the standalone folder?
H
haitam364d ago
thank you soo much for your help
H
haitam364d ago
for anyone intrested i made these two scripts
# ./scripts/run-production.sh
source .env

node ./out/s1/server.js
# ./scripts/run-production.sh
source .env

node ./out/s1/server.js
# ./scripts/run-build.sh
set -e
git stash
git pull
pnpm i
yarn build

rm -rf out/s2
mkdir -p "out/s1"
cp -rf out/s1 out/s2
cp -rf .next/standalone/* out/s1/
cp -rf .next/standalone/.next out/s1/
cp -rf .next/static out/s1/.next
# ./scripts/run-build.sh
set -e
git stash
git pull
pnpm i
yarn build

rm -rf out/s2
mkdir -p "out/s1"
cp -rf out/s1 out/s2
cp -rf .next/standalone/* out/s1/
cp -rf .next/standalone/.next out/s1/
cp -rf .next/static out/s1/.next
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:
import bg from "../../../../public/images/bg.png";
// make sure paths are relative and doesn't use the fancy ts path like @/public.. etc
import bgLight from "../../../../public/images/bg-light.png";

export default function Hero() {
const { theme } = useGlobal();
return (
<div
className="hero min-h-screen"
style={{
backgroundImage:
theme === "dark"
? `url(${bg.src})`
: `url(${bgLight.src})`,
}}
/>
}
import bg from "../../../../public/images/bg.png";
// make sure paths are relative and doesn't use the fancy ts path like @/public.. etc
import bgLight from "../../../../public/images/bg-light.png";

export default function Hero() {
const { theme } = useGlobal();
return (
<div
className="hero min-h-screen"
style={{
backgroundImage:
theme === "dark"
? `url(${bg.src})`
: `url(${bgLight.src})`,
}}
/>
}
- 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.
P
pajaro364d ago
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?
F
Finn364d ago
Huh til
P
pajaro364d ago
do you like.. && all the things?
F
Finn361d ago
nah the source on files like .env 😅
H
haitam360d ago
interesting.. thanks for the tips
P
pajaro360d ago
pretty sure* bash is mostly tips and tricks
H
haitam360d ago
terminal on steroids
Want results from more Discord servers?
Add your server
More Posts
Geniune question: php vs server componentsI love nextjs. I hear a lot of comments about nextjs just reinvented php. Can someone clarify thingsHow do you fetch an svg from s3 into an angular app?I tried several things, but each time the svg isn't displayed.What's this errorit was working till yesterday then i added stateDistrict to address model then i started to get thisPrisma find many undefinedHello, In my other projet when i do `prisma.resource.findMany({select: ...})` the type is `{id: strESLint to force @types in dev-dependenciesWe recently had an outage coz someone installed the @types/[package-name] in dependencies, but neverUpdating existing T3 with Supabase Auth from Next AuthBackground: - Launched a T3 app with Next Auth. - Currently got 3000 users. - Launching an app vetRPC + AppRouter without reactQueryhi everyone how can i host trpc on next.js and use trpc on server components without using react queMutate instantly returning success instead of isLoadingI have been working on this endpoint that uploads files do Google Drive. It can upload one or multipNext 13.4 problem with loading state after content is visible & hydration problemHey, I have a small app with Next 13.4 with Shadcn Ui 😍 it's really really good. But I'm also usingis there a way to change/refresh token when data in db changes such as role?Hi, I had a project using NextAuth as my provider and the JWT strategy. When I use the database straRefresh a single React Server ComponetnsI have a dashboard where I want a certain piece of data to update every 10 seconds, what's the best Axios Singleton good or bad idea and how to implement?Hey ppl, I'm asking myself a question. Is it a good idea to have a single instance of axios for an aNext-Auth in server rendered components aka appDir pageshow do we deal with next-auth in appDir? I am genuinely curious, as I am trying to migrate from pageAny Clerk gurus in here? Following the Next.js 13 getting started guide renders blank screenFollowing the getting started with nextjs guide for clerk renders a completely blank screen. I've foNested TRPC CallsHi, would anyone be able to assist please? Hope it's ok to post stack overflow link, just figured coCan I use tRPC with Next.Js App RouterI want to know if there's a way I can use tRPC with Next.Js app router. I mean, I don't want to use Suggestions for React Native offline-first DB with syncingHi all, basically I’m trying to get Firebase functionality without using Firebase. because of Their Querying external api in trpc router not workingHi guys! So I'm trying to query an api endpoint that I created through a separate node server insideinfer from trpc callsIt appears trpc clients dont infer the return type, and I have to set it in useQuery like this.. Using GithubAPI + NextAuth Github Provider to access a User's repo information.I am building an app where will allow users to login with Github and view their Github accounts data