Setting Up Additional Services

Lando allows you to override and add services in addition to the ones it comes with via recipes. In this tutorial we will...

  • Override the services provided by a recipe
  • Add additional services to a recipe

Overriding Recipe Services

Consider the starting .lando.yml file.

name: addservices
recipe: drupal8
config:
  php: '7.1'

Let's say we want to add some global composer dependencies, use a custom php.ini that is unique to our app and run an automatic composer install build step when we start up or rebuild our app.

First, run lando info to see the names of the services provided by the drupal8 recipe. Generally, you will have an appserver and database container. Now let's update our .lando.yml file and override the appserver service, making a change to install phpunit. Run lando rebuild for our changes to take effect.

services:
  appserver:
    composer:
      phpunit/phpunit: '*'
    build:
      # Uncomment this when you have a composer.json in the root directory
      # - cd $LANDO_MOUNT && composer install
    config:
      conf: php.ini

Now let's override our database service to lock down its external port and to change the database credentials. Again, lando rebuild for the changes to apply.

services:
  appserver:
    composer:
      phpunit/phpunit: '*'
    build:
      # Uncomment this when you have a composer.json in the root directory
      # - cd $LANDO_MOUNT && composer install
    config:
      conf: php.ini
  database:
    portforward: 1337
    creds:
      user: tswift
      password: troubletroubletrouble
      database: songz

Adding Additional Services

Let's say our app requires more services and devtools. Specifically we need a redis caching backend, an elasticsearch index, node based cli tools and mailhog to test out our campaigns. You can easily add any of the supported services to your .lando.yml to give any of the default recipes a little more muscle.

# Overriden recipe services
services:
  appserver:
    composer:
      phpunit/phpunit: '*'
    build:
      # Uncomment this when you have a composer.json in the root directory
      # - cd $LANDO_MOUNT && composer install
    config:
      conf: php.ini
  database:
    portforward: 1337
    creds:
      user: tswift
      password: troubletroubletrouble
      database: songz

# Additional services
  cache:
    type: redis
    persist: true
  search:
    type: elasticsearch:5.4
  mailhog:
    type: mailhog
    hogfrom:
      - appserver
  node-cli:
    type: node:6.10
    globals:
      gulp-cli: "latest"

Full Example

# Example for overriding and augmenting a d8 recipe with additional things
name: addservices

# Start with the normal drupal recipe running php 7.1
# See: https://docs.devwithlando.io/recipes/drupal8.html
recipe: drupal8
config:
  php: '7.1'

# Add routing to mailhog ui
# See: https://docs.devwithlando.io/config/proxy.html
proxy:
  mailhog:
    - mailhog.addservices.lndo.site

# Service overrides and augments
# See: https://docs.devwithlando.io/config/services.html
services:

  # Override the appserver with composer globals, build step and custom php.ini
  # See: https://docs.devwithlando.io/services/php.html
  appserver:
    composer:
      phpunit/phpunit: '*'
    build:
      # Uncomment this when you have a composer.json in the root directory
      # - cd $LANDO_MOUNT && composer install
    config:
      conf: php.ini

  # Override the default database credentials and lock down the exposed port
  # See: https://docs.devwithlando.io/services/mysql.html
  database:

    # Set a static port
    # This port needs to be free otherwise all hell will break lose
    portforward: 1337

    # Optionally change the default db credentials
    creds:
      user: tswift
      password: troubletroubletrouble
      database: songz

  # Add a caching backend
  # See: https://docs.devwithlando.io/services/redis.html
  cache:
    type: redis
    persist: true

  # Add an indexing backend
  # See: https://docs.devwithlando.io/services/elasticsearch.html
  search:
    type: elasticsearch:5.4

  # Add mailhog capturing
  # See: https://docs.devwithlando.io/services/mailhog.html
  mailhog:
    type: mailhog
    hogfrom:
      - appserver

  # Add node cli
  # See: https://docs.devwithlando.io/services/node.html
  node-cli:
    type: node:6.10
    globals:
      gulp-cli: "latest"

# Add a php unit command and node commands
# See: https://docs.devwithlando.io/config/tooling.html
tooling:
  phpunit:
    service: appserver
    description: "Run PHP Unit tests: lando phpunit"
  npm:
    service: node-cli
  node:
    service: node-cli
  gulp:
    service: node-cli

results matching ""

    No results matching ""