Skip to content
Coritan Docs

Run an app or a database

Deploy your code from git on App Deployment, run a PostgreSQL database beside it, and connect the two, from start to finish.

View as Markdown

This tutorial gets your own code running on Coritan with a database beside it, both on App Deployment. Sections 1 to 3 deploy the app from its git repository and serve it over HTTPS on your domain, sections 4 and 5 run a PostgreSQL database from the catalogue, and section 6 connects them. To run only a database, start at section 4.

The app is billed by what it uses, after the free amounts every account gets each month, so a small app can cost nothing and the order has no price to pay. One instance with light traffic comes to about $1.14 a month (How App Deployment is billed). The database server is billed by what it uses too (How game servers and databases are billed). If you are not sure which way to run your code suits it, read Which compute product to choose first.

  • A Coritan account. Create an account if you have none, then sign in.
  • Your app in a git repository on a public host, such as GitHub, that answers over HTTPS.
  • An app that listens on the port in its PORT variable and answers HTTP requests for / (How each kind runs).
  • An access token for the API, because section 1 orders the app with one request (Authentication). To order it from the dashboard instead, follow Order the app in the dashboard, then continue at section 2.
  • Credit on your account. The app and the database are billed by what they use, and a prepaid account needs a minimum total of deposits, $10.00 by default, before either runs (What you need before you order). The credit pays for their use each hour (Add credit to your balance).
  • Server access, for the database. Pro, Business and Enterprise include it, and a Free account adds it in the same order as its first database. The app needs no plan.
  • psql, PostgreSQL's command-line client, on your computer.
  1. Order the app with your repository and its branch. An app needs no plan and no size, so the order names neither (Order any kind). The example runs one instance in Frankfurt (fra):

    Shell
    curl -X POST https://api.coritan.com/api/v1/services/order \
      -H "Authorization: Bearer $CORITAN_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "config": {
          "kind": "git",
          "name": "web-shop",
          "placement": {"mode": "single", "locations": ["fra"]},
          "source": {"git": {"repo_url": "https://github.com/example/web-shop", "branch": "main"}},
          "runtime": {"port": 3000, "health_check_path": "/"}
        }
      }'
    
  2. The app has nothing to pay up front. A prepaid account that has not made the first deposit gets 403 with Deposit at least $10.00 before you start anything that bills by use. The deposit stays in your account as credit. Add credit, then send the order again.

In the dashboard, open App Deployment. web-shop is listed as a Web service, marked Not deployed until its first release is ready (Order any kind).

Order the app in the dashboard

Section titled Order the app in the dashboard
  1. In the dashboard, go to App Deployment and select New deployment.
  2. Under What to deploy, select Git repository. Under Repository, select Paste an address and type https://github.com/example/web-shop, or select From GitHub and choose the repository.
  3. Under Build and run, leave the fields blank so the build works them out. The app listens on port 3000, which is what a blank Port means.
  4. Under Locations, keep Single and choose Frankfurt under Data centres. There is no size to choose: the memory limit starts at 512 MB, or 1 GB for Next.js, and grows by itself.
  5. Under Networking, keep the suggested Deployment name. Leave Advanced as it is: Largest memory limit is 4 GB and Monthly budget is empty.
  6. In the summary, read the Billed by use panel. For one instance, it shows $0.25 a month for an idle app, $1.14 for light traffic and $12.81 for busy traffic, after the free amounts each month.
  7. If your account has not made its first deposit, the summary shows a Deposit line: the credit stays yours and pays for what the app uses. Choose how to pay under Pay with.
  8. Select the button. It reads Deploy when nothing is due, or names the amount, such as Pay $10.00 and deploy, and pays the deposit and deploys in one click.

The order's page shows Setting up while we set the app up (Order your code).

  1. Open web-shop, then its Releases tab. Its first release builds the newest commit on main, and the release's page shows the build log as it goes.
  2. The release moves from Queued to Building to Deploying. Once its instance passes the health check, the release reads Live, and so does the deployment in the App Deployment list.
  3. The deployment's header shows its platform address, such as web-shop.apps.example.net, with Copy address. Open it in a browser with https:// in front.

