|
| 1 | +# Unison Cloud on Docker Compose |
| 2 | + |
| 3 | +**NOTE:** all paths/files in this documentation assume you are already within the `docker` directory (not the project root). |
| 4 | + |
| 5 | +## Scope and disclaimers |
| 6 | + |
| 7 | +** This is not a production setup.** |
| 8 | + |
| 9 | +This Docker Compose configurations is intended to demonstrate minimalist deployments of unison.cloud in a local environment. It is **not production-ready** but serves testing, development, and demonstration purposes. It provides an easy way to test unison.cloud in your own environment, with the expectation that you might later integrate these learnings into an existing production environment. Specifically, please be aware of the following caveats: |
| 10 | + |
| 11 | +- The secret store (used by [Environment.setValue](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/terms/Environment/setValue) and [Environment.Config.lookup](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/types/Environment/Config)) stores values insecurely and in-memory: **they will not persist when the Vault container is terminated**. |
| 12 | +- Your [storage](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/types/Storage), [blobs](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/types/Blobs), and [services](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/types/Services) are persisted only to named Docker volumes on your machine. If your hard drive fails or you perform some overzealous Docker pruning, they are gone forever. The centralized Unison Cloud control plane stores only some metadata like IDs and permissions; it cannot restore your data. |
| 13 | + |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +### Install Docker |
| 18 | + |
| 19 | +See [instructions on docker.com](https://docs.docker.com/engine/install/). |
| 20 | + |
| 21 | +### Register a cluster |
| 22 | + |
| 23 | +See [instructions](../README.md#register-a-byoc-cluster). |
| 24 | + |
| 25 | +## Configure your cluster |
| 26 | + |
| 27 | +1. Copy [nimbus-secrets-example.json](nimbus-secrets-example.json) to `nimbus-secrets.json`. |
| 28 | +2. Replace the `cloudApiToken` value with the token you received when registering your cluster. |
| 29 | +3. In `cloudApiInstances.uri`, replace `YOUR_CLUSTER_NAME` with the cluster name that you registered. |
| 30 | + |
| 31 | +Some insecure development credentials (ex: `INSECURE_DEV_TOKEN`) have been provided for the services running on your local cluster. These are fine for local development, so you can leave them for now, but you will want to change them before opening up your cluster outside of your personal computer. |
| 32 | + |
| 33 | +## Run your cluster |
| 34 | + |
| 35 | +Run this `docker compose` command to start up your cluster: |
| 36 | + |
| 37 | +```sh |
| 38 | +docker compose --env-file secrets-example.env --env-file .env up --remove-orphans |
| 39 | +``` |
| 40 | + |
| 41 | +Logs will print to the screen. When you see messages that start with `Starting public HTTP server` from your `unison-cloud-nimbus` instances, your cluster is ready to serve requests! |
| 42 | + |
| 43 | +If you would prefer to run your containers in the background, you can add `--detach` (or `-d`) to the end of the command: |
| 44 | + |
| 45 | +```sh |
| 46 | +docker compose --env-file secrets-example.env --env-file .env up --remove-orphans --detach |
| 47 | +``` |
| 48 | + |
| 49 | +In detached mode logs will not print to the screen and you can use your terminal window to run other commands. |
| 50 | + |
| 51 | +See [Tear down your cluster](#tear-down-your-cluster) when you are ready to stop your cluster. |
| 52 | + |
| 53 | +## Use your new cluster! |
| 54 | + |
| 55 | +Now you can point your [Unison Cloud client](https://share.unison-lang.org/@unison/cloud) to your own cluster to submit batch jobs, deploy services and more! |
| 56 | + |
| 57 | +First you'll need to know the control plane endpoint for your cluster. It has the form `{your_cluster_name}.byoc.unison.cloud` (ex: `alice-homelab.byoc.unison.cloud`). |
| 58 | + |
| 59 | +There are two ways to point your cloud client to your cluster: via an environment variable _or_ with a custom [Cloud.ClientConfig](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/types/Cloud/ClientConfig). |
| 60 | + |
| 61 | +### Configure via environment variable |
| 62 | + |
| 63 | +Set the `UNISON_CLOUD_HOST` environment variable to your cluster control plane endpoint. You could set this in your shell init file (ex: `.bashrc`) or you could just set it in the scope of your `ucm` session: |
| 64 | + |
| 65 | +```sh |
| 66 | +UNISON_CLOUD_HOST=alice-homelab.byoc.unison.cloud ucm |
| 67 | +``` |
| 68 | + |
| 69 | +You can now use [Cloud.run](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/terms/Cloud/run) and it will point to your cluster. |
| 70 | + |
| 71 | +### Configure via Cloud.ClientConfig |
| 72 | + |
| 73 | +Instead of setting the `UNISON_CLOUD_HOST` environment variable, you can programmatically configure your cloud client to point to your cluster. Note that this approach requires using [Cloud.run.withConfig](https://share.unison-lang.org/@unison/cloud/code/releases/20.16.1/latest/terms/Cloud/run/withConfig) instead of `Cloud.run`. |
| 74 | + |
| 75 | +```unison |
| 76 | +main : '{IO, Exception} Nat |
| 77 | +main = do |
| 78 | + homelabConfig = |
| 79 | + Cloud.ClientConfig.default() |> ClientConfig.host.set (HostName "alice-homelab.byoc.unison.cloud") |
| 80 | + Cloud.run.withConfig homelabConfig do |
| 81 | + Cloud.submit Environment.default() do |
| 82 | + 1 + 1 |
| 83 | +``` |
| 84 | + |
| 85 | +## Tear down your cluster |
| 86 | + |
| 87 | +When you are done using your local cluster, you can terminate it. If you ran `docker compose` in attached mode (without the `--detach`/`-d` flag), then you can hit `<ctrl>-c` to stop the running containers. |
| 88 | + |
| 89 | +If you ran `docker compose` in detached mode, then you'll need to run the `down` variant of the `up` command that you previously ran: |
| 90 | + |
| 91 | +```sh |
| 92 | +docker compose --env-file secrets-example.env --env-file .env down |
| 93 | +``` |
| 94 | + |
| 95 | +Even if you ran `docker compose` in attached mode you still may want to run the above `down` command to perform some cleanup that `<ctrl>-c` doesn't trigger like removing stopped containers and the cluster network. |
0 commit comments