Moving to VIM

After 30 years in front of the keyboard, I decided to refine my craft and learn to touch type. It’s been about a month, and I’m improving. Keeping my fingers on “home keys” got me thinking about how often I remove them to touch the mouse. All these keys at my finger tips and they are almost useless for navigation within a file. Hello Vim.

I’ve used Vim for editing text files on a server for years. I knew the basics: insert mode, save, and exit. One of the powerful features of Vim is its modes. The two primary modes are Normal and Insert. When in normal mode, the keys are used to navigate, copy and paste, find, and much more. You don’t need to mouse or cursor keys; in fact, you shouldn’t be using them. To modify text, you enter insert mode, which is the only mode in most text editors. The capabilities of Vim are mind-blowing.

To get started, I watched several videos on Youtube and began a slow transition. While it’s a gradual transition, you will see the benefits quickly. I hope to replaced VS Code with Vim someday. I love the idea of using the same tool proficiently on a desktop, VPS, or Raspberry Pi.

How to get started

My recommendation:

  1. Vim Mode – using your existing IDE, such as VS Code, adding a Vim extension to give you basic Vim workflow and key bindings. This is a good bridge from where you are today to Vim 100%.
  2. Six Part Series – Recently, Youtuber, The Primeagan, released an excellent six part series to learn Vim. His videos are educational and entertaining. Watch video 1 and don’t moved to the second video until you don’t need to think about basic navigation keys. I’m not through them all yet.
  3. Explore – There are many Vim tutorial available online. You them to explore the capabilities of Vim to do things easier and faster.

Faster Drupal Development on Linux

Local Drupal development has moved to docker based environments with solutions like Lando and DDEv. With these tools, it’s fast and easy to spin up a local environment and manage many projects. The days of MAMP and WAMP are (long) gone.

Here’s the problem, Mac OS is the dominant development platform for Drupal developers, and Docker runs terribly on it. Docker interacts differently with macOS than it does with Linux. The source code on the host computer is shared with Docker containers. The multiple layers of communication between Docker and the macOS file system make file-sharing very slow. While Docker’s direct access to the Linux file system makes it very fast. This video, Improving Docker Desktop File Sharing Performance, from DockerCon 18 describes this issue in detail.

The file-sharing performance issue became apparent when working with a colleague to set up a new Drupal 8 website build. I was shocked to see the local build process taking over 8 minutes on my colleague’s computer and less than 30 seconds on my computer.

Benchmarks

In an unscientific way, with some help from my friends, I tested the build process on a few Macs and Linux computers with different hardware specs. Each computer had Docker and Lando installed. The website is a Drupal 8 Standard profile with Acquia’s BLT. The test is simple, run the BLT artifact build, blt artifact:build

Below are the results of this test.

ComputerSpecsOSArtifact:build
ThinkPad T420 (2011)i5 (2 cores), 8GB RAM, SSDLinux (Endevour OS)20 seconds
Custom Build (2020)Ryzen i7 (8 cores), 32GB, SSDLinux (Endevour OS)7 seconds
Macbook Air (2018)i5 (2 cores), 8GB RAM, SSDmacOS Catalina8+ minutes
MacBook Pro (2015)i7 (4 cores), 16GB RAM, SSDmacOS Mojave6 minutes

Solutions

There are some potential solutions. Lando has an undocumented Mac-only feature called “Turbo Mode”. Reviewing the issue thread, there are mixed results with this implementation. Turbo Mode had little impact on my test case shaving off 30 to 60 seconds. A 5% to 10% improvement is good, but when comparing it to performance on Linux, there is no practical improvement. Others have seen better improvements with Turbo Mode. This approach is easy to implement and worth exploring, but Turbo Mode hasn’t made it’s way into Lando as a supported feature. Use with caution.

Some tweaks can be made to your Docker configuration. Increasing the default RAM usage from 2GB to 4GB is a starting point. You can also limit the number of shared folders Docker watches, by default, the entire /Users folder is included. I tested the memory upgrade and limited the shared folders to only the necessary application folders. Similar to the results with Turbo Mode, they were minimal for my test case. You may have more promising results. There are many online resources with recommendations to improve performance, search “Docker Mac performance”.

The beauty of using Lando is simplicity, which starts to diminish with lots of OS based tweaks. I suspect more research and testing could result in better performance on Mac. BUT, using Linux for Drupal development with Docker will get you the best performance by far, with ease. It’s that simple.

Drupal 8 and Lando

Overview

Below are steps to setup a local Drupal 8 composer based environment using Lando.

Prerequisites

You need to have Lando installed using these instructions.

Steps

Create a local folder. <app> will be the name of your application folder and Lando instance.

mkdir <app>

Position your working directory as your new folder

cd <app>

Initialize Lando and answer a few questions. This utility creates a .lando.yml file in your working directory. When you start Lando in the next step, this file is used to define the Lando configuration.

lando init
Choose: current working directory
Choose: Drupal8
Enter for webroot: web
Enter for app: <app>

Start Lando

lando start

Install Drupal code using composer. Note – Drupal is being install in a Docker container, not on your local computer.

lando composer create-project drupal-composer/drupal-project:8.x-dev blah -n

