17.4 C
London
Tuesday, September 3, 2024

Add macOS to your steady integration pipelines with AWS CodeBuild


Voiced by Polly

Beginning at this time, you may construct functions on macOS with AWS CodeBuild. Now you can construct artifacts on managed Apple M2 machines that run on macOS 14 Sonoma. AWS CodeBuild is a totally managed steady integration service that compiles supply code, runs assessments, and produces ready-to-deploy software program packages.

Constructing, testing, signing, and distributing functions for Apple techniques (iOS, iPadOS, watchOS, tvOS, and macOS) requires the usage of Xcode, which runs solely on macOS. If you construct for Apple techniques within the AWS Cloud, it is rather doubtless you configured your steady integration and steady deployment (CI/CD) pipeline to run on Amazon Elastic Cloud Compute (Amazon EC2) Mac situations.

Since we launched Amazon EC2 Mac in 2020, I’ve spent a big period of time with our prospects in varied industries and geographies, serving to them configure and optimize their pipelines on macOS. Within the easiest kind, a buyer’s pipeline may appear like the next diagram.

iOS build pipeline on EC2 Mac

The pipeline begins when there’s a new commit or pull request on the supply code repository. The repository agent put in on the machine triggers varied scripts to configure the surroundings, construct and check the applying, and finally deploy it to App Retailer Join.

Amazon EC2 Mac drastically simplifies the administration and automation of macOS machines. As I like to explain it, an EC2 Mac occasion has all of the issues I like from Amazon EC2 (Amazon Elastic Block Retailer (Amazon EBS) volumes, snapshots, digital non-public clouds (VPCs), safety teams, and extra) utilized to Mac minis working macOS within the cloud.

Nevertheless, prospects are left with two challenges. The primary is to organize the Amazon Machine Picture (AMI) with all of the required instruments for the construct. A minimal construct surroundings requires Xcode, however it is rather widespread to put in Fastlane (and Ruby), in addition to different construct or growth instruments and libraries. Most organizations require a number of construct environments for a number of combos of macOS and Xcode variations.

The second problem is to scale your construct fleet in accordance with the quantity and length of builds. Giant organizations sometimes have a whole lot or 1000’s of builds per day, requiring dozens of construct machines. Scaling out and in of that fleet helps to avoid wasting on prices. EC2 Mac situations are reserved in your devoted use. One occasion is allotted to at least one devoted host. Scaling a fleet of devoted hosts requires a particular configuration.

To handle these challenges and simplify the configuration and administration of your macOS construct machines, at this time we introduce CodeBuild for macOS.

CodeBuild for macOS relies on the lately launched reserved capability fleet, which accommodates situations powered by Amazon EC2 which are maintained by CodeBuild. With reserved capability fleets, you configure a set of devoted situations in your construct surroundings. These machines stay idle, able to course of builds or assessments instantly, which reduces construct durations. With reserved capability fleets, your machines are all the time working and can proceed to incur prices so long as they’re provisioned.

CodeBuild gives a normal disk picture (AMI) to run your builds. It accommodates preinstalled variations of Xcode, Fastlane, Ruby, Python, Node.js, and different fashionable instruments for a growth and construct surroundings. The total checklist of instruments put in is on the market within the documentation. Over time, we are going to present further disk pictures with up to date variations of those instruments. You can even deliver your personal customized disk picture for those who want.

As well as, CodeBuild makes it simple to configure auto scaling. You inform us how a lot capability you need, and we handle every thing from there.

Let’s see CodeBuild for macOS in motion
To point out you the way it works, I create a CI/CD pipeline for my pet undertaking: getting began with AWS Amplify on iOS. This tutorial and its accompanying supply code clarify the best way to create a easy iOS app with a cloud-based backend. The app makes use of a GraphQL API (AWS AppSync), a NoSQL database (Amazon DynamoDB), a file-based storage (Amazon Easy Storage Service (Amazon S3)), and person authentication (Amazon Cognito). AWS Amplify for Swift is the piece that glues all these companies collectively.

The tutorial and the supply code of the app can be found in a Git repository. It contains scripts to automate the construct, check, and deployment of the app.

Configuring a brand new CI/CD pipeline with CodeBuild for macOS includes the next high-level steps:

  1. Create the construct undertaking.
  2. Create the devoted fleet of machines.
  3. Configure a number of construct triggers.
  4. Add a pipeline definition file (buildspec.yaml) to the undertaking.

To get began, I open the AWS Administration Console, choose CodeBuild, and choose Create undertaking.

codebuild mac - 1

I enter a Mission title and configure the connection to the Supply code repository. I exploit GitHub on this instance. CodeBuild additionally helps GitLab and BitBucket. The documentation has an up-to-date checklist of supported supply code repositories.

codebuild mac - 2

For the Provisioning mannequin, I choose Reserved capability. That is the one mannequin the place Amazon EC2 Mac situations can be found. I don’t have a fleet outlined but, so I determine to create one on the flight whereas creating the construct undertaking. I choose Create fleet.

codebuild mac - 3

