Dockerized macOS for CI/CD and Cross-Platform Testing
Hey there! As a software engineer, you're probably used to a lot of different development environments. Sometimes, though, you need to work with macOS-specific tools, frameworks, or even just test your app on a Mac without having a physical one handy. This is where dockur/macos comes in clutch. It lets you run a full-fledged macOS desktop environment inside a Docker container. Think of it as a virtual Mac that you can spin up and tear down with simple Docker commands. This is super useful for
CI/CD Pipelines
You can use it in your automated builds to run tests that are specific to macOS, like testing a mobile app that uses Xcode.
Cross-Platform Development
If you're building a tool that needs to work on Windows, Linux, and macOS, this gives you an easy way to test the macOS part of your code without having to switch machines.
Experimentation
Want to try out a new macOS feature or build tool but don't want to mess with your main development machine? Spin up a container, do your thing, and then delete it. Simple!
Getting started is surprisingly easy. You'll need to have Docker and Docker Compose installed on your machine. The dockur/macos project provides a docker-compose.yml file that makes the setup process almost a one-liner.
First, you'll want to grab the necessary files from the project's GitHub repository. You can do this by cloning the repository.
git clone https://github.com/dockur/macos.git
cd macos
Next, you need to configure the amount of memory and CPU cores you want to allocate to the virtual machine. You can do this by editing the docker-compose.yml file. Look for the qemu service and adjust the -m (memory) and -smp (CPU cores) arguments.
Now, all you have to do is run the container.
docker-compose up -d
This command will download the necessary image, set up the container, and start it in the background. Once it's running, you can connect to the graphical desktop using a VNC client. The docker-compose.yml file exposes the VNC port on 5900, so you can connect to localhost:5900 to see your new macOS desktop!
Let's say you have a shell script, build-for-mac.sh, that uses an app called macOS-tool to build your project. This tool only runs on macOS. Here's a quick example of how you could use a Dockerfile to automate this process.
You'd start by creating a Dockerfile that uses dockur/macos as a base image. This Dockerfile would then install your specific tools and run your script.
# Start with the base macOS image
FROM dockur/macos:monterey
# Set a working directory
WORKDIR /app
# Copy your script into the container
COPY build-for-mac.sh .
# Install a hypothetical macOS-specific tool
RUN /bin/bash -c 'echo "Installing macOS-tool..." && sleep 5 && echo "Done."'
# Run the script when the container starts
CMD ["/bin/bash", "build-for-mac.sh"]
#!/bin/bash
echo "Building project for macOS..."
# Here you would put your macOS-specific commands,
# for example, using a tool that only runs on Mac
/usr/local/bin/macOS-tool build
echo "Build complete!"
To run this, you would build the image and then run the container.
docker build -t my-mac-builder .
docker run my-mac-builder