How to deploy on multiple servers a project without a single line of code!

Romaric Paul
HackerNoon.com
5 min readMar 19, 2018

--

This post require to know how write and read the .yaml syntaxe only : easy ! ;)

What we need ?

  • A terminal with php on your local machine
  • A git repository for your project

What we use ? automate !

This is the official website of automate : https://automate-deployer.com/

Automate

It’s time to start !

First, the .automate.yml file

First, add the .automate.ymlfile at the root of your project (not the public directory), write this lines :

Okay so what we have write here ? It’s just setting, not coding ;)

Here, we just wrote the address of your project, for example here a sample project with Symfony4.

Here, we defined all servers we want to deploy our project. So as you can see, 2 servers are defined : development and preproduction one.

For each server we defined which git branch is used via default_branch ; so for the developmentserver I want to use the master branch and for thepreprod server I want to use thepreprod branch.

We have to defined how many maximum releases we want to stock on each server. 2 seems good because if you get some bug after a new deployment you can rollback with one command, we will see later.

Here, we defined all servers by platform, In this case we have just one server / platform but you can easely add 2 or 3 servers to deploy your project.

For each server you have to define :

  • Host
  • User (with ssh access)
  • The path of you project on the remote server
  • For the password, it’s not a good practice to write this one here in this file, so that’s why we are using % each side, because when you will start the deployment the terminal will ask you to enter the right password.

Here, we defined all files shared for all releases, in this case this environment file is for Symfony which contains all the necessary environment variables. So no matter which release is current there is just one config file for all my releases !

Here, same story with folders. We defined all folders that we need for all releases. The best example is the upload directory.

Here, it’s the list of commands lines that your project need to be deploy perfectly. There are 3 events availables with automate : pre_deploy , on_deploy and post_deploy all are well explain here :

https://automate-deployer.com/doc

So now your .automate.yml file is ready !

Second, install the automate.phar

Go to your root path of project

You can download the latest version of Automate with the following command:

Now you should get something like that :

Sample with Symfony4 project

It’s time to deploy !

Go to your root path of project and launch automate !

start the deployment

Enter the dev_password and enjoy the show ! ;)

You should get something like that :

End point of the deployment

What happen to our server ?

Well if you go to our server, we should get something like that :

our development server remote
  • current directory is a symbolic link to the lastest release
  • releases directory contain all last releases (depend the max_releases number you set in the .automate.yml file)
  • shared directory contain all folders shared between every releases

If we go to the shared directory you can see :

the shared directory

Which contain the “real” folders and files. On the other hand if we go to the current directory you can see :

The .env file is a symbolic link to the real file .envwhich is in the shared directory.

So as you can see, we deployed without a single line of code ! Automate is very easy to use and to set. Automate has a lot of plugins by default, you can see all of this to the official documentation :

https://automate-deployer.com/doc

To conclude, we can now imagine to use automate and gitlab with an automatic deployment on each merge request ! ;)

Thanks to Solène Louvrier & Nicolas Legendre for rereading. :)

--

--