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
Related
I'm new to git and github and would like to know how to git push login-credentials.php without Username and Password in it.
Suppose, there are just two files on local repository and index.php will include ("login-redentials.php");:
index.php
login-credentials.php
When using git push origin master, both files will be pushed to github. In this case, USERNAME and PASSWORD will be made published.
What is the best way to remove login credentials from login-credentials.php BEFORE using git push? - I could not find a best practice for this use case in git documentation.
If you want to totally ignore the files, you should add them to your .gitignore.
If you wish to "hide" only the credentials, that depends on your deployment and your build process. One way is using a vault (again, depending on your system).
Another option would be reading credentials from some environment variable, that'll be set in a secured manner somewhere else.
We use a Flexible Environment with Google App Engine for our PHP Website (Laravel) and cannot figure out how to download current website image from Google App Engine with flexible environment setup. As I now have a new developer, we need this latest version for a backup purpose and for future improvement. The idea is to get the latest code from there and also the database, which is even more important, as website already has data and users on it (it is live now, in beta).
We also have a GitHub account setup. If we could load an image from the cloud to GitHub, that could work as well.
You may be able to find the source code here:
https://console.cloud.google.com/debug
Alternatively, since you are using GAE Flex, you could ssh into your instance to try to find it:
https://cloud.google.com/appengine/docs/flexible/php/debugging-an-instance#connecting_to_the_instance
As for the Database, the answer depends on 1) which database you are using (google datastore vs google cloud sql, etc) and 2) what you intend to do with it.
For example, Google datastore has datastore admin which can retrieve a snapshot of the database (https://console.cloud.google.com/datastore/settings), but the output is not something standard like csv. It's primarily used for backups & restores. But you can use this to clone your database into another app engine project
In order to copy anything from a VM on google Cloud platform, you first need to access the docker via SSH (command: sudo docker exec -it gaeapp /bin/bash). When inside of docker, you need to archive everything you need into TAR.GZ format (or try rar or zip, my server only supported TAR.GZ), once archived, you need to copy that outside of docker, which i already forgot how I have done that (oops). But google will help. Once done there will be a very non obvious gear icon on your SSH window top right where you can simply click download file and enter a file name. Choose your archive and vuala.
I've a tricky problem in my project. I have an application runs on VDS. I installed this application with git and composer. This project have git repository just like local one.
I'm trying to make an auto updater bot.This bot is going to get last commit/tag from gitlab and fetch it.
I can use nodejs or php cron job to do.
But git pull command asks for my username and password.
I cant install php_expect extension. Tried this yuloh/expect library but it didn't catch username input.
So here is my question:
How and which method should i implement for run this git pull command and pass username and password?
Solved
For getting new updates...
git pull https://username:password#gitprovider/vendor/repository "version_code":"version_code"
For merging updates with the end-user application.
git merge "version_code":master
this two together completely updates app with new version.
About password protection, we'r going to use ioncube for cron file.
if I fully understanded your question you can try this:
you can put the password in .netrc file (_netrc on windows). From there it would be picked up automatically. It would go to your home folder with 600 permissions.
you could also just clone the repo with https://user:pass#domain/repo but that's not really recommended as it would show your user/pass in a lot of places...
a new option is to use the credential helper. Note that credentials would be stored in clear text in your local config using standard credential helper. credential-helper with wincred can be also used on windows.
Usage examples for credential helper
git config credential.helper store - stores the credentials indefinitely.
git config credential.helper 'cache --timeout=3600'- stores for 60 minutes
For ssh-based access, you'd use ssh agent that will provide the ssh key when needed. This would require generating keys on your computer, storing the public key on the remote server and adding the private key to relevant keystore.
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.
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 ?