Your app answers over HTTPS (Deploy, promote and roll back releases).

  1. On the deployment's page, select the Domains tab, then Add domain…. The Add a domain page opens.
  2. In Domain, type the name, such as www.example.com, and select Add domain.
  3. At your DNS host, create the TXT record that proves the domain is yours and the CNAME record that sends its visitors to the app, both as the tab gives them. When Coritan hosts the domain's DNS, add both on the domain's DNS tab (Add, edit and delete DNS records).
  4. Wait a few minutes, then select Verify on the domain's row.

The domain shows Verified, and Certificate issued once the certificate authority has checked it. Your app answers at https://www.example.com (Add a domain and protection).

  1. In the dashboard, go to Order a service and select PostgreSQL database under Quick start. The order page opens with PostgreSQL chosen in the Catalogue.
  2. Under Size, choose a plan. It sets what the database has and does not set a price: the database is billed by what it uses.
  3. Under Version, keep the version the page chose, marked Default, or choose the major version your app needs.
  4. Under Data centres, choose the one your app runs in, Frankfurt in this example, so the two are close.
  5. Under Settings, keep the suggested Server name or type your own. You can rename the server later on its Settings tab (Rename the server).
  6. Check the summary under Your order, then select the button under it. It reads Deploy when nothing is due, and otherwise names the amount, such as Pay $14.50 and deploy for a Free account with no credit: one click adds Server access and the deposit, places the order and pays for it on this page.
  7. If the order's page reads Order placed, payment due, pay under Pay invoice.

The order's page shows Setting up, then Your order is ready. The database appears under App Deployment, marked Starting while Coritan installs PostgreSQL (Order a deployment).

5. Start the database and connect to it

Section titled 5. Start the database and connect to it
  1. Open the database from the App Deployment page. The install does not start it, so select Start. The Console tab shows PostgreSQL's own messages until it prints database system is ready to accept connections (Use the console and power controls).

  2. Select the Settings tab. Under Network, Address with port shows where the database listens, such as 203.0.113.10:10565, and Copy address copies it.

  3. Under Startup variables, read the user name in POSTGRES_USER, the password in POSTGRES_PASSWORD and the database's name in POSTGRES_DB (Server settings). The same card changes and adds startup variables, such as an app server's own settings and keys (Add a startup variable).

  4. On your computer, connect with psql and the values from the tab, then type the password when it asks:

    Shell
    psql -h 203.0.113.10 -p 10565 -U pguser pgdb
    
  5. At the pgdb=# prompt, give the user a password of your own:

    Text
    \password pguser
    

Warning

Every new PostgreSQL server starts with the password that Startup variables shows, and the server's address is public. Set your own before you store anything. The table goes on showing the first password, so keep the new one somewhere safe.

psql connects and shows its prompt, and after \password it connects only with your new password.

6. Connect the app to the database

Section titled 6. Connect the app to the database
  1. Open web-shop from App Deployment and select the Variables tab, then Add variable…. The Add a variable page opens.
  2. In Name, type the variable your app reads, such as DATABASE_URL. In Value, type the connection address, such as postgresql://pguser:YOUR_PASSWORD@203.0.113.10:10565/pgdb, with your new password in it.
  3. Leave Secret ticked and Environment at All environments, choose Runtime only under Available at, and select Add variable. The page closes and the list shows the new variable.
  4. A notice at the top of the page says Redeploy to apply your changes. Select Redeploy… in it, then Redeploy in the dialog. The app reads this variable only while it runs, so a redeploy applies it and nothing is built. Instances keep the variables they started with until the next release.

A new release starts. Once it is Live, your app reads DATABASE_URL and stores its data in PostgreSQL (Environments and variables). With the API, a binding can set DATABASE_URL and the rest for you instead, and keeps them up to date when the password changes (Variables from Coritan services).

The app did not pass its health check within 10 minutes. Health check on /: the connection failed
Nothing answered on the port in the app's PORT variable. Make the app listen on that port (Troubleshooting).
Not verified yet above the domain's row
Coritan did not find the TXT record. Check its name and value at your DNS host, wait a few minutes, then select Verify again.
psql cannot connect
Check that the database's status says it is running, and that psql uses the port from Address with port rather than PostgreSQL's usual 5432 (Troubleshoot servers).