|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +--- |
| 4 | + |
| 5 | +# Digital Ocean App Platform 🌊 |
| 6 | + |
| 7 | +[App Platform](https://www.digitalocean.com/products/app-platform) is a service from [Digital Ocean](https://www.digitalocean.com) that helps you launch apps quickly while they manage the underlying infrastructure. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Before you get started, if you haven't already completed these steps, you'll have to: |
| 12 | + |
| 13 | +1. Create a free [Digital Ocean account](https://cloud.digitalocean.com/registrations/new) (or sign in with Google or Github). |
| 14 | + |
| 15 | +:::caution |
| 16 | +You can incur costs when running this quickstart! For more details, see [App Platform Pricing](https://www.digitalocean.com/pricing/app-platform) and [Container Registry Pricing](https://www.digitalocean.com/pricing/container-registry). |
| 17 | +::: |
| 18 | + |
| 19 | +2. Install [Docker](https://docs.docker.com/get-docker/) on your machine and run it. You can verify it is set up correctly by running: |
| 20 | + |
| 21 | +```bash |
| 22 | +docker images |
| 23 | +``` |
| 24 | + |
| 25 | +(If Docker is running, the command will print the images on your machine. If not, it will print something like `Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?`) |
| 26 | + |
| 27 | +3. Install the [Digital Ocean CLI (doctl)](https://docs.digitalocean.com/reference/doctl/how-to/install) on your machine. |
| 28 | + |
| 29 | +4. [Create a Digital Ocean API Token](https://docs.digitalocean.com/reference/api/create-personal-access-token) for your account with read and write access, then use it to give `doctl` access to your account by running (it will prompt you for the access token): |
| 30 | + |
| 31 | +```bash |
| 32 | +doctl auth init --context [NAME] |
| 33 | +``` |
| 34 | + |
| 35 | +- `[NAME]`: A new name for the authentication context. |
| 36 | + |
| 37 | +:::tip |
| 38 | +You can switch authentication contexts in `doctl` buy running: |
| 39 | + |
| 40 | +```bash |
| 41 | +doctl auth switch --context [NAME] |
| 42 | +``` |
| 43 | + |
| 44 | +::: |
| 45 | + |
| 46 | +5. Give Docker permission to push images to Digital Ocean by running: |
| 47 | + |
| 48 | +```bash |
| 49 | +doctl registry login |
| 50 | +``` |
| 51 | + |
| 52 | +6. Create a Container Registry. This can be done in the [Digital Ocean console](https://docs.digitalocean.com/products/container-registry/quickstart/#create-a-registry), or by running: |
| 53 | + |
| 54 | +```bash |
| 55 | +doctl registry create [REGISTRY_NAME] --region [REGION] |
| 56 | +``` |
| 57 | + |
| 58 | +- `[REGISTRY_NAME]`: A name for the newly created registry. |
| 59 | +- `[REGION]`: The Digital Ocean region the registry should reside in (ex: sfo1) |
| 60 | + |
| 61 | +:::note |
| 62 | +Be creative - registry names must be unique across all Digital Ocean container registries. |
| 63 | +::: |
| 64 | + |
| 65 | +## Deploying |
| 66 | + |
| 67 | +1. Build your API for production use by running: |
| 68 | + |
| 69 | +```bash |
| 70 | +dart_frog build |
| 71 | +``` |
| 72 | + |
| 73 | +This will create a `/build` directory with all the files needed to deploy your API. |
| 74 | + |
| 75 | +2. Build your API using Docker by running: |
| 76 | + |
| 77 | +```bash |
| 78 | +docker build build \ |
| 79 | + --tag registry.digitalocean.com/[REGISTRY]/[IMAGE_NAME] |
| 80 | +``` |
| 81 | + |
| 82 | +- `[REGISTRY]`: The name of the registry you created eariler |
| 83 | +- `[IMAGE_NAME]`: A name given to this image to identify it in the registry |
| 84 | + |
| 85 | +This command will build the Docker image on your machine and can take up to a few minutes. |
| 86 | + |
| 87 | +3. Push the image to Container Registry by running: |
| 88 | + |
| 89 | +```bash |
| 90 | +docker push registry.digitalocean.com/[REGISTRY]/[IMAGE_NAME] |
| 91 | +``` |
| 92 | + |
| 93 | +You should now see your repository in the [Container Registry page](https://cloud.digitalocean.com/registry) |
| 94 | + |
| 95 | +4. Create your App by following [these instructions](https://docs.digitalocean.com/products/app-platform/how-to/deploy-from-container-images/#deploy-resource-using-a-container-image-as-the-source). |
| 96 | + |
| 97 | +5. Congratulations! You have successfully built and deployed your API to App Platform. You can now access your API via the URL at the top of the app’s overview page 🎉 |
| 98 | + |
| 99 | +## Additional Resources |
| 100 | + |
| 101 | +- [App Platform docs](https://docs.digitalocean.com/products/app-platform) |
| 102 | +- [`doctl` CLI reference](https://docs.digitalocean.com/reference/doctl) |
| 103 | +- [Adding a custom domain in App Platform](https://docs.digitalocean.com/products/app-platform/how-to/manage-domains) |
| 104 | +- [View logs in App Platform](https://docs.digitalocean.com/products/app-platform/how-to/view-logs) |
0 commit comments