The above command uses composer to install Drupal and it’s dependencies into a folder called ‘blah’. Now, the files/folders in ‘blah’ will be move up one level into your directory and the ‘blah’ folder will be removed.

mv blah/* .
mv blah/.* .
rm -rf blah

Rebuild Lando containers.

lando rebuild -y

On a success rebuilt on Lando, it’s time to install Drupal 8. Goto the local URL for your Drupal 8 website.

https://<app>.lndo.site  

Follow the steps in the Drupal installation Wizard. When the database page appears, use ‘drupal8’ for the database name, username and password. Also, use ‘database’ for the host name (under the Advanced settings.

You should be up and running,

Updates

12/10/2019 – As of Drupal 8.8.0, Composer project templates are now available as part of Drupal core. The composer create-project command was updated to reflect this change.

$100 Development Laptop

At the beginning of 2018 I switch to Linux as my ‘daily driver’. I have a desktop and laptop from System76 running Pop_OS!. I’m super happy about that switch.

Linux is everywhere; from Rasperry PIs to supercomputers. It runs nuclear submarines, refrigerators, air traffic control and my Drupal development environment. It can run fantastically on modern hardware and bring life back to the forgotten computer in the closet.

I wondered if it was possible to configure an under $300 laptop for Drupal development. I started by looking at low-end consumer laptops. Best Buy has Intel and AMD laptops, 4-8GBs Ram with an SSD, preinstalled with Windows, on sale in that price range. I asked for recommendations in an online Linux community. I was advised by many not to buy consumer ‘junk’, but instead, look for used enterprise-class laptops on Ebay in the same price range or less. In my research, I found a cult-like following for the Thinkpad T420, a laptop released in 2011 (see video The $110 Lenovo Thinkpad T420, a Laptop with a Legacy). It’s known for its durability, performance and ‘old-school’ keyboard. That seemed like a reasonable place to start.

Acquisition

The price range on eBay for a T420 with an SSD was between $125 – $225. I found one without an HD (or SSD) or power cord. With those two essential parts missing, I was highest bigger at $45 (plus 12.97 shipping). This T420 has as i5-2520M @ 3.200GHz with 8GB Ram. I bought a 240GB SSD for $28.95 and power cord for $10.99. At worse case, this would be a failed $97.91 experiment.

ThinkPad T420

You never know what you’re going to get with used equipment. The Thinkpad was in surprisingly good shape. As promised, everything was in working order with normal wear for a nine-year-old computer. I unboxed it, slid in the SSD and had Manjaro Linux installed in 10 minutes. Manjaro is my first experience with a Linux distribution outside of Pop_OS!.

Infamous Linux Wifi Issue?

I had one hiccup, the wireless card wouldn’t work. It wasn’t a big problem because the T420 has lots of ports, one of which is ethernet (take that Apple). I tried to get wireless working late into the evening, then decided to install the distribution I was familiar with, maybe it was a software issue. I installed POP_OS! and immediately identified the issue from a message, something like “wireless hardware switch is off”. What!!?? Sure enough, there’s a small hardware switch on the side of the T420 to turn off blue tooth and wireless. This problem was undoubtedly not software or hardware related. I decided to leave Pop_OS! running, I will experiment with Manjaro at another time.

Wifi Hardware Swtich

Drupal Development

The primary software requirements for my Drupal development includes web browsers (Chrome and Firefox), Lando (and required software) and VS Code (IDE). While there are many other tools I use day to day, those are the must-haves. Outside of Docker needing some extra attention, loading this software was straight forward. I’m was up and running in short order.

Observations

After a month of using the T420 as a second laptop for Drupal development and general computing tasks, my observations are:

  • The Thinkpad T420 is a solid computer. It feels and is a quality build.
  • I like the feel of the classic, “clicky clack” keyboard. It’s easy to use.
  • I missed a laptop with lots of ports and single purpose buttons
  • This computer is fast, not just fast enough. While I didn’t push the limit with lots of containers running at the same time I’m editing audio on a Zoom call, it performs well.

Summary

This T420 running Linux is at least a solid backup computer, and maybe a daily driver for most developers. It feels good to sit behind a classic laptop, running a current OS, while building a modern website. Maybe it’s like cruising down the road in a 1964 Mustang. Is it a fluke that I was able to put this system together for under $100? No. I’ve bought two more and have done the same thing.

Backstop JS and Lando

I’ve recently started using Backstop JS for visual regression testing. You can add the following settings to your Lando configuration, .lando.yml, to include Backstop JS.

services:
   node:
     type: node:10
     globals:
       backstopjs: "latest"
     command: npm start
     run_as_root:
       - apt-get -y update && apt-get -y install software-properties-common
       - wget https://dl-ssl.google.com/linux/linux_signing_key.pub && apt-key add linux_signing_key.pub
       - add-apt-repository "deb http://dl.google.com/linux/chrome/deb/ stable main"
       - apt-get -y update && apt-get -y install google-chrome-stable
 tooling:
   backstop:
     service: node

You will need to use the .internal URL from Lando to access the local website. For example:

  "scenarios": [
    {
      "label": "Homepage",
      "url": "http://appserver_nginx.your-site-name.internal"
    }

The backstop commands will be run through Lando tooling:

lando backstop reference
lando backstop test