dev-master
9999999-devDeployment and migration using Mercurial and ssh
Unlicense
The Requires
The Development Requires
by DEPIDSVY
Deployment and migration using Mercurial and ssh
PHP script to handle versioning of mercurial project migration with it's dependent mercurial repositories., (*2)
If you use git - you don't need to read further., (*3)
If you use composer for versioning your dependencies with branches - you don't need to read further. Continue reading if you don't use branches in Mercurial., (*4)
> migrate add . > migrate add vendor/spidgorny/nadlib > migrate add vendor/something/else > hg add VERSION.json > migrate commit "update VERSION.json" > cd /directory/corresponding/to/the/live/server > rem Start synchronization tool (read below) > migrate golive ...........
When testing deployer for deploying my PHP applications I've realized it is meant to be used with Git. It does not work with Mercurial (hg). This led me to write my own deployment script for projects tracked in Mercurial., (*5)
There are two independent problems that migrate tries to solve. One is the ability to upload files to the remote machine. This is a bare deployment itself. The other problem is to know which exact version of the project and it's dependent libraries are to be deployed and were deployed on the live server last time., (*6)
This is solved in migrate by storing the necessary versions in the VERSION.json file. There are some commands for managing repositories in the VERSION.json file. This file can be edited manually as well, if you know what you are going., (*7)
Adds specified folder (default .) to the VERSION.json file. Make sure you add at least the main project as "."., (*8)
> migrate add .
Removes specified folder (no default) from VERSION.json file., (*9)
Shows both the current VERSION.json and currently installed versions., (*10)
Just shows what is stored in VERSION.json now. This is a default command if migrate is called without any parameters., (*11)
There are two ways to do the deployment with migrate. One way is to run the commands on the local folder on your PC and rely on some third party synchronization tool to copy the changes made to the local files to a remote server. Such tools are: * PhpStorm * WinSCP * FileZilla, (*12)
The other way is to run Mercurial and composer commands directly on the live server so that the server will pull the changes from the repositories. This requires SSH access to the server and SSH client installed on the PC. It also requires public key authentication to the server since otherwise you will be asked to enter your password way too often. At least once for every command., (*13)
When running these commands you switch to a local folder which corresponds to the state of the live server and run synchronization tool in the background. These commands will change the contents of the local files only. All changes to the live server depend on the sync tool (for example PhpStorm)., (*14)
This is not recommended anymore. If you have SSH access to the live server please check the deployment with remote hg commands instead., (*15)
Runs "hg pull" and "hg update -r xxx" on each repository., (*16)
Runs composer install., (*17)
Checks current versions, does install of new versions, composer (call on LIVE)., (*18)
Shows the default pull/push location for current folder. Allows to compare current and latest version., (*19)
Will fetch the latest version available and update to it. Like install but only for the main folder repo (.), (*20)
Runs "hg id" for each repository in VERSION.json. This will replace the VERSION.json., (*21)
Since we have dependant repositories stored in VERSION.json file we can run some Mercurial commands on the specific repository without going to that directory manually. And we can run these commands for all the tracked repositories one-by-one automatically., (*22)
You may specify which repository each command should be run at by typing only part of the repository path., (*23)
> migrate thg nadlib
This will run a command on vendor\spidgorny\nadlib path as "nadlib" matches part of the path., (*24)
Will execute TortoiseHG in a specified folder (use .). Partial match works., (*25)
Shows a changelog of the main project which can be read by humans., (*26)
Only does "hg pull" without any updating., (*27)
Only does "hg pull" without any updating., (*28)
Will commit the VERSION.json file and push., (*29)
Just shows what is stored in VERSION.json now., (*30)
Runs "hg id" for each repository in VERSION.json. This will replace the VERSION.json. This is called before other commands often in order to know the current state of the repositories., (*31)
This is the best part of migrate. Before continue - make sure you can run, (*32)
> ssh live.server.com -i your/public/key.file
without typing your password. All commands below run ssh command like the one above + specify what to do on the live server after connecting to it., (*33)
Another concept is versioning in a subfolder. Migrate will automatically create a subfolder on the live server which corresponds to the revision number of your project in mercurial repository. It's up to you to change your Apache configuration to point to a new location or use RewriteRule to dynamically route user requests to a corresponding subfolder., (*34)
The live server name, live server, (*35)
Will ssh to the live server and create subfolder for current version., (*36)
Will connect to the live server and ls -l., (*37)
Will connect to the live server and clone current repository., (*38)
Will run hg status remotely, (*39)
rpull Will pull on the server rupdate Will update only the main project on the server. Not recommended. Use rinstall instead. rinstall Will update to the exact versions from VERSION.json on the server. All repositories one-by-one. Make sure to run rpull() first. rcomposer Will run composer remotely rdeploy Will make a new folder and clone, compose into it or update existing rvendor Trying to rcp vendor folder. Not working since rcp not using id_rsa? dump Just shows what is stored in VERSION.json now check Runs "hg id" for each repository in VERSION.json. This will replace the VERSION.json, (*40)
Deployment and migration using Mercurial and ssh
Unlicense