3

A client needs Compass for SASS compilation inside the DDEV-Local web container. How can I get compass in there?

rfay
  • 9,963
  • 1
  • 47
  • 89

1 Answers1

8

Compass requires ruby and rubygems, and rubygems requires a full build environment to build compass. (See http://compass-style.org/install/)

You can get all that with a .ddev/web-build/Dockerfile like this:

RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests build-essential ruby-full rubygems
RUN gem install compass

A slightly smaller approach would be to just add webimage_extra_packages: [ ruby-full, rubygems, build-essential ] to your .ddev/config.yaml and then use ddev exec sudo gem install compass when you need compass.

rfay
  • 9,963
  • 1
  • 47
  • 89
  • Thanks for this solution. Regarding the "slightly smaller approach", would it be useful/recommended to add `sudo gem install compass` in the `post-start` hook of the `.ddev/config.yaml` file? – Watergate Jan 14 '21 at 14:43
  • If you do something like that as a post-start hook, it has to happen on every start. That's the only issue. But it would certainly work. – rfay Jan 14 '21 at 15:13
  • @rfay Is there something like a post-build hook? There's already a way for additional apt packages for the build to be specified in config.yaml, so it'd be nice if there was a way to put the post-build scripts that only need to be run once in there, too. – mbomb007 Mar 16 '21 at 19:32
  • ddev itself doesn't have any concept of "build", so there's no post-build hook. However, the sky's the limit in creating your own scripts. Lots of things check on start to see if something needs to be done and then do it. You could do the same. For example, this snippet only loads a db if it's empty, it's a similar concept, https://github.com/drud/ddev-contrib/tree/master/hook-examples/import-db-if-empty – rfay Mar 17 '21 at 13:05