Adding Compass to a local dev environment with Lando

<p><span class="drop-cap">I</span> have a very short tale to tell today. One of my coworkers asked me to set up a Lando dev environment for him, with the possibility to run Compass commands from within the Lando containers. </p> <p>This makes sense, either with Compass or anything else, it’s good to have the functionality in a Docker container. All developers will have the same version of the tool and they won’t be forced to install it separately in their computers. Yay!</p> <p>So here’s how I did it.</p> <p>I first took a look at how our designer (the only one with the Compass tool installed) compiled the Sass into Css files. He was indeed using Compass. So I googled “how to install compass on linux”, and I found out I needed to install Ruby first. Long story short, I listed everything I needed to install and tried it first from inside the Lando containers.</p> <p>I’ll explain my train of thought, since I think it might help you understand how I got it working.<br /> I can google how to install anything on a Linux computer, but I have to translate that to our Lando file somehow. As a first step, and to figure out what I was dealing with, I accessed the terminal of my container as root by running</p> <pre> <code class="language-bash">lando ssh -u root</code></pre> <p>I had to do it as root, since I was going to try installing a bunch of stuff.</p> <p>After that, I tried every one of all the needed steps, as if it were my linux computer.</p> <pre> <code class="language-bash">apt update -y apt install ruby-full -y gem install compass</code></pre> <p><span><span><span><span><span><span>Since those succeeded, I went ahead and added them to a script, to be able to run them automatically after building Lando (</span></span></span></span></span></span><a href=""><span><span><span><span><span><span><span><span>here is some doc about that</span></span></span></span></span></span></span></span></a><span><span><span><span><span><span>).</span></span></span></span></span></span></p> <h3><span><span><span><span><span><span>On how I did that</span></span></span></span></span></span></h3> <p><span><span><span><span><span><span>The equivalent of going in manually through the ssh command and installing things, would be to call the script with the build_as_root build step, like this:</span></span></span></span></span></span></p> <pre> <code class="language-yaml">services: myservice: build_as_root: cmd: /app/ </code></pre> <p><span><span><span><span><span><span>Mainly because it runs </span></span></span></span></span></span><span><span><span><span><em><span>after</span></em></span></span></span></span><span><span><span><span><span><span> Lando has created the containers and also because it runs as </span></span></span></span></span></span><span><span><span><span><em><span>root</span></em></span></span></span></span><span><span><span><span><span><span>.</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>As you can see, I’m just calling a script (</span></span></span></span></span></span><a href=""><span><span><span><span><span><span><span><span>which is the recommended way to run these kind of commands</span></span></span></span></span></span></span></span></a><span><span><span><span><span><span>) and in that script, I just entered all the same commands I tested manually from inside the container (plus another few):</span></span></span></span></span></span></p> <pre> <code class="language-bash">#!/bin/bash # Install ruby apt update -y apt install ruby-full -y #Install Compass gem install compass #Install Compass dependencies gem install sass-globbing gem install susy gem install breakpoint gem install compass-rgbapng </code></pre> <p><span><span><span><span><span><span>After this, I rebuilded my containers by running</span></span></span></span></span></span></p> <pre> <code class="language-bash">lando rebuild -y </code></pre> <p><span><span><span><span><span><span>And paid careful attention to the output in the console. No errors, seemed it was good to go. Just be sure, I accessed the container via ssh once more and checked if ruby and compass were installed</span></span></span></span></span></span></p> <p><img alt="Test your ruby and comppas instalaltion" data-entity-type="file" data-entity-uuid="f088f666-e7e3-4ff8-82a0-2620cf6ee27c" src="/sites/default/files/inline-images/Screen%20Shot%202020-09-13%20at%2015.00.39.png" /></p> <p><span><span><span><span><span><span>So far so good!</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>Finally, I added a </span></span></span></span></span></span><a href=""><span><span><span><span><span><span><span><span>tooling</span></span></span></span></span></span></span></span></a><span><span><span><span><span><span> alias to be able to run Compass from my computer (instead of going into the container as I showed you earlier). Here’s my .lando.yml file:</span></span></span></span></span></span></p> <pre> <code class="language-yaml">name: my_project recipe: drupal7 config: webroot: docroot services: appserver: build_as_root: cmd: /app/ tooling: compass: service: appserver description: Runs compass within Lando. cmd: compass level: app </code></pre> <p><span><span><span><span><span><span>And now I have it, I just have to run </span></span></span></span></span></span></p> <pre> <code class="language-bash">lando compass compile </code></pre> <p><span><span><span><span><span><span>From the directory with the config.rb file (as I would normally do with Compass as well).</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>I hope this helps anyone!</span></span></span></span></span></span></p> <p><span><span><span><span><span><span>Have a great day!</span></span></span></span></span></span></p> <p> </p>