Skip to content

Commit

Permalink
paas: add deployment on Render and DigitalOcean
Browse files Browse the repository at this point in the history
  • Loading branch information
Altonhe committed Aug 9, 2024
1 parent ef9c8b5 commit a12a99d
Show file tree
Hide file tree
Showing 22 changed files with 926 additions and 12 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ This repo is using [Opentofu](https://opentofu.org/) and other tools to create c

## Platform Support Status

| | VM | Docker | K8s |
|-----------------------|-------------|-------------------|--------------|
| Microsoft Azure | VM ✅ | ACI ✅ | AKS 🔲 |
| Amazon Web Services | EC2 ✅ | ECS(Fargate) ✅ | EKS 🔲 |
| Google Cloud Platform | GCE ✅ | Cloud Run ✅ | GKE 🔲 |
| Render || DOCKER ✅🚧(See 1) ||
| Heroku || HCR 🚧 ||
| DigitalOcean | Droplets 🚧 | CR 🚧 | DOKS 🔲 |
| Native K8s ||| K8S ✅(See 2) |
| | VM | Docker | K8s |
|-----------------------|------------|-----------------|--------------|
| Microsoft Azure | VM ✅ | ACI ✅ | AKS 🔲 |
| Amazon Web Services | EC2 ✅ | ECS(Fargate) ✅ | EKS 🔲 |
| Google Cloud Platform | GCE ✅ | Cloud Run ✅ | GKE 🔲 |
| Render || DOCKER ✅(See 1) ||
| DigitalOcean | Droplets ✅ | AP ⚠️(See 3) | DOKS 🔲 |
| Native K8s ||| K8S ✅(See 2) |

The following icons are used to represent the status of support for each platform:
- ✅: completed
- ⚠️: partially completed
- 🚧: in progress
- ❌: not applicable
- 🔲: not started

1. Completed by Aaron, you can find Render deployment file here: [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker), will be integrated into this repo.
1. Completed by Aaron, you can find Render deployment file here: [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker), has been integrated into this repo.
2. Completed by Neo2308, you can find `oba.yaml` here: [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker), will be rewrite in [Kustomize](https://github.com/kubernetes-sigs/kustomize).
3. DigitalOcean app engine's gVisor is conflicting with supervisor, they already know this issue and will fix it in the future.
2 changes: 1 addition & 1 deletion modules/aws-ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ variable "username" {
}

variable "caddy" {
description = "Wheather to use Caddy or not, leave empty to disable"
description = "Whether to use Caddy or not, leave empty to disable"
type = string
default = "1"
}
Expand Down
2 changes: 1 addition & 1 deletion modules/azure-vm/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ variable "size" {
}

variable "caddy" {
description = "Wheather to use Caddy or not, leave empty to disable"
description = "Whether to use Caddy or not, leave empty to disable"
type = string
default = "1"
}
Expand Down
26 changes: 26 additions & 0 deletions modules/digitalocean-ap/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions modules/digitalocean-ap/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.digitalocean_token
}

resource "digitalocean_app" "main" {
spec {
name = "onebusaway-api-server"
region = var.region

service {
name = "onebusaway-api-webapp"
image {
registry_type = "DOCKER_HUB"
registry = "opentransitsoftwarefoundation"
repository = "onebusaway-api-webapp"
tag = "2.5.12-cs-v1.0.0"
}
instance_size_slug = var.instance_size_slug
instance_count = var.num_instances

env {
key = "TZ"
value = var.env_var_tz
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "GTFS_URL"
value = var.env_var_gtfs_url
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "VEHICLE_POSITIONS_URL"
value = var.env_var_vehicle_positions_url
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "TRIP_UPDATES_URL"
value = var.env_var_trip_updates_url
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "ALERTS_URL"
value = var.env_var_alerts_url
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "FEED_API_KEY"
value = var.env_var_feed_api_key
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "FEED_API_VALUE"
value = var.env_var_feed_api_value
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "REFRESH_INTERVAL"
value = var.env_var_refresh_interval
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "AGENCY_ID"
value = var.env_var_agency_id
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "JDBC_USER"
value = var.env_var_jdbc_user
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "JDBC_PASSWORD"
value = var.env_var_jdbc_password
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "JDBC_URL"
value = var.env_var_jdbc_url
scope = "RUN_AND_BUILD_TIME"
}
env {
key = "PORT"
value = var.env_var_port
scope = "RUN_AND_BUILD_TIME"
}

http_port = var.env_var_port

health_check {
http_path = "/onebusaway-api-webapp/api/where/current-time.json?key=org.onebusaway.iphone"
port = var.env_var_port
}
}
}
}
73 changes: 73 additions & 0 deletions modules/digitalocean-ap/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Deployment Guide for DigitalOcean App Platform

DigitalOcean App Platform is a platform-as-a-service (PaaS) that makes it easy to build, deploy, and scale apps quickly. This guide will walk you through deploying the OneBusAway server on DigitalOcean App Platform using Opentofu.

> [!WARNING]
> Currently DigitalOcean App Platform's gVisor is conflicting with supervisor, they already know this issue and will fix it in the future.
>
> FYI: [App platform supervisor error](https://www.digitalocean.com/community/questions/app-platform-supervisor-error)
## Prerequisites

1. A [DigitalOcean](https://www.digitalocean.com/) account. If you don't have one, you can create an account [here](https://cloud.digitalocean.com/registrations/new).

2. A DigitalOcean API token, which you can generate from the [DigitalOcean Control Panel](https://cloud.digitalocean.com/account/api/tokens).

3. Opentofu, an open-source Terraform alternative. You can install it by following the instructions [here](https://opentofu.org/docs/intro/install/).

4. Ensure you have *ALL* the prerequisites installed before starting the deployment.

## Steps

1. Clone this repository to your local machine. You can run:

```bash
git clone https://github.com/OneBusAway/onebusaway-deployment.git
cd onebusaway-deployment/modules/digitalocean-ap
```

2. Initialize the project. This will download the necessary plugins and providers for the project:

```bash
tofu init
```

3. Create a `terraform.tfvars` file by copying the example variables file, and then modify it according to your needs:

```bash
cp terraform.tfvars.example terraform.tfvars
```

4. Edit the `terraform.tfvars` file and update the variable values to match your specific requirements, such as your DigitalOcean API token, region, instance size, environment variables, and more.

5. Run Tofu plan to preview the infrastructure changes:

```bash
tofu plan
```

6. Apply the Tofu configuration to create the actual resources:

```bash
tofu apply
```

Type `yes` when prompted to confirm the resource creation.

7. After the deployment is complete, verify the created resources in the DigitalOcean Control Panel. Ensure the App Platform service, environment variables, and other related resources are created and running correctly.

8. Access the OneBusAway server by visiting the public URL of the App Platform service. You can find the service URL in the DigitalOcean Control Panel under the App Platform service details.

## Clean up

If you want to shut down the server and clean up the resources, you can run the following command:

```bash
tofu destroy
```

Opentofu will destroy all resources created by this project, including the DigitalOcean App Platform service and associated resources.

## Conclusion

This guide shows you how to deploy the OneBusAway server on DigitalOcean App Platform using Opentofu. If you have any questions or suggestions, feel free to open an issue in this repository.
18 changes: 18 additions & 0 deletions modules/digitalocean-ap/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
digitalocean_token = ""
region = "nyc3"
instance_size_slug = "basic-xxs"
num_instances = 1

env_var_tz = "America/Toronto"
env_var_gtfs_url = "https://api.cityofkingston.ca/gtfs/gtfs.zip"
env_var_vehicle_positions_url = "https://api.cityofkingston.ca/gtfs-realtime/vehicleupdates.pb"
env_var_trip_updates_url = "https://api.cityofkingston.ca/gtfs-realtime/tripupdates.pb"
env_var_alerts_url = "https://api.cityofkingston.ca/gtfs-realtime/alerts.pb"
env_var_feed_api_key = ""
env_var_feed_api_value = ""
env_var_refresh_interval = 30
env_var_agency_id = "0"
env_var_jdbc_user = "oba_user"
env_var_jdbc_password = "oba_password"
env_var_jdbc_url = "jdbc:mysql://<DATABASE_HOST>:<PORT>/oba_database"
env_var_port = 8080
89 changes: 89 additions & 0 deletions modules/digitalocean-ap/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
variable "digitalocean_token" {
description = "DigitalOcean API Token"
type = string
}

variable "region" {
description = "The slug for the DigitalOcean data center region hosting the app."
type = string
default = "nyc3"
}

variable "instance_size_slug" {
description = "The instance size to use for this component. This determines the plan (basic or professional) and the available CPU and memory. "
type = string
default = "basic-xxs"
}

variable "num_instances" {
description = "Number of instances"
type = number
default = 1
}

variable "env_var_tz" {
description = "Timezone"
type = string
}

variable "env_var_gtfs_url" {
description = "GTFS URL"
type = string
}

variable "env_var_vehicle_positions_url" {
description = "Vehicle positions URL"
type = string
}

variable "env_var_trip_updates_url" {
description = "Trip updates URL"
type = string
}

variable "env_var_alerts_url" {
description = "Alerts URL"
type = string
}

variable "env_var_feed_api_key" {
description = "Feed API Key"
type = string
}

variable "env_var_feed_api_value" {
description = "Feed API Value"
type = string
}

variable "env_var_refresh_interval" {
description = "Refresh interval"
type = number
default = 30
}

variable "env_var_agency_id" {
description = "Agency ID"
type = string
}

variable "env_var_jdbc_user" {
description = "JDBC User"
type = string
}

variable "env_var_jdbc_password" {
description = "JDBC Password"
type = string
}

variable "env_var_jdbc_url" {
description = "JDBC URL"
type = string
}

variable "env_var_port" {
description = "Port"
type = number
default = 8080
}
16 changes: 16 additions & 0 deletions modules/digitalocean-droplets/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GTFS_URL=https://api.cityofkingston.ca/gtfs/gtfs.zip
TEST_API_KEY=test
VEHICLE_POSITIONS_URL=https://api.cityofkingston.ca/gtfs-realtime/vehicleupdates.pb
TRIP_UPDATES_URL=https://api.cityofkingston.ca/gtfs-realtime/tripupdates.pb
ALERTS_URL=https://api.cityofkingston.ca/gtfs-realtime/alerts.pb
REFRESH_INTERVAL=30
AGENCY_ID=0
TZ=America/Toronto
GOOGLE_MAPS_API_KEY=<YOUR_GOOGLE_MAPS_API_KEY>
GOOGLE_MAPS_CHANNEL_ID=<YOUR_GOOGLE_MAPS_CHANNEL_ID>
GOOGLE_MAPS_CLIENT_ID=<YOUR_GOOGLE_MAPS_CLIENT_ID>
# Your Domain Name, leave blank if you don't have one
DOMAIN=oba.example.com
# OBA image version. You can find the available versions at:
# https://hub.docker.com/r/opentransitsoftwarefoundation/onebusaway-api-webapp/tags
OBA_VERSION=latest
Loading

0 comments on commit a12a99d

Please sign in to comment.