Integrate macOS in CI pipelines using AWS CodeBuild | Amazon Web Services

NewsIntegrate macOS in CI pipelines using AWS CodeBuild | Amazon Web Services

AWS CodeBuild Now Supports macOS: A Comprehensive Guide for Developers

Starting today, developers can now build applications on macOS using AWS CodeBuild. This significant update allows for the creation of artifacts on managed Apple M2 machines running macOS 14 Sonoma. AWS CodeBuild is a fully managed continuous integration (CI) service that compiles source code, runs tests, and produces ready-to-deploy software packages.

The Need for macOS in Development

Building, testing, signing, and distributing applications for Apple systems (iOS, iPadOS, watchOS, tvOS, and macOS) requires the use of Xcode, Apple’s integrated development environment (IDE), which runs exclusively on macOS. When developers build for Apple systems in the AWS Cloud, they typically configure their CI/CD pipeline to run on Amazon Elastic Cloud Compute (Amazon EC2) Mac instances.

Since the launch of Amazon EC2 Mac in 2020, AWS has been working closely with customers across various industries to help them configure and optimize their pipelines on macOS. A typical pipeline might look like this: a new commit or pull request on the source code repository triggers scripts to configure the environment, build and test the application, and eventually deploy it to App Store Connect.

Challenges with EC2 Mac Instances

While Amazon EC2 Mac simplifies the management and automation of macOS machines, it presents two main challenges:

  1. Preparing the Amazon Machine Image (AMI): A minimum build environment requires Xcode, but many organizations also need to install Fastlane, Ruby, and other development tools and libraries. Multiple build environments are often required for different combinations of macOS and Xcode versions.
  2. Scaling the Build Fleet: Large organizations may have hundreds or thousands of builds per day, requiring dozens of build machines. Scaling in and out of that fleet helps save on costs. EC2 Mac instances are reserved for dedicated use, meaning one instance is allocated to one dedicated host, making scaling a complex task.

    Introducing CodeBuild for macOS

    To address these challenges, AWS has introduced CodeBuild for macOS. This service leverages the recently introduced reserved capacity fleet, which includes instances powered by Amazon EC2 and maintained by CodeBuild. Reserved capacity fleets consist of dedicated instances ready to process builds or tests immediately, reducing build durations. However, these machines will continue to incur costs as long as they are provisioned.

    Features of CodeBuild for macOS

    • Standard Disk Image (AMI): CodeBuild provides a standard disk image preinstalled with Xcode, Fastlane, Ruby, Python, Node.js, and other popular tools. The full list of installed tools is available in the AWS documentation. Over time, additional disk images with updated tools will be provided. Custom disk images can also be used.
    • Auto Scaling: CodeBuild makes it easy to configure auto scaling. Simply specify the desired capacity, and AWS manages the rest.
    • Cost Management: Reserved fleets are charged for the time the machines are reserved, even when no builds are running. This follows the Amazon EC2 Mac 24-hour minimum allocation period, as required by Apple’s Software License Agreement for macOS.

      How to Use CodeBuild for macOS

      Let’s walk through the process of creating a CI/CD pipeline using CodeBuild for macOS with a pet project: getting started with AWS Amplify on iOS.

  3. Create the Build Project: Open the AWS Management Console, select CodeBuild, and click "Create project." Enter a project name and configure the connection to the source code repository (e.g., GitHub).
  4. Create the Dedicated Fleet of Machines: Select "Reserved capacity" as the provisioning model and create a fleet. Enter a compute fleet name, select macOS as the operating system, and specify the memory, vCPUs, and number of instances needed.
  5. Configure Build Triggers: Add build triggers to start the build every time a commit or pull request is sent to the project on GitHub.
  6. Add a Pipeline Definition File: Include a buildspec.yaml file in the project to orchestrate the build commands.

    Here’s an example of a buildspec.yaml file:

    “`yaml
    version: 0.2

    phases:
    install:
    commands:

    • code/ci_actions/00_install_rosetta.sh
      pre_build:
      commands:
    • code/ci_actions/01_keychain.sh
    • code/ci_actions/02_amplify.sh
      build:
      commands:
    • code/ci_actions/03_build.sh
    • code/ci_actions/04_local_tests.sh
      post_build:
      commands:
    • code/ci_actions/06_deploy_testflight.sh
    • code/ci_actions/07_cleanup.sh
      artifacts:
      name: $(date +%Y-%m-%d)-getting-started.ipa
      files:

      • ‘getting started.ipa’
        base-directory: ‘code/build-release’
        “`

        Commit and push this file to the GitHub repository. The build will start automatically, and you can monitor its progress in the AWS Management Console.

        Testing and Deployment

        Once the build is successful, you can see the iOS application IPA file uploaded to an S3 bucket. The final build script uploads the binary to App Store Connect, making it available in the TestFlight section of App Store Connect.

        Things to Know

      • Initial Preparation Time: It takes 8-10 minutes to prepare an Amazon EC2 Mac instance for the first build. Any builds submitted during this time are queued and processed once the machine is ready.
      • Shared Fleets: A fleet of machines can be shared across CodeBuild projects on your AWS account. Only CodeBuild can access these machines.
      • Cache Mechanism: CodeBuild cleans the working directory between builds but allows using the local cache mechanism to quickly restore selected files.
      • Custom Build Images: Ensure custom build images are built for a 64-bit Mac-Arm architecture and install the AWS Systems Manager Agent (SSM Agent). The AMI must be available to the CodeBuild organization ARN.

        Availability

        CodeBuild for macOS is available in the following AWS Regions: US East (Ohio, N. Virginia), US West (Oregon), Asia Pacific (Sydney), and Europe (Frankfurt).

        Conclusion

        AWS CodeBuild’s support for macOS is a significant advancement for developers working on Apple systems. By simplifying the configuration and management of macOS build machines and providing robust scaling options, AWS CodeBuild for macOS offers a powerful solution for continuous integration and deployment. Get started today by creating your first CodeBuild project on macOS.

        For more details, visit the AWS CodeBuild page.

        Written by Sebastien Stormacq, Senior Developer Advocate at AWS. Follow him on Twitter @sebsto.

For more Information, Refer to this article.

Neil S
Neil S
Neil is a highly qualified Technical Writer with an M.Sc(IT) degree and an impressive range of IT and Support certifications including MCSE, CCNA, ACA(Adobe Certified Associates), and PG Dip (IT). With over 10 years of hands-on experience as an IT support engineer across Windows, Mac, iOS, and Linux Server platforms, Neil possesses the expertise to create comprehensive and user-friendly documentation that simplifies complex technical concepts for a wide audience.
Watch & Subscribe Our YouTube Channel
YouTube Subscribe Button

Latest From Hawkdive

You May like these Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.