On the Compute fleet configuration web page, I enter a Compute fleet title and choose macOS as Working system. Beneath Compute, I choose the quantity of reminiscence and the amount of vCPUs wanted for my construct undertaking, and the variety of situations I need beneath Capability.

For this instance, I’m comfortable to make use of the Managed picture. It contains Xcode 15.4 and the simulator runtime for iOS 17.5, amongst different packages. You possibly can learn the checklist of packages preinstalled on this picture within the documentation.

When completed, I choose Create fleet to return to the CodeBuild undertaking creation web page.

CodeBuild - create fleet

As a subsequent step, I inform CodeBuild to create a brand new service position to outline the permissions I need for my construct surroundings. Within the context of this undertaking, I have to embody permissions to tug an Amplify configuration and entry AWS Secrets and techniques Supervisor. I’m not sharing step-by-step directions to take action, however the pattern undertaking code accommodates the checklist of the permissions I added.

codebuild mac - 4

I can select between offering my set of construct instructions within the undertaking definition or in a buildspec.yaml file included in my undertaking. I choose the latter.

codebuild mac - 5

That is non-compulsory, however I need to add the construct artifact to an S3 bucket the place I can archive every construct. Within the Artifact 1 – Main part, I due to this fact choose Amazon S3 as Sort, and I enter a Bucket title and artifact Title. The file title to add is specified within the buildspec.yaml file.

codebuild mac - 6

Down on the web page, I configure the undertaking set off so as to add a GitHub WebHook. This can configure CodeBuild to start out the construct each time a commit or pull request is shipped to my undertaking on GitHub.

codebuild - webhook

Lastly, I choose the orange Create undertaking button on the backside of the web page to create this undertaking.

Testing my builds
My undertaking already contains construct scripts to organize the construct, construct the undertaking, run the assessments, and deploy it to Apple’s TestFlight.

codebuild - project scripts

I add a buildspec.yaml file on the root of my undertaking to orchestrate these present scripts.

model: 0.2

phases:

  set up:
    instructions:
      - code/ci_actions/00_install_rosetta.sh
  pre_build:
    instructions:
      - code/ci_actions/01_keychain.sh
      - code/ci_actions/02_amplify.sh
  construct:
    instructions:
      - code/ci_actions/03_build.sh
      - code/ci_actions/04_local_tests.sh
  post_build:
    instructions:
      - code/ci_actions/06_deploy_testflight.sh
      - code/ci_actions/07_cleanup.sh
artifacts:
   title: $(date +%Y-%m-%d)-getting-started.ipa
   information:
    - 'getting began.ipa'
  base-directory: 'code/build-release'

I add this file to my Git repository and push it to GitHub with the next command: git commit -am "add buildpsec" buildpec.yaml

On the console, I can observe that the construct has began.

codebuild - build history

Once I choose the construct, I can see the log information or choose Part particulars to obtain a high-level standing of every section of the construct.

codebuild - phase details

When the construct is profitable, I can see the iOS utility IPA file uploaded to my S3 bucket.

aws s3 ls

The final construct script that CodeBuild executes uploads the binary to App Retailer Join. I can observe new builds within the TestFlight part of the App Retailer Join.

App Store Connect

Issues to know
It takes 8-10 minutes to organize an Amazon EC2 Mac occasion and to simply accept the very first construct. This isn’t particular to CodeBuild. The builds you submit in the course of the machine preparation time are queued and might be run so as as quickly because the machine is on the market.

CodeBuild for macOS works with reserved fleets. Opposite to on-demand fleets, the place you pay per minute of construct, reserved fleets are charged for the time the construct machines are reserved in your unique utilization, even when no builds are working. The capability reservation follows the Amazon EC2 Mac 24-hour minimal allocation interval, as required by the Software program License Settlement for macOS (article 3.A.ii).

A fleet of machines may be shared throughout CodeBuild tasks in your AWS account. The machines within the fleet are reserved in your unique use. Solely CodeBuild can entry the machines.

CodeBuild cleans the working listing between builds, however the machines are reused for different builds. It permits you to use the CodeBuild native cache mechanism to rapidly restore chosen information after a construct. For those who construct totally different tasks on the identical fleet, make sure you reset any world state, such because the macOS keychain, and construct artifacts, akin to the SwiftPM and Xcode package deal caches, earlier than beginning a brand new construct.

If you work with customized construct pictures, ensure they’re constructed for a 64-bit Mac-Arm structure. You additionally should set up and begin the AWS Techniques Supervisor Agent (SSM Agent). CodeBuild makes use of the SSM Agent to put in its personal agent and to handle the machine. Lastly, be certain that the AMI is on the market to the CodeBuild group ARN.

CodeBuild for macOS is on the market within the following AWS Areas: US East (Ohio, N. Virginia), US West (Oregon), Asia Pacific (Sydney), and Europe (Frankfurt). These are the identical Areas that provide Amazon EC2 Mac M2 situations.

Get began at this time and create your first CodeBuild undertaking on macOS.

— seb



Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here