Deploying containers in a swarm environment: Drupal Migration

More manuals

Create directories

Export the Drupal files

Find the Document Root path.

cat /etc/apache2/sites-enabled/<nom-web>.conf | grep Document

When you know which directory is the data located in, you have to copy them to the NFS mounting point.

scp -rp DocumentRoot_path/* your_user@server_name.s.upf.edu:/mnt/vmdata/research_group/project_name/html

Copy the .htaccess file:

scp -rp DocumentRoot_path/.htaccess your_user@server_name.s.upf.edu:/mnt/vmdata/research_group/project_name/html

Export the Database

The next step consists of knowing which database and credentials are used by Drupal. settings.php file provides this information:

cat <DocumentRoot>/sites/default/settings.php

$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'db',
'username' => 'user',
'password' => 'password',

'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);

Then, export the database content with "mysqldump" command.

mysqldump -u user -p database_name > DatabaseDump.sql

Finally, copy the .sql file inside the project name folder of the NFS mounting point. Never copy it inside the mysql folder if you have not run the mysql container.

scp -rp DatabaseDump.sql your_user@server.s.upf.edu:/mnt/vmdata/research_group/project_name

Stack Creation

First of all, you will need to obtain the Wordpress version and MySQL version numbers.

<DocumentRoot>/wp-includes/version.php

mysql -V 

Create the stack following these steps.

After that, configure yor Compose file. You need to create two services: HTML and MySQL.

  • HTML:
    • Use the drupal:version image.
    • Define the port number.
    • Point the Drupal installation to /var/www/html.
    • Point the Drupal files to /var/www/html/project_name-files.
  • MySQL:
    • Use the mysql:version image.
    • Add MySQL credentials.
    • Store database data to /var/lib/mysql.

Here, you have the Drupal template. Since it is a .yml file extension, be careful with indents if you copy-paste some parts.

Database Import

Modify the settings.php file. Change 'localhost' to 'db':

$databases = array (
  'default' =>
  array (
    'default' =>
    array (
      'database' => 'db',
      'username' => 'user',
      'password' => 'password',
      'host' => 'db',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

Move the DatabaseDump.sql inside mysql folder when its container is running and all configuration files created. 

mv DatabaseDump.sql  mysql/DatabaseDump.sql

Access to Console and export the database.

mysql -u root -p database_name < /var/lib/mysql/DatabaseDump.sql

Test

Test your application connecting to docker.sb.upf.edu:XXXX, where XXXX is the number port given to you in the CAU. 

If everything works fine, we will change the load balancer configuration to point to this port and all deployed docker servers.