How to deploy to freistilbox from a monorepo
Published 2019-05-25 by Jochen Lillich
Earlier today, I gave a talk at DrupalCamp Scotland about the many advantages of a monorepo over the traditional “multirepo” approach of creating a separate version control repository for each new project. I am immensely grateful for all the praise I got from attendees, both immediately after the talk and later over drinks at Hemma.
Hemma is, by the way, a good after-conference venue even for introverts and non-native speakers like me because it doesn’t get overly loud, which makes participating in conversations quite a bit easier. I enjoyed the evening a lot!
It was when I was leaving the venue that my friend and camp organiser Duncan thought he could throw me off with a question: “Monorepos are all fine and all, but how would I deploy from a monorepo to freistilbox, Jochen?” Apparently, my brain wasn’t on top of its game anymore because he succeeded and instead of “Looks like you didn’t pay attention, buddy!”, I only answered that I’d think about it. Well, so I did and here’s my proper answer!
If you maintain your Drupal application not in its own repository but in a subdirectory of a monorepo (as you should!), there are two simple things you need to do before pushing your code for the first time:
- Ask our engineers to wipe your site repository. That way, you get rid of the content with which we pre-populate new websites by default and that would be (almost) impossible to incorporate into your monorepo.
- Add a step to your deployment script that extracts your Drupal application from everything else before you push it to freistilbox as usual.
Part 1 requires just a short support request from the freistilbox dashboard. Part 2 is a special git command to create what I called a “splitrepo” in my talk. CAUTION: Since this command will significantly alter your repository on disk, I recommend you run it on an extra copy of your monorepo. A CI system would be the perfect place.
$ git filter-branch --prune-empty --subdirectory-filter path/to/drupal
This git command will erase everything from history but the commits that affected your Drupal application. It will also lift your application to the repository root. That’s all there is to do. Now that you’ve turned your monorepo (clone!) into a common Drupal repository, you can
git push and will see your web application live on freistilbox a few seconds later.
Thanks for inviting me to speak at another great DrupalCamp Scotland, Duncan. Let me know if you have any more question about monorepos!