automatic pull on production server after push to BitBucket - php

I develop my code locally, commit it to my local repsoitory and then push it to my Bitbucket server. After that I have to login via ssh to my production server
like this:
ssh my-server#my-host.de
pass: very-secure-passs
cd www/myPage
cd git pull origin master
pass: very-secure-pass
I would like to avoid login to my production server and let him pull automatically.
I want to have 3 repositories (local, BitBucket and production Server), so I cant use this solution: Do an automatic pull request after pushing to server
I found this question A hook that let `pull` from VPS when I `push` to Bitbucket which is exactly what I want, but it is from 2013 and the answer is outdated since BitBucket has changed since then.
I found here https://community.atlassian.com/t5/Answers-Developer-Questions/How-can-I-deploy-my-bitbucket-repo-to-my-production-server/qaq-p/565348 that someone suggested to use a free Plugin called HTTP-Request Hook for Bitbucket Server
set up an automated "Pull": Each time you do a push to your central
repository, your production machine is notified and pulls the
repository on notification. Bitbucket Server offers serval plugins to
support the notification process - the one I use is Http Request Post
Receive Hook: each time a push is made, a configured URL is contacted,
submitting some info. On my production machine I have set up a little
web server, waiting for this HTTP-Request. On receiving the
HTPP-Request I evaluate the given parameters and perform an action
(for example: pulling the repository ...)
Now my questions are:
Is it possible to use a Webhook instead of the HTTP-Request
Hook Plugin?
How should the file on my production server look like so that it will do a pull request when it receives a HTTP-Request? I would be interested in a basic example in PHP.

The webhook documentation you linked is for Bitbucket Cloud (bitbucket.org), not Bitbucket Server (which is self-hosted and has some other URL). If you're using BB Cloud, then the HTTP-Request Hook Plugin won't work, but the documentation you linked will. If you're using BB Server, then you can use https://confluence.atlassian.com/bitbucketserver/managing-webhooks-in-bitbucket-server-938025878.html instead to define a webhook.
For the second half of your question - how to set up your server's end of a webhook - you'll need to have a small service that listens for the incoming webhook, does whatever authentication you want, and then runs your pull method. There are a zillion ways to do this, but most will vary based on your preferred language and security settings and on the network configuration of the server in question. I'd suggest a Google search for "webhook deploy $LANGUAGE" to see how some others have done it with your preferred language, or to see if there's a public repo or gist or snippet out there that you can use.

Instead of directly trying to pull on production server, you can setup a Jenkins job that will push the code to production server on each commit. Using Jenkins you can even customize the solutions to match particular token in commit message.

Related

DocuSign API callback not sent to application

Recently stopped working on new application installation. The application was built in Laravel and from XAMPP installation and Ngrok I am able to create envelopes and to sign them. If application is deployed on any webserver (tested with 2 VPS) callback is not sent at all.
Replacing callback on the online version with Ngrok gave results also on the online Webhook.site I got a callback.
Envelope and Recipients are generated correctly. The code is absolutely the same on the localhost and online version.
the callback from DocuSign must be able to go through firewall etc. and must used TLS 1.2 or later on your end. The request is probably not making it through because of some networking problem on your network/server.
I would recommend you consider using a method where the request doesn't go to you directly but rather to a cloud provider and you have a listener connected to it.
Here is C# code for this (we have a few other langs options if you need):
https://github.com/docusign/connect-csharp-worker-aws
Here is PHP - https://github.com/docusign/connect-php-worker-aws

Can I Link XAMPP Server to Github?

How would I go about starting a XAMPP server that uses files from GitHub instead of htdocs?
The idea is that I have my PC on connected to my router and while I am away I can push or merge updates to GitHub, and they are automatically live as XAMPP would be pointed at my Repo.
Can this be done?
I know you can use gitpages, but php and server side code is critical to what we are doing.
You could use webhooks in combination with your Xamp server in order to:
listen to push events on GitHub, and,
when said push is detected, git pull that repository in order to update your files

How to test integrations between local environment and external services (webhooks)

