Serbiaaaaa ! – Commerce Guys – Why do I care about best practices?



Serbiaaaaa ! – Commerce Guys – Why do I care about best practices?

0 0


slides-drupal-best-practices

Slides about best practices in Drupal using Reveal.js.

On Github GuGuss / slides-drupal-best-practices

Serbiaaaaa !

Augustin Delaporte

@GussTissier

Commerce Guys

Paris | London | Ann Arbor, MI

Creators of Drupal Commerce

Creators of Platform.sh

Why do I care about best practices?

The Chinese experience...

Developed multiple Drupal and Drupal Commerce sites

Managed the development of Commerce Kickstart v2

Managed the development of Commerce Guys Marketplace

Used those best practices on my own e-commerce website

Couple de Huit

What did I learn?

It’s easy to maintain a Drupal site

Small websites are built the same way as big websites

Making architectural changes is simple on a Drupal site

It's all about tools and techniques

TOOLS

Version control

Easily save and revert your work

Manage projects with multiple developers

Use Git

Great flexibility on branching and merging

Code review

Audit specific pieces of code

Track down problems that might arise

We use Github

Powerful *pull request* and *fork* workflow

Drush

Drupal without Drush is like life without mobile phones... you know you managed just fine but now you just can't imagine how

Drush

  • Login MySQL database: drush sql cli
  • Install the site from scratch: drush si
  • Run cron: drush cron
  • Run pending database updates: drush updatedb
  • Revert/update features: drush fra
  • Run migrations: drush mi
  • ...

Development Modules

  • Devel
  • Drupal for firebug
  • Coder
  • XDebug

Automated testing

  • Simpletest
  • Behat/Mink
  • Selenium

Preformance testing

  • JMeter
  • Apache Bench

Now what?

TECHNIQUES

Architectural plan

Think hard before clicking

Development environments

Everyone should be able to test in live conditions

Installation profile

Install from scratch at any time

Whaaaaat?

Your own profile

Need a starting point?

Configuration ==> files

Features

drush feature-revert

Migrate

drush migrate-import

An example

Updates

drush updatedb

Make files

Forget about randomly patched modules in the repository

What you will get

Predictable development workflow

Reusable components across projects

Better tracking of configuration changes

Better integration with automated testing

In the past

                
    #!/bin/bash
    set -xe

    if [ ! -d marketplace/.git ]; then
      git clone git@github.com:commerceguys/marketplace.git
    fi

    # Go to Marketplace to run backups.
    run-on-host marketplace_prod@marketplace.commerceguys.com << "END"

    # Backup files and database (just in case).
    export DIRDATE=`date '+%Y-%m-%d---%H-%M-%S'`
    export BACKUPDIR=$HOME/jenkins-backups/marketplace-$DIRDATE
    mkdir -p $BACKUPDIR
    cp -RL www $BACKUPDIR/www
    cd www
    drush sql-dump > $BACKUPDIR/marketplace-$DIRDATE.sql

    # End of backup script.
    END

    cd marketplace

    # Fetch the new commits and checkout.
    git fetch
    git reset "origin/master" --hard

    cd ..

    # Copy to marketplace
    rsync -a --delete marketplace/ marketplace_prod@marketplace.commerceguys.com:blimp
    run-on-host marketplace_prod@marketplace.commerceguys.com << "EOF"
    #!/bin/bash
    set -xe

    # Maintenance mode
    unlink live
    ln -s marketplace-maintenance live
    sudo /etc/init.d/php5-fpm restart
    cd www
    drush vset maintenance_mode 1

    # Stop the Advanced Queue daemon.
    sudo sv stop advqueue-marketplace

    # Build website.
    cd ../blimp
    export BUILD_ROOT=".."
    chmod 755 ../www/sites/default
    ./scripts/build

    cd ../www

    # Remove all .txt files
    find . -name "*.txt" | xargs rm

    # Rebuild registry
    drush -y rr --no-cache-clear

    # Update database.
    drush -y updatedb --uri=https://marketplace.commerceguys.com

    # Clear drush caches.
    drush cc drush

    # Clear all caches.
    drush cc all

    # Revert features.
    drush -y fra

    # Rebuild indexes.
    drush -y sapi-c
    drush -y sapi-i productdisplay 0
    drush -y sapi-i licenses 0
    drush -y sapi-i delivery_partner 0

    # Go live.
    drush vset maintenance_mode 0
    sudo sv start advqueue-marketplace
    cd
    unlink live
    ln -s www live
    sudo /etc/init.d/php5-fpm restart

    EOF
                
              

Now

github.com/GuGuss