Deploy Endpoint in Repo
We’ll put a file in the repo that Bitbucket can target to trigger an update of the production repository.
We’ll call this file
Bitbucket Deploy Key
In order for your production install to be able to pull code from the main repository, it will need to have a deployment key. The deployment key allows for read-only access so it can pull information from the repo, but not push any changes to it.
If one does not already exist, you will need to create an SSH key:
The public key will be created in
~/.ssh/id_rsa.pub. Copy the contents of this and paste it into the Add Key dialog in the Settings > Deployment Keys area of your repo on Bitbucket.
Bitbucket has additional details here.
Bitbucket POST Hook
A new POST hook will need to be added in the Settings > Hooks area of your repository. Select POST from the Select a hook dropdown, and then hit the Add hook button.
The URL for the POST hook should be to that of your
deploy.php script. For example: http://www.example.com/wp-content/themes/my-theme/deploy.php.
This tells Bitbucket to POST information about the last changeset to that URL for further processing. Now, the
deploy.php script above isn’t concerned with the actual information that Bitbucket posts. The only thing that matters to it is that some change has been made and that it should now get an updated version of the repo.
Bitbucket provides detailed information here.
We can add a
post-merge git hook that tells git to run a command or series of commands when new changes are merged in.
Note: If your repo or branch is setup to rebase instead merge on pull (a la
git pull --rebase), this hook will not be fired
Create a new git hook and make it executable:
It should be updated to read as follows:
If we’re executing things like grunt tasks, then we will need to have node installed and ready.
If the production site is hosted on a VPS or some other sort of managed server, simply follow the standard installation method here. If, however, the production site will be hosted on a shared server, node will need to be installed in the hosting account’s home directory.