Better (S)FTP deployment with DPLOY
Deployment is the process in which we transfer the local code to staging or production environment. That process can be carried out in many forms and ways. Often I see people using ordinary FTP clients to deploy the code to the remote host because it’s maybe a shared host or perhaps it doesn’t provide a SSH access. Perhaps it hasn’t got a set of certain tools (like Git) that a developer might need. So what’s the solution? DPLOY.
DPLOY is a open source project that hooks onto your local Git repository. It uses it to deploy new or modified files to the remote host via the FTP or SFTP. Since this is built in node.js you’ll first need to install the node.js itself along with node package manager. After that you can use the node package manager to install DPLOY (globaly):
Great. Now all you have to do is to go to your project repository, create a git repository (if you don’t already have one) and do an initial commit (if you don’t have any commits). After that you can do a local dploy installation which will create a default dploy.yaml configuration file. In that file you can define multiple environments of your app and credentials that are needed to deploy the application to that particular environment. Installation is carried out with the following command:
That’s it. Now you’re able to deloy your app in seconds just by typing the dploy command and by specifying the environment name to which you wish to deploy the code to:
Every time you invoke the dploy command it will do a git diff of the current commit and the last commit that was deployed to the remote host. For that purpose DPLOY uses the .rev file which is stored on the remote host and a temporary .rev file that will be created (and deleted) on your local development environment. If you open that file on the remote host you’ll find a commit hash of the last deployed commit. That hash is being used by the git diff command so try not to delete that file. If you have only one environment you can also write the dploy command without the environment name.
Another neat thing is that you can restrict which branch can be deployed to a specific environment. That can be particularity handy when you have two separate branches for staging and production environments. You can specify the branch name by adding the branch attribute to the dploy.yaml file:
With DPLOY you can make your deployments much faster and even safer since:
- You don’t need to look at which files you’ve modified since the last deployment
- You don’t have to worry about deploying files that should not be deployed
- You wont forget to deploy certain file or a certain set of files
- You wont deploy from wrong branch by accident (which, trust me, happens)
To recap, DPLOY is a simple open source automation tool that can be used for deployment purposes. Also it can deployed to almost any environment that you can imagine since it needs only (S)FTP access. With DPLOY you can ditch the old-school FTP clients. If you want to find out more about this project, check out it’s official github page where you can find even more useful options.