paint-brush
How to deploy on multiple servers a project without a single line of code!by@romaricp
6,317 reads
6,317 reads

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

by Romaric PaulMarch 19th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This is the official website of automate&nbsp;: <a href="https://automate-deployer.com/" target="_blank">https://automate-deployer.com/</a>
featured image - How to deploy on multiple servers a project without a single line of code!
Romaric Paul HackerNoon profile picture

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 :
































repository: [email protected]:romaricp/kit-starter-symfony-4-docker.gitplatforms:development:default_branch: mastermax_releases: 2servers:dddv-server:host: 10.128.12.12user: devpassword: %dev_password%path: /home/wwwroot/sf4preprod:default_branch: preprodmax_releases: 2servers:pddv-server:host: 10.128.12.13user: devpassword: %preprod_password%path: /home/wwwroot/sf4shared_files:- .envshared_folders:- public/uploadon_deploy:- "composer install"- "setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX var"- "setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX var"- "php bin/console c:c --env=prod --no-debug"post_deploy:- "php bin/console doctrine:schema:update --force"- "php bin/console cache:war --no-debug"

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

repository: [email protected]:romaricp/kit-starter-symfony-4-docker.git

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



















platforms:development:default_branch: mastermax_releases: 2servers:dddv-server:host: 10.128.12.12user: devpassword: %dev_password%path: /home/wwwroot/sf4preprod:default_branch: preprodmax_releases: 2servers:pddv-server:host: 10.128.12.13user: devpassword: %preprod_password%path: /home/wwwroot/sf4

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.






servers:pddv-server:host: 10.128.12.13user: devpassword: %preprod_password%path: /home/wwwroot/sf4

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.


shared_files:- .env

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 !


shared_folders:- public/upload

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






on_deploy:- "composer install"- "php bin/console c:c --env=prod --no-debug"post_deploy:- "php bin/console doctrine:schema:update --force"- "php bin/console cache:war --no-debug"

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

cd /your/path/project

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

curl -LSs https://

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 !

cd /your/path/project

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. :)