I am trying to figure out with what method do web developer use in order to build the website while it is in use ?
This is what I am trying to think : Using gitlab.
So I put all the files in gitlab and pull the site from the terminal while to the staging.
After update - re-pull all the sites to the staging website with force so that it replace everything.
The same method also utilize when pull all the files to the production server. After another update pull it with force so that it replace everything to the production server. While for the database, you just have to run the migration one by one after the updates in order to make the database works while it is in use.
There are tools like Envoyer to facilitate zero downtime deployments.
This article gives you some understanding of the technique using symlinks to serve a different release of the project; which has been fetched to a different directory on the server
That's a good idea, but I don't think my client is willing to pay for the service. Maybe 30 minutes downtime is not a big deal.
Is there any git command like: pull -f
Pull with force ? So that it replace all the files after the pull ? Since, if normal pull will leave a lot of conflict and I don't want to debug the file from the server. Since I am the only developer for this current project.
@davy_yg 30 minutes?!?!?! Even without zero downtime, pulling and migrating shouldn't take 30 minutes. Maybe 30 seconds at the very max.
And no need to pull with force, as your production env, will never change any of the files managed by git. But you can do git reset --hard on production to ensure it is indeed clean
@Sinnbeck See I only worry if there are code conflicts after the pull since there would be extra codes that I added. I don't want having to fix all the conflicts on the server.
@Sinnbeck Supposing that the owner of the website would like to add extra features while the website is being used. Just like updating the current website with extra features.
I would add the codes from localhost and push it to the gitlab. Then pull my gitlab codes to the production server after testing it in the staging server.
Will it not create any code conflicts in the production server ?
@davy_yg No. Only if you have changed code directly on the production server. Conflicts in git happen when the same file has been changed by two different persons/branches etc. So production should always be "clean"
If I have assets that needs to be compiled. (Using laravel-mix)
Do you compile your assets locally (npm run production) and push the assets? (Or using GitHub actions or something similar)
Or would you advice to add that to the script? And compile on the server, before changing symlink?
The problem I have when compiling on the server is that laravel-mix (devDependency) needs to be installed. And I do not want to install devDependencies on the production server.
Like testing the codes in local and push it to gitlab and pull it from the server everytime will takes around 6 minutes before I get to see the debug code live on staging server again.
@davy_yg For the production server I think you best option is the script that @snapey suggested.
For the staging server, if this is a server only used for your testing and you would like to see the changes immediately, you could use an extension for your code editor that copies the files to the server (through scp or rsync) every time you save the file.
I've never used jenkins, so I can't speak on that.
For all of my projects (also my personal blog) I use ploi. Setting up zero downtime up is just checking a box. And setting up a staging site is also quite easy if you need one. They are quite cheap