since i started to develop web applications i always found very annoying to inspect external services requests and test my application with "realistic" scenarios. What's the solutions we've got to expose my local development environment to external services?
I am using Laravel Homestead and/or PHP Development Server
Before some time searching for the definitive answer i found a solution that solves all these problems in an efficient, free way, this is Ngrok, a product created by Alan Shreve -- which has worked on giants like Microsoft and Twilio. Alan wrote about the creation of Ngrok and an article on his blog he describes the product as:
"Ngrok is a tunneling, reverse proxy that establishes secure tunnels from a public endpoint to a locally running network service while capturing all traffic for inspection and replay. It is an open-source project on GitHub."
Let's get started:
Well, now that you know a little bit about the tool and why i found it let's demonstrate how to expose a local environment to allow third-party services to submit requests to local environments via Webhook is very simple and the two solutions that I'm going to present have been tested and work with the following scenarios :
Scenario 1: A PHP project using PHP 7.2.6 Development Server
Scenario 2: A Laravel (PHP) project using Laravel Development Server (php artisan serve)
Scenario 3: A Laravel (PHP) project using Laravel Homestead
To do this just follow the steps:
Access the Ngrok website
Register or Login
Download the client based on your OS
Authenticate the client downloaded following the instructions that appear on the same page you've downloaded it.
For the first two scenarios just run the following command
ngrok http <host>:<port>
ex: ngrok http 127.0.0.0.1:666
For the third scenario (if you are using a domain to access the homestead Ex: homestead.test you must rewrite the host-header. But don't worry, to achieve it just increment the command above to something like)
ngrok http <homestead_host_ip>:<port> -host-header=<homestead_domain>
example: ngrok http 192.168.10.10:80 -host-header=homestead.test
VoilĂ , now just point the URL generated by Ngrok in Webhook that you want to test and enjoy this wonderful solution.

Git autodeploy on Windows 2003 with WAMP

I work for a company that for some reason uses a Windows 2003 server with WAMP for its live product (please don't ask me why). Currently we have to push updates locally to github, manually connect to this production server with Remote Desktop Connection and pull.
We want to automate this proccess.
I have tried github webhooks with no success -> Couldn't find a way to create SSH keys for the system account (NT AUTHORITY/SYSTEM), which is the one used by apache on that server solution. The project is currently cloned via HTTPS, so we could also try saving credentials globally so that git won't prompt the local system account for password when trying to pull via PHP, but that seems like the worst possible solution security-wise.
Any ideas?
-- UPDATE --
We've decided not to worry about security implications right now. I then followed all the steps to save credentials for a new read-only user, but no success. I can see a .git-credentials file with the correct user/pass/url in:
C:\WINDOWS\system32\config\systemprofile
All commands work (via browser) except for pull, fetch, etc.
Any more ideas?
-- UPDATE 2 --
I've now changed the wampapache service to run as an administrator account instead, which also has credentials stored on its "root" folder (~). It's the same account I can push/pull via cmd without user/pass prompts. But when I try via browser... No luck.
I'm now officially out of ideas.
I have finally found a solution!
Simply editting the git config file to add user:password to the url parameter under [remote "origin"] has done the job.
url = https://user:pass#github.com/organization/project.git

Git setup for web development on my personal server

I'm going to start working on a web application. The application uses php and the files are going to be hosted on a server I own. Some of my friends will also be working on this project with me.
How exactly should I set up git (using GitHub) so that when me and my friends push our changes to GitHub, our server gets updated automatically with the php files?
git push has a mirror mode that may just be what you want. All you need to do to activate it is to set your remote as --mirror=push and all should be good. IF not, leave a comment and I'll help further.
Another way is to install git on your server, add the settings for github and setup a cron every x period (1 minute) that makes a git fetch and reset to the development branch - that way when you push something to that branch your server will fetch it and reset the filesystem to it.
3rd way - check out the article using Github WebHooks on http://jonathanstark.com/blog/deploying-code-automatically-with-github-webhooks

Categories