# Launch a macOS instance (Preview)

Run macOS with Xcode on an Apple Mac mini, open a terminal through Connect, and what the Preview does not do yet.

**Important:**
macOS instances are a **Preview**, shown to an organization once Deutsche Cloud has granted it access
(**Request access** on the page). They run on Apple Mac mini computers (Apple M4, 10 cores, 16 GiB)
that also run macOS CI jobs.

## Sizes and price

| Type       | vCPU | Memory | Per Mac | Price          |
| ---------- | ---- | ------ | ------- | -------------- |
| `mac-4x6`  | 4    | 6 GiB  | 2       | €0.10 per hour |
| `mac-8x12` | 8    | 12 GiB | 1       | €0.20 per hour |

You pay €0.025 per vCPU for every started hour an instance runs, recorded when it ends.

The image `macos-27-xcode-27-2` is macOS 27 with Xcode 27.2 and its iOS simulators. You sign in as
`ec2-user`, an administrator with `sudo` without a password.

The Macs also run macOS CI jobs. A Mac runs either CI jobs or instances, never both at once. A
launch therefore takes a Mac from CI only when no CI job is waiting for one and another Mac stays
with CI. Otherwise it is refused with `409` and the reason, for example "A macOS CI run is waiting
for a Mac". Try again a few minutes later. A Mac goes back to CI as soon as its last instance is
terminated.

## Prerequisites

- Permission for `ec2:RunInstances`, and `ec2:StartSession` to open a terminal.
- A key pair, if you want your key on the instance as well (Compute → Key pairs).

## Launch it

```sh
dcloud ec2 mac get
dcloud ec2 instances run --region-id de1 --server-type mac-4x6 \
  --name xcode-01 --key-pair-id key-pair-uuid
```

`dcloud ec2 mac get` lists the sizes, the images and your macOS instances as their Macs report
them.

The instance is `pending` while its Mac clones the image and starts it (under a minute on an idle
Mac), then `running`.

## Connect

A macOS instance has no public address: it is reached through Deutsche Cloud Connect, which the
instance starts itself.

```sh
dcloud ec2 connect i-0123abcd --user ec2-user
```

From there `xcodebuild`, `xcrun simctl` and `swift` work as on any Mac.

## Terminate it

```sh
dcloud ec2 instances terminate i-0123abcd
```

Its Mac deletes the virtual machine and its disk within seconds.

## What the Preview does not do yet

- **Stop, start and reboot** from Deutsche Cloud: shut down or reboot from inside
  (`sudo shutdown -r now`), or terminate.
- **A VPC, subnet, security groups, user data, an instance role, images of your own**: refused
  with `400` naming the field.
- **Screen Sharing** and a streamed iOS simulator in the console.
- Auto scaling groups.
