Skip to main content

Run on App Platform

Run on DigitalOcean

It is easy to run DB2Rest on DigitalOcean App Platform using the Docker image. It is also possible to run DB2Rest on droplets or virtual machines(VM).

DigitalOcean managed database

DigitalOcean provides managed database service for :

  • PostgreSQL
  • MySQL
  • MongoDB
  • Redis

DB2Rest currently supports PostgreSQL and MySQL.

Create database

Follow the tutorials below to launch either PostgreSQL or MySQL database service.

The example below shows the dashboard of a managed PostgreSQL database created on DigitalOcean cloud.

PostgreSQL Database

Create Table

Next, create a table using any database tool. Our favorite tool is Dbeaver.

info

The connection details are available on the database dashboard.


CREATE TABLE employee (
id serial4 NOT NULL,
first_name varchar(50) NOT NULL,
last_name varchar(50) NOT NULL,
email varchar(255) NOT NULL,
created_on timestamp NOT NULL,
CONSTRAINT employee_email_key UNIQUE (email),
CONSTRAINT employee_pkey PRIMARY KEY (id)
);

Create app service

DB2Rest can now be deployed as an app service on Digital Ocean's App Platform and connect to your database created in the previous step. In order to get started, click on the buttons as shown in the image below:

Create App

This will open the Create App form.

In this form set the values as listed below.

  1. Service Provider - Select Docker Hub
  2. Repository - kdhrubo/db2rest

Create App Form

Click on the Next button to load the Resources form.

App resources

Now click on Edit Plan button to set the number of Containers to 1 to reduce cost.

Edit Plan

Click on Back to go back to the Resources form. Then click Next.

In the Environment screen, set the values for the following environment variables:

  • DB_URL
  • DB_USER
  • DB_PASSWORD

Set Environment

Click on Save to save the environment variables. Then click on the Next button twice to reach the Review page.

Final Review

On the Review page, click on Create Resources to provision DB2Rest as an app service.

tip

The values needed for the environment are available in the database dashboard.

DB Environment Variables

Test DB2Rest App Service

Once the deployment is successfully completed, it is time to test the application service.

Successful deployment

Check DB2Rest Health

It is very easy to verify DB2Rest application service with the actuator endpoint as shown below:


curl --request GET \
--url 'https://seashell-app-47ctm.ondigitalocean.app/actuator/health?=' \
--header 'User-Agent: insomnia/8.6.1'


The actuator health check service in DB2Rest will return the following response:

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked

{
"status": "UP",
"groups": [
"liveness",
"readiness"
]
}

The status attribute shows that the application service is ready to handle database operations.

Insert Row


curl --request POST \
--url https://seashell-app-47ctm.ondigitalocean.app/employee \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/8.6.1' \
--data '{
"first_name" : "Salman",
"last_name" : "Khan",
"email" : "[email protected]",
"created_on" : "2015-04-14T11:07:36.639Z"
}'


HTTP Response

    {
"row": 1,
"keys": {
"id": 3
}
}

Read Row


curl --request GET \
--url https://seashell-app-47ctm.ondigitalocean.app/employee \
--header 'User-Agent: insomnia/8.6.1'

HTTP Response

    [
{
"id": 1,
"first_name": "Salman",
"last_name": "Khan",
"email": "[email protected]",
"created_on": "2015-04-14T11:07:36.639+00:00"
}
]

Secure the deployment

In this deployment, the app service and database are not in the same Virtual Private Cloud or VPC. It is not secure connectivity even though SSL is turned on.

warning

It is imperative to restrict access to the database from external sources. The database dashboard already shows this warning.

Successful database

Click on the link Secure this database cluster by restricting access to go the settings page (also available in the Settings tab) to set the Trusted sources. Click on Edit and select the app service as the only service to connect to the database.

Add trusted resources

Once the DB2Rest service (named seashell-app by DigitalOcean) is selected, click Save. Now the database instance is safe and will only allow connection requests from configured trusted sources.

Secured database

Finally, refer to the DB2Rest documentation for further learning and exploring API features.

For help, visit us on Discord or our GitHub Discussions