Skip to main content

Advanced options for AWS EC2 instances

For optimal use of the EC2 instances, we recommend additional configuration that is not strictly required for the instances to run Bitrise builds. Some of these configuration options are best set during instance creation.

Connectivity and security of your EC2 instance

Once your EC2 instance is ready, make sure you can connect to the instance and that it can connect to the relevant Bitrise services. You can connect to the instance using SSH or in the case of Mac instances, VNC.

You can also set a password for your instance.

Instance passwords

User data

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of user data during instance creation.

User data is provided either in plain text or in base64 encoded format.

By default, the Bitrise AMI doesn't have user passwords. It is the subscriber's responsibility to set the desired password.

For a Mac instance, you need to set a user password and the default login.keychain password:

sudo /usr/bin/dscl . -passwd /Users/ec2-user
security set-keychain-password  -o "" -p "<new password>" ~/Library/Keychains/login.keychain-db

For a Linux instance:

sudo passwd

Connecting to the instance

To connect to your instance using SSH, we recommend using TCP port 22. To connect to the instance via SSH:

macOS

Linux

  • ssh -i "<your-ssh-key>" ec2-user@<your-mac2-instance>

    You can also connect with VNC. We recommend using TCP port 5900. To connect:

    open vnc://ec2-user@<aws-mac2-instance>
  •  ssh -i ~/.ssh/key   ubuntu@<your-aws-instance>

Security group configuration

Make sure to enable the use of both ports in your security group configuration of the instance!

Pre-warming the disk after booting

User data

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of user data during instance creation.

User data is provided either in plain text or in base64 encoded format.

You can improve EBS performance by pre-warming the disk right after booting it up. You only need to do it once.

Recommended for virtualization

We highly recommend pre-warming the disk if you use our virtualized offering.

Mac instance

Linux instance

  • export cnt=$(($(df -h | grep "/$" | awk '{print $4}' | grep -oE "[0-9]+")-2))
    sudo dd if=/dev/random of=bigfile bs=1g count=$cnt
  • sudo dd if=/dev/xvdf of=/dev/null bs=1M

    dev/xvfd

    Be aware that xvdf might be different on your machine

Increasing disk size on a Mac instance

User data

To make sure instance behavior is consistent across all instances, we recommend configuring this as part of user data during instance creation.

User data is provided either in plain text or in base64 encoded format.

If you have configured a bigger EBS storage for your EC2 Mac instance than the default (400 GB), resize the partition so macOS can use all available disk space:

PDISK=$(diskutil list physical external | head -n1 | cut -d" " -f1)
APFSCONT=$(diskutil list physical external | grep "Apple_APFS" | tr -s " " | cut -d" " -f8)
yes | sudo diskutil repairDisk $PDISK

sudo diskutil apfs resizeContainer $APFSCONT 0

For more information, please refer to the AWS macOS EC2 documentation.

Cleaning up your AWS build environment

When running a self-hosted agent, one agent executes multiple builds (one after the other). This allows sharing of data between builds on the local filesystem, but it also requires some care in order to avoid one build affecting another.

To avoid this problem, you can clean up your build environment in between builds. To do so, you need to run the Bitrise CLI on the self-hosted machines in agent mode: Cleaning up a persistent build environment