We have the following setup - remote repository with gitlab gui.
Our webserver is located on another server and we have ssh access to it. We also have local copies of our dev site, our git setup right now just push to the repo in gitlab.
My goal is to automate the process and on every push to gitlab repo to update the server dir with latest changes.
I saw that for this purpose we should use webhooks or deploy keys. I want to avoid using cron job.
I created a bash script which performs git pull after certain php file is accessed.
However when I placed the url to this php file in webhook section in gitlab, nothing happened.
If I access the file manually by typing url in address bar it works ok.
When I try to test the hook I get 500 error and timeout.
Any recommendations how to improve this process or where Im going wrong ?
The webhook does not just sends a get request to the provided URL, it also sends its data as JSON in raw data.
Can your script handle that?
Have a look at gitlab-webhook-push.php
The actual issue was that gitlab was not able to access our domain and was leading to timeouts, of course sys admins decided to restrict the access from external sources without notifying. Also it is good to mention that JSON raw data can be used for more complex solutions which is pretty nice.
Related
I am developing a laravel application and have a test server setup to show the demo to client. How i get the code in server is I push the code to github and login to server and pull the code there and run.
Is there an automated way of doing this? I looked at continuous integration/delivery and it seemed to be dealing with testing the code?
You can make it by using webhook
To get git pull to run on the server every time there is a commit, can be achieved by using Webhooks.
On GitLab go to Settings -> Integrations
Enter a url to your server and a file to handle the webhook for this tutorial I will create a file called gitlab.php to the url will be
http://example.com/gitlab.php
Enter your url ensure push events is tickets and click Add Webook.
Now head over to your server and create a php file on the server.
touch gitlab.php (you can name it anything but it much match the webhook on GitLab)
As the file created won’t have the right permissions change it with chmod
chmod 644 gitlab.php
Now edit the file with vim:
vi gitlab.php
Press i to go into edit mode
Type:
git pull
Then press escape to go into read mode then save and exit by pressing : then type wq and enter.
By using backticks in the file the server will treat the file as a bash script.
Alternatively, you can use system_exec(‘git pull’)
Now make a change on GitLab and the change will be pushed to your server automatically.
Using rsync
1) You could rsync the code directly from your instance to the customers server:/path/
Example:
rsync -avz yourwebfolder/ user#customerserverip:/var/www/
Using CI/CD
2) You can also push to Github or Gitlab and have a CI/CD which may run tests, and if they pass, to push directly to the customer's server, (for which you would need to setup ssh keys between the git build and the customer's server)
Testing of the code is always optional but also always preferable. So you can do a CI/CD without any testing..
How To CI/CD
If your repository is on Github go to it and then click on Actions, and there you can setup workflows.. There are tutorials online on how to set it up, here's one exampe tutorial.
Gitlab has similar CI/CD section, where you can create a .gitlab-ci.yml file in the root of the project, and add the instructions there.
Create an SSH key in the server and add that the public key to github. Once you have done that, you do not need to login to push or pull.
Creating public and private key
http://lunar.lyris.com/help/lm_help/12.0/Content/generating_public_and_private_keys.html
Adding keys to github
https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
I am 'new' to PHP so this question probably has a very obvious answer, so Ill apologize in advance.
Situation:
I am running a VueJS project, running it with npm run serve and then deploying it with npm run build to a laragon apache server with PHP 7 on it.
That all works great.
I am now moving from using our C# API which we have hosted and you hit it as a URL. To a PHP Api, this API is just set up with a straight connection to SQL using sqlsrv_connect. This is also working when I host it on apache/laragon in its own folder and hitting it on its own URL extension.
But what I was wanting to do ( and not sure if this is possible )
Is in my VueJS project put the .php files in a data folder and hit them like this fetch("src\data\GetSQLData.php?table=Clients&columns=top%2010ClientID"")
Is this possible, or should I rather have them hosted separately and use the URL method?
Buddy,
Vuejs is a front-end framework.What it means is, When you do npm run build then it will create bunch of js and html/css/image files on the server.Then you require a web server to server these files.
When you hit the url on your web-browser then all these files will download into
the web-browser and then execute over there.This is how front-end framework works in a nutshell.
PHP is a back-end scripting language.Which means it require back-end php engine to run and execute the code logic.So it has nothing to do with vuejs that is running on your web-browser.
Best possible way to connect these 2 applications is via API.You should request data from a php API which is running on back-end web server.
fetch('http://localhost/GetSQLData.php?table=Clients&columns=top%2010ClientID')
TL;DR: Is there a way to use PHP to my advantage so I can serve some stylesheets and javascripts from a private github repository for testing purposes before going live?
The full story:
I have a new, private git repository with a master branch and two sub-branches. My idea is for my fellow developer and I to push our changes to our respective sub-branches, and then add a query string variable to our PHP-based web app to tell it to serve stylesheets and javascripts from github.
For example something like:
Switch to your branch in Atom
Make some changes
Push and commit those changes
Go to a URL like "example.com/MyApp.php?User=Me"
MyApp.php will see the "User" query string var, and will prefix the necessary stylesheets and javascripts with a URL so they load directly from github
We can test Myapp.php and make sure we're happy, and then merge our changes with the master branch.
FTP our local changes to our live site
I like the idea of doing it this way because I can have one local set of files, which we only ever FTP to one spot on the live site, and only after the above steps have been completed. I don't have to worry about one of us accidentally FTPing to the live site instead of some testing folder or something, because during testing we'll only do github pushes, leaving the live site unchanged. Meanwhile, github will keep a nice history of versions etc if we need to backtrack for some reason. I have no plans to use github as an ongoing host or cdn. Once we're happpy with the changes and we've merged with master, we'll proceed to FTP the files to our live site, which will always serve from its own local directory.
Unfortunately there are two problems with this:
Github specifically doesn't allow hotlinking, hence sites like rawgit.com
I can't use rawgit since this is a private repository
So that brings me to the TL;DR. Is there some way I can use PHP to authorize my script so it can serve files from github? Maybe it can get a token or something? I suppose I can be really hacky and use cURL to simulate a login, grab some auth tokens and tack them on to URLs like raw.githubusercontent.com/....../java.js?token=.... But ugh, there must be a better way.
Alternatively is there a better way to go about our workflow? Keeping in mind I'd really like to avoid something like "during testing, FTP your files up to the dev folder, but during production, FTP them up to the live folder" - I feel like this is just asking for trouble.
As per the title - I'm trying to trigger an Azure Website "triggered" WebJob from our custom PHP deployment application hosted external to Azure websites.
Thanks to what I believe is Active Directory, I'm able to navigate the /api URLs in my browser and get a JSON output without having to reauthenticate. For example, /api/triggeredwebjobs outputs the triggered WebJob information (that I've set up inside Azure Portal) in my browser.
I've gotten as far in my PHP app as sending a POST request and it is successfully authenticating using basic auth, but every single /api URL that I set in my PHP app returns:
"No route registered for '/api/triggeredwebjobs/{webjobname}'"
where {webjobname} is my custom name for the web job, hidden for privacy of the client. Every URL returns this, but if I navigate in my browser, I only get that error if I navigate to a URL that doesn't exist, such as /api/blahblahblah.
I've set up a deployment user which is what it's using to authenticate... I've even logged in to https://{azuresite}.scm.azurewebsites.net/basicauth using the deployment user and successfully gotten output from each /api page in my browser.
If it helps, I'm using Httpful.phar to handle the HTTP requests.
Thank you very much for taking the time to read and possibly assist.
A colleague helped me get to the bottom of this - the documentation was out of date. I have opened an issue on the Kudu Github Repo to get them to review this:
https://github.com/projectkudu/kudu/issues/1466
To solve the issue for future readers of this question, the correct URL to use within the requester app is:
https://{yoursite}.scm.azurewebsites.net/jobs/triggered/{jobname}/run
Good luck!
I want to deploy a website stored on github to a shared server from OVH. So, basically, after each push I would like the new code to auto-deploy on my server.
I read this article (in french, sorry). To sum it up, it explains how to do it with BitBucket. They provide a php file to put on your server. Then, you make BitBucket send a POST request on that file, and it's over. Here is the code of that php file.
My only trouble is that I know nothing about php and that file is made for BitBucket and not GitHub. But I think it should be easy to make it work with GitHub. The only line to change should be that one :
$url = "https://api.bitbucket.org/1.0/repositories".$uri."raw/".$node."/".$file->file;
Instead of BitBucket I should adapt for GitHub... But I have no idea of what I should write instead...
Could anyone help me with that ?