Building a iOS app with Fastlane inside Docker

K.. picture K.. · Jan 3, 2018 · Viewed 16.1k times · Source

I'm trying to streamline my iOS development builds and read about Docker.

If I understood it right, I could create an image that would include all the dependencies and my fellow devs could just pull it and build inside it.

Point is now, does this also work with Fastlane (which uses the Xcode cli tools I think) and "Docker for Mac"?

Also, I'm using React-Native, which seems to start a second process for bundling the JavaScript that will be included in the native build later and I read Docker only allows one process, is this a problem?

Answer

milch picture milch · Jan 3, 2018

The problem with using Docker is that even if you use Docker for mac, you won't have access to macOS-based images. Docker runs in a lightweight virtual machine called xhyve - at least if you install docker via the Docker for Mac package - that runs Linux on your mac.

Essentially what this means is that your docker container is going to be limited to non-Xcode functionality. Here's what you definitely won't be able to do, at least not without a non-trivial amount of work:

  • Compile your app's native code
  • Take screenshots of your app or run your app in the Simulator
  • Signing the finished app with Apple's codesign

Here's things that you could potentially use your docker container for:

  • Building the JS code (I assume, since RN should work on Linux)
  • Uploading your app with iTMSTransporter (i.e. using fastlane's deliver)
  • Downloading/Creating certificates, provisioning profiles and push certificates (i.e. fastlane's match, cert, pem and sigh)
  • Working with git

All in all you're probably going to be very limited. Instead, it would be advisable to use things like Gemfile and Brewfile to list all your dependencies, and have a small setup.sh script that runs brew bundle and bundle install to install them on your colleague's machines. You can also set it up to run those during building (with Xcode's script build phases), so that no one can accidentally forget to install something that is needed for the build.

That being said, there is a fastlane docker image that is being worked on here that is also available on the Docker Hub. Note that it has only ever been tested to run the fastlane tests (that don't depend on macOS-only software), so it doesn't actually claim to run fastlane reliably.

I read Docker only allows one process

Docker allows multiple processes, it just doesn't allow more than one main process. If your main process stops everything else and the container stops with it. If you just want to use it to install dependencies so that you can run one-off commands that use them, instead of hosting a long-running service, you can always do that by using docker run:

docker run <repo/image:tag> <your_command>

Or launch an interactive shell into the container:

docker run -it <repo/image:tag> /bin/bash