Skip to content

Commit

Permalink
feat: add deployment solution to digital ocean app platform (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal authored Jan 30, 2024
1 parent c61e5e6 commit 4589e2e
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 356 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ jobs:
pass: ${{ secrets.DOCKER_PASSWORD }}
slug: asyncapi/server-api
description: Server API providing official AsyncAPI tools

deploy-app:
name: Deploy to DigitalOcean App
needs: publish-docker
runs-on: ubuntu-latest
steps:
- name: Deploy to DigitalOcean App
uses: digitalocean/[email protected]
with:
app_name: "server-api"
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
images: '[{"name":"asyncapi-server-api","image":{"registry_type":"DOCKER_HUB","registry":"asyncapi","repository":"server-api","tag":"latest"}}]'
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ server is ready to use on [http://localhost:80](http://localhost:80).
2. Write code and tests.
3. Make sure all tests pass `npm test`

## Deployment

This project is deployed to [DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform/) using [Terraform](https://www.terraform.io/) and [GitHub Actions](https://www.github.com/digitalocean/app_action/). To deploy it to your own account, follow these steps:

1. Fork this repository.
2. Create a [DigitalOcean Personal Access Token](https://cloud.digitalocean.com/account/api/tokens) with `read` and `write` permissions. For more information, see [DigitalOcean's documentation](https://docs.digitalocean.com/reference/api/create-personal-access-token/).
3. Run `terraform init` to initialize the Terraform project as can be seen [here](./deployments/apps/main.tf). This should be run being located at ./deployments/apps directory preferably.
4. Run `terraform apply` to create the necessary infrastructure.

> [!NOTE]
> You need to export the following environment variables before running `terraform apply`:
> - `DIGITALOCEAN_ACCESS_TOKEN`: Your DigitalOcean Personal Access Token.

### How the GitHub workflow works

The [GitHub workflow](./.github/workflows/release-docker.yml) is triggered when a new tag is pushed to the repository. It will build a new Docker image and push it to the [Docker Hub](https://hub.docker.com/r/asyncapi/server-api) repository. Then the [DigitalOcean App Platform GitHub Action](https://www.github.com/digitalocean/app_action/) updates the application with the new image.

## Contribution

Read [CONTRIBUTING](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md) guide.
Expand Down
3 changes: 3 additions & 0 deletions deployments/apps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform
terraform.tfstate
terraform.tfstate.backup
26 changes: 26 additions & 0 deletions deployments/apps/.terraform.lock.hcl

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

82 changes: 82 additions & 0 deletions deployments/apps/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
terraform {
required_version = ">= 1.0.0"

required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.0.0"
}
}
}

provider "digitalocean" {}

resource "digitalocean_app" "server-api" {
spec {
name = "server-api"
region = "sfo3"

domain {
name = "api.asyncapi.com"
type = "PRIMARY"
}

ingress {
rule {
component {
name = "asyncapi-server-api"
}
match {
path {
prefix = "/"
}
}
cors {
allow_origins {
exact = "*"
}
allow_methods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
allow_headers = ["*"]
}
}
}

service {
name = "asyncapi-server-api"
http_port = 80
health_check {
http_path = "/v1/help/validate"
port = 80
}
env {
key = "PORT"
value = "80"
}

image {
registry_type = "DOCKER_HUB"
registry = "asyncapi"
repository = "server-api"
tag = "latest"
}

instance_count = 1
instance_size_slug = "basic-xs" // $10/month

alert {
rule = "CPU_UTILIZATION"
value = 80
operator = "GREATER_THAN"
window = "TEN_MINUTES"
}
}

alert {
rule = "DEPLOYMENT_FAILED"
}
}
}

output "live_url" {
value = digitalocean_app.server-api.default_ingress
}
23 changes: 0 additions & 23 deletions deployments/k8s/.helmignore

This file was deleted.

7 changes: 0 additions & 7 deletions deployments/k8s/Chart.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions deployments/k8s/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions deployments/k8s/templates/NOTES.txt

This file was deleted.

51 changes: 0 additions & 51 deletions deployments/k8s/templates/_helpers.tpl

This file was deleted.

69 changes: 0 additions & 69 deletions deployments/k8s/templates/deployment.yaml

This file was deleted.

33 changes: 0 additions & 33 deletions deployments/k8s/templates/hpa.yaml

This file was deleted.

Loading

0 comments on commit 4589e2e

Please sign in to comment.