From 534610d12f96d4bfc62a27a928b1a10c823e897b Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Wed, 10 Jan 2024 18:28:28 +0530 Subject: [PATCH 01/11] feat: initial workflow setup --- .github/workflows/deploy-digitalocean.yml | 55 +++++++++++++++++++++++ deployments/droplets/.gitignore | 3 ++ deployments/droplets/.terraform.lock.hcl | 26 +++++++++++ deployments/droplets/main.tf | 20 +++++++++ deployments/droplets/output.tf | 4 ++ deployments/droplets/server-api.yaml | 25 +++++++++++ terraform.tfstate | 9 ++++ 7 files changed, 142 insertions(+) create mode 100644 .github/workflows/deploy-digitalocean.yml create mode 100644 deployments/droplets/.gitignore create mode 100644 deployments/droplets/.terraform.lock.hcl create mode 100644 deployments/droplets/main.tf create mode 100644 deployments/droplets/output.tf create mode 100644 deployments/droplets/server-api.yaml create mode 100644 terraform.tfstate diff --git a/.github/workflows/deploy-digitalocean.yml b/.github/workflows/deploy-digitalocean.yml new file mode 100644 index 00000000..98d0efea --- /dev/null +++ b/.github/workflows/deploy-digitalocean.yml @@ -0,0 +1,55 @@ +name: Deploy to DigitalOcean Droplets + +on: + push: + branches: + - master + + workflow_dispatch: + inputs: + branch: + description: 'Branch to deploy' + required: true + default: 'master' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy to DigitalOcean Droplets + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + script: | + cd /home/${{ secrets.USERNAME }} + if [ ! -d "deploy" ]; then + git clone https://github.com/asyncapi/server-api.git:deploy + fi + + cd deploy + git checkout master + git pull origin master + + # Remove old docker containers + docker rm -f $(docker ps -a -q) + # Remove old docker images + docker rmi -f $(docker images -a -q) + # Remove old docker volumes + docker volume rm $(docker volume ls -q) + + # Build new docker image + docker build -t asyncapi/server-api . + + # Run new docker image + docker run -d -p 80:80 -p 443:443 --name asyncapi-server-api asyncapi/server-api --restart=always + + + + + + + + diff --git a/deployments/droplets/.gitignore b/deployments/droplets/.gitignore new file mode 100644 index 00000000..4c305a08 --- /dev/null +++ b/deployments/droplets/.gitignore @@ -0,0 +1,3 @@ +.terraform +terraform.tfstate +terraform.tfstate.backup diff --git a/deployments/droplets/.terraform.lock.hcl b/deployments/droplets/.terraform.lock.hcl new file mode 100644 index 00000000..8bf3ce37 --- /dev/null +++ b/deployments/droplets/.terraform.lock.hcl @@ -0,0 +1,26 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/digitalocean/digitalocean" { + version = "2.34.1" + constraints = ">= 2.0.0" + hashes = [ + "h1:iRyhFUfKnDRWx75+alSOEtdS0BtNUkrvLusC15s34eo=", + "zh:022d4c97af3d022d4e3735a81c6a7297aa43c3b28a8cecaa0ff58273a5677e2e", + "zh:1922f86d5710707eb497fbebcb1a1c5584c843a7e95c3900d750d81bd2785204", + "zh:1b7ab7c67a26c399eb5aa8a7a695cb59279c6a1a562ead3064e4a6b17cdacabe", + "zh:1dc666faa2ec0efc32329b4c8ff79813b54741ef1741bc42d90513e5ba904048", + "zh:220dec61ffd9448a91cca92f2bc6642df10db57b25d3d27036c3a370e9870cb7", + "zh:262301545057e654bd6193dc04b01666531fccfcf722f730827695098d93afa7", + "zh:63677684a14e6b7790833982d203fb2f84b105ad6b9b490b3a4ecc7043cdba81", + "zh:67a2932227623073aa9431a12916b52ce1ccddb96f9a2d6cdae2aaf7558ccbf8", + "zh:70dfc6ac33ee140dcb29a971df7eeb15117741b5a75b9f8486c5468c9dd28f24", + "zh:7e3b3b62754e86442048b4b1284e10807e3e58f417e1d59a4575dd29ac6ba518", + "zh:7e6fe662b1e283ad498eb2549d0c2260b908ab5b848e05f84fa4acdca5b4d5ca", + "zh:9c554170f20e659222896533a3a91954fb1d210eea60de05aea803b36d5ccd5d", + "zh:ad2f64d758bd718eb39171f1c31219900fd2bfb552a14f6a90b18cfd178a74b4", + "zh:cfce070000e95dfe56a901340ac256f9d2f84a73bf62391cba8a8e9bf1f857e0", + "zh:d5ae30eccd53ca7314157e62d8ec53151697ed124e43b24b2d16c565054730c6", + "zh:fbe5edf5337adb7360f9ffef57d02b397555b6a89bba68d1b60edfec6e23f02c", + ] +} diff --git a/deployments/droplets/main.tf b/deployments/droplets/main.tf new file mode 100644 index 00000000..73005d82 --- /dev/null +++ b/deployments/droplets/main.tf @@ -0,0 +1,20 @@ +terraform { + required_version = ">= 1.0.0" + + required_providers { + digitalocean = { + source = "digitalocean/digitalocean" + version = ">= 2.0.0" + } + } +} + +provider "digitalocean" {} + +resource "digitalocean_droplet" "server-api" { + image = "ubuntu-23-10-x64" + name = "server-api" + region = "BLR1" + size = "s-1vcpu-1gb" + user_data = file("server-api.yaml") +} \ No newline at end of file diff --git a/deployments/droplets/output.tf b/deployments/droplets/output.tf new file mode 100644 index 00000000..d46eaedd --- /dev/null +++ b/deployments/droplets/output.tf @@ -0,0 +1,4 @@ +output "ip_address" { + value = digitalocean_droplet.server-api.ipv4_address + description = "The public IP address of your Droplet application." +} \ No newline at end of file diff --git a/deployments/droplets/server-api.yaml b/deployments/droplets/server-api.yaml new file mode 100644 index 00000000..ea40554f --- /dev/null +++ b/deployments/droplets/server-api.yaml @@ -0,0 +1,25 @@ +#cloud-config +groups: + - ubuntu: [root,sys] + +users: + - default + - name: asyncapi + gecos: AsyncAPI + primary-group: ubuntu + groups: users, admin + shell: /bin/bash + sudo: ALL=(ALL) NOPASSWD:ALL + ssh-authorized-keys: + - # Add your public key here +runcmd: + - sudo apt-get update -y + - sudo apt install apt-transport-https ca-certificates curl software-properties-common + - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" + - sudo apt-get update -y + - sudo apt install docker-ce -y + - sudo systemctl status docker + - sudo usermod -aG docker ${USER} + - sudo systemctl enable docker + - sudo systemctl start docker diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 00000000..5dbc206d --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,9 @@ +{ + "version": 4, + "terraform_version": "1.6.2", + "serial": 1, + "lineage": "f4f578fd-1301-998b-0c80-dcde4a94bac1", + "outputs": {}, + "resources": [], + "check_results": null +} From 5e464882712d629aef56053efe1fdf878f60a138 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Wed, 10 Jan 2024 19:49:11 +0530 Subject: [PATCH 02/11] fix: deployment workflow and steps --- .github/workflows/deploy-digitalocean.yml | 11 ++--------- deployments/droplets/server-api.yaml | 5 ++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-digitalocean.yml b/.github/workflows/deploy-digitalocean.yml index 98d0efea..487da86e 100644 --- a/.github/workflows/deploy-digitalocean.yml +++ b/.github/workflows/deploy-digitalocean.yml @@ -4,13 +4,6 @@ on: push: branches: - master - - workflow_dispatch: - inputs: - branch: - description: 'Branch to deploy' - required: true - default: 'master' jobs: deploy: @@ -26,7 +19,7 @@ jobs: script: | cd /home/${{ secrets.USERNAME }} if [ ! -d "deploy" ]; then - git clone https://github.com/asyncapi/server-api.git:deploy + git clone https://github.com/asyncapi/server-api.git deploy fi cd deploy @@ -44,7 +37,7 @@ jobs: docker build -t asyncapi/server-api . # Run new docker image - docker run -d -p 80:80 -p 443:443 --name asyncapi-server-api asyncapi/server-api --restart=always + docker run -d -p 80:80 -p 443:443 --restart always --name asyncapi-server-api asyncapi/server-api diff --git a/deployments/droplets/server-api.yaml b/deployments/droplets/server-api.yaml index ea40554f..fd2fb2a8 100644 --- a/deployments/droplets/server-api.yaml +++ b/deployments/droplets/server-api.yaml @@ -12,6 +12,7 @@ users: sudo: ALL=(ALL) NOPASSWD:ALL ssh-authorized-keys: - # Add your public key here + runcmd: - sudo apt-get update -y - sudo apt install apt-transport-https ca-certificates curl software-properties-common @@ -20,6 +21,8 @@ runcmd: - sudo apt-get update -y - sudo apt install docker-ce -y - sudo systemctl status docker - - sudo usermod -aG docker ${USER} + # Add your user to the docker group to avoid using sudo when running docker + # NOTE: You need to logout and login again for this to take effect - sudo systemctl enable docker - sudo systemctl start docker + - sudo usermod -aG docker asyncapi From bf4b43ae5d07ad6080d53dbf1f7dd8868ef71aa0 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Wed, 10 Jan 2024 19:49:41 +0530 Subject: [PATCH 03/11] chore: remove k8s from deployments --- deployments/k8s/.helmignore | 23 ------- deployments/k8s/Chart.yaml | 7 -- deployments/k8s/README.md | 32 --------- deployments/k8s/templates/NOTES.txt | 16 ----- deployments/k8s/templates/_helpers.tpl | 51 --------------- deployments/k8s/templates/deployment.yaml | 69 -------------------- deployments/k8s/templates/hpa.yaml | 33 ---------- deployments/k8s/templates/ingress.yaml | 26 -------- deployments/k8s/templates/service.yaml | 20 ------ deployments/k8s/values.yaml | 79 ----------------------- 10 files changed, 356 deletions(-) delete mode 100644 deployments/k8s/.helmignore delete mode 100644 deployments/k8s/Chart.yaml delete mode 100644 deployments/k8s/README.md delete mode 100644 deployments/k8s/templates/NOTES.txt delete mode 100644 deployments/k8s/templates/_helpers.tpl delete mode 100644 deployments/k8s/templates/deployment.yaml delete mode 100644 deployments/k8s/templates/hpa.yaml delete mode 100644 deployments/k8s/templates/ingress.yaml delete mode 100644 deployments/k8s/templates/service.yaml delete mode 100644 deployments/k8s/values.yaml diff --git a/deployments/k8s/.helmignore b/deployments/k8s/.helmignore deleted file mode 100644 index 0e8a0eb3..00000000 --- a/deployments/k8s/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/deployments/k8s/Chart.yaml b/deployments/k8s/Chart.yaml deleted file mode 100644 index d5d8924e..00000000 --- a/deployments/k8s/Chart.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v2 -name: asyncapi-server-api -description: Helm chart that installs the AsyncAPI Server API - https://github.com/asyncapi/server-api - -type: application -version: 0.1.0 -appVersion: "0.1.0-alpha" diff --git a/deployments/k8s/README.md b/deployments/k8s/README.md deleted file mode 100644 index ce890d29..00000000 --- a/deployments/k8s/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# asyncapi-event-gateway - -![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.1.0-alpha](https://img.shields.io/badge/AppVersion-0.1.0--alpha-informational?style=flat-square) - -Helm chart that installs the AsyncAPI Server API - https://github.com/asyncapi/server-api - -## Values - -| Key | Type | Default | Description | -|-----|------|---------|-------------| -| affinity | object | `{}` | | -| autoscaling.enabled | bool | `true` | | -| autoscaling.maxReplicas | int | `4` | | -| autoscaling.minReplicas | int | `1` | | -| autoscaling.targetCPUUtilizationPercentage | int | `80` | | -| fullnameOverride | string | `""` | | -| image.pullPolicy | string | `"Always"` | | -| image.repository | string | `"asyncapi/server-api"` | | -| image.tag | string | `"latest"` | | -| imagePullSecrets | list | `[]` | | -| nameOverride | string | `""` | | -| nodeSelector | object | `{}` | | -| podAnnotations | object | `{}` | | -| podSecurityContext | object | `{}` | | -| ports | object | `{"http":80}` | Server API opened ports. | -| ports.http | int | `80` | Port where the Server API will be available. | -| replicaCount | int | `2` | | -| resources | object | `{}` | | -| securityContext | object | `{}` | | -| service.annotations | object | `{}` | | -| service.type | string | `"ClusterIP"` | | -| tolerations | list | `[]` | | diff --git a/deployments/k8s/templates/NOTES.txt b/deployments/k8s/templates/NOTES.txt deleted file mode 100644 index 8e81929e..00000000 --- a/deployments/k8s/templates/NOTES.txt +++ /dev/null @@ -1,16 +0,0 @@ -1. Get the application URL by running these commands: -{{- if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "asyncapi-server-api.fullname" . }}) - export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") - echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} - NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "asyncapi-server-api.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "asyncapi-server-api.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "asyncapi-server-api.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") - export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") - echo "Visit http://127.0.0.1:80 to use your application" - kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 80:$CONTAINER_PORT -{{- end }} diff --git a/deployments/k8s/templates/_helpers.tpl b/deployments/k8s/templates/_helpers.tpl deleted file mode 100644 index f022e746..00000000 --- a/deployments/k8s/templates/_helpers.tpl +++ /dev/null @@ -1,51 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "asyncapi-server-api.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -If release name contains chart name it will be used as a full name. -*/}} -{{- define "asyncapi-server-api.fullname" -}} -{{- if .Values.fullnameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- $name := default .Chart.Name .Values.nameOverride }} -{{- if contains $name .Release.Name }} -{{- .Release.Name | trunc 63 | trimSuffix "-" }} -{{- else }} -{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} -{{- end }} -{{- end }} -{{- end }} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "asyncapi-server-api.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} -{{- end }} - -{{/* -Selector labels -*/}} -{{- define "asyncapi-server-api.selectorLabels" -}} -app.kubernetes.io/name: {{ include "asyncapi-server-api.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Common labels -*/}} -{{- define "asyncapi-server-api.labels" -}} -helm.sh/chart: {{ include "asyncapi-server-api.chart" . }} -{{ include "asyncapi-server-api.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end }} \ No newline at end of file diff --git a/deployments/k8s/templates/deployment.yaml b/deployments/k8s/templates/deployment.yaml deleted file mode 100644 index aab5d9ea..00000000 --- a/deployments/k8s/templates/deployment.yaml +++ /dev/null @@ -1,69 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "asyncapi-server-api.fullname" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "asyncapi-server-api.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "asyncapi-server-api.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "asyncapi-server-api.selectorLabels" . | nindent 8 }} - {{- range $key, $value := .Values.deploymentExtraLabels }} - {{ $key }}: {{ $value | quote }} - {{- end }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: http - containerPort: {{ .Values.ports.http }} - protocol: TCP - livenessProbe: - httpGet: - path: / - port: {{ .Values.ports.http }} - initialDelaySeconds: {{ .Values.initialDelaySeconds.liveness }} - periodSeconds: {{ .Values.periodSeconds.liveness }} - readinessProbe: - httpGet: - path: / - port: {{ .Values.ports.http }} - initialDelaySeconds: {{ .Values.initialDelaySeconds.readiness }} - periodSeconds: {{ .Values.periodSeconds.readiness }} - - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/deployments/k8s/templates/hpa.yaml b/deployments/k8s/templates/hpa.yaml deleted file mode 100644 index d6a525a3..00000000 --- a/deployments/k8s/templates/hpa.yaml +++ /dev/null @@ -1,33 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta2 -kind: HorizontalPodAutoscaler -metadata: - name: {{ include "asyncapi-server-api.fullname" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "asyncapi-server-api.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ include "asyncapi-server-api.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - target: - type: Utilization - averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - target: - type: Utilization - averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} -{{- end }} diff --git a/deployments/k8s/templates/ingress.yaml b/deployments/k8s/templates/ingress.yaml deleted file mode 100644 index b8d3d0ef..00000000 --- a/deployments/k8s/templates/ingress.yaml +++ /dev/null @@ -1,26 +0,0 @@ -{{- if .Values.ingress.enabled }} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: {{ include "asyncapi-server-api.fullname" . }} - namespace: {{ .Release.Namespace }} - annotations: - cert-manager.io/issuer: {{ .Values.ingress.issuerName }} # here we use the name of the issuer we created through this chart. -spec: - tls: - - hosts: - - {{ .Values.host }} - secretName: {{ .Values.ingress.secretName }} - ingressClassName: nginx - rules: - - host: {{ .Values.host }} - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: {{ include "asyncapi-server-api.fullname" . }} - port: - number: {{ .Values.ports.http }} -{{- end }} diff --git a/deployments/k8s/templates/service.yaml b/deployments/k8s/templates/service.yaml deleted file mode 100644 index 6a411ff5..00000000 --- a/deployments/k8s/templates/service.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "asyncapi-server-api.fullname" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "asyncapi-server-api.labels" . | nindent 4 }} - {{- with .Values.service.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - type: {{ .Values.service.type }} - ports: - - name: http - protocol: TCP - port: {{ .Values.ports.http }} - targetPort: http - selector: - {{- include "asyncapi-server-api.selectorLabels" . | nindent 4 }} diff --git a/deployments/k8s/values.yaml b/deployments/k8s/values.yaml deleted file mode 100644 index 32ad646f..00000000 --- a/deployments/k8s/values.yaml +++ /dev/null @@ -1,79 +0,0 @@ -# Default values for asyncapi-event-gateway. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -image: - repository: asyncapi/server-api - pullPolicy: Always - tag: latest - -imagePullSecrets: [] - -replicaCount: 2 - -host: api.asyncapi.com -# Server API opened ports. -ports: - # Port where the Server API will be available. - http: 80 - -#periodSeconds for livenees and Readiness Ports -periodSeconds: - liveness: 10 - readiness: 6 -#initialDelaySeconds for liveness and Readiness Ports -initialDelaySeconds: - liveness: 30 - readiness: 30 -# Env vars. Needed for configuring the app. -env: {} - -nameOverride: "" -fullnameOverride: "" - -podAnnotations: {} - -podSecurityContext: {} - # fsGroup: 2000 - -securityContext: {} - # capabilities: - # drop: - # - ALL - # readOnlyRootFilesystem: true - # runAsNonRoot: true - # runAsUser: 1000 - -service: - type: ClusterIP - annotations: {} - -resources: {} - # We usually recommend not to specify default resources and to leave this as a conscious - # choice for the user. This also increases chances charts run on environments with little - # resources, such as Minikube. If you do want to specify resources, uncomment the following - # lines, adjust them as necessary, and remove the curly braces after 'resources:'. - # limits: - # cpu: 100m - # memory: 128Mi - # requests: - # cpu: 100m - # memory: 128Mi - -autoscaling: - enabled: true - minReplicas: 1 - maxReplicas: 4 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - -nodeSelector: {} - -tolerations: [] - -affinity: {} - -ingress: - enabled: false - issuerName: "letsencrypt-prod" - secretName: "server-api-cert" From b04f43675627e69f3c95916f2664cd0fd94a8196 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Wed, 10 Jan 2024 19:53:50 +0530 Subject: [PATCH 04/11] chore: add checks for conventional commits --- .github/workflows/deploy-digitalocean.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-digitalocean.yml b/.github/workflows/deploy-digitalocean.yml index 487da86e..f4c1b576 100644 --- a/.github/workflows/deploy-digitalocean.yml +++ b/.github/workflows/deploy-digitalocean.yml @@ -7,6 +7,15 @@ on: jobs: deploy: + # We just check the message of first commit as there is always just one commit because we squash into one before merging + # "commits" contains array of objects where one of the properties is commit "message" + # Release workflow will be skipped if release conventional commits are not used + if: | + startsWith( github.repository, 'asyncapi/' ) && + (startsWith( github.event.commits[0].message , 'fix:' ) || + startsWith( github.event.commits[0].message, 'fix!:' ) || + startsWith( github.event.commits[0].message, 'feat:' ) || + startsWith( github.event.commits[0].message, 'feat!:' )) runs-on: ubuntu-latest steps: - name: Deploy to DigitalOcean Droplets @@ -38,11 +47,3 @@ jobs: # Run new docker image docker run -d -p 80:80 -p 443:443 --restart always --name asyncapi-server-api asyncapi/server-api - - - - - - - - From 43ee94b72a60af418c5f45bf1846eccbfb985c8a Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Thu, 11 Jan 2024 18:14:50 +0530 Subject: [PATCH 05/11] chore: remove tfstate --- terraform.tfstate | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 terraform.tfstate diff --git a/terraform.tfstate b/terraform.tfstate deleted file mode 100644 index 5dbc206d..00000000 --- a/terraform.tfstate +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.6.2", - "serial": 1, - "lineage": "f4f578fd-1301-998b-0c80-dcde4a94bac1", - "outputs": {}, - "resources": [], - "check_results": null -} From 290de1192011d97b426181cc8128689e1bd89527 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:50:22 +0530 Subject: [PATCH 06/11] feat: use apps instead of droplets --- .github/workflows/deploy-digitalocean.yml | 49 ------------- .github/workflows/release-docker.yml | 12 ++++ deployments/apps/.gitignore | 3 + deployments/apps/.terraform.lock.hcl | 26 +++++++ deployments/apps/main.tf | 83 +++++++++++++++++++++++ 5 files changed, 124 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/deploy-digitalocean.yml create mode 100644 deployments/apps/.gitignore create mode 100644 deployments/apps/.terraform.lock.hcl create mode 100644 deployments/apps/main.tf diff --git a/.github/workflows/deploy-digitalocean.yml b/.github/workflows/deploy-digitalocean.yml deleted file mode 100644 index f4c1b576..00000000 --- a/.github/workflows/deploy-digitalocean.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Deploy to DigitalOcean Droplets - -on: - push: - branches: - - master - -jobs: - deploy: - # We just check the message of first commit as there is always just one commit because we squash into one before merging - # "commits" contains array of objects where one of the properties is commit "message" - # Release workflow will be skipped if release conventional commits are not used - if: | - startsWith( github.repository, 'asyncapi/' ) && - (startsWith( github.event.commits[0].message , 'fix:' ) || - startsWith( github.event.commits[0].message, 'fix!:' ) || - startsWith( github.event.commits[0].message, 'feat:' ) || - startsWith( github.event.commits[0].message, 'feat!:' )) - runs-on: ubuntu-latest - steps: - - name: Deploy to DigitalOcean Droplets - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - key: ${{ secrets.KEY }} - port: ${{ secrets.PORT }} - script: | - cd /home/${{ secrets.USERNAME }} - if [ ! -d "deploy" ]; then - git clone https://github.com/asyncapi/server-api.git deploy - fi - - cd deploy - git checkout master - git pull origin master - - # Remove old docker containers - docker rm -f $(docker ps -a -q) - # Remove old docker images - docker rmi -f $(docker images -a -q) - # Remove old docker volumes - docker volume rm $(docker volume ls -q) - - # Build new docker image - docker build -t asyncapi/server-api . - - # Run new docker image - docker run -d -p 80:80 -p 443:443 --restart always --name asyncapi-server-api asyncapi/server-api diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index baf54492..81b1797d 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -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/app_action@v1.1.5 + 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"}}]' diff --git a/deployments/apps/.gitignore b/deployments/apps/.gitignore new file mode 100644 index 00000000..4c305a08 --- /dev/null +++ b/deployments/apps/.gitignore @@ -0,0 +1,3 @@ +.terraform +terraform.tfstate +terraform.tfstate.backup diff --git a/deployments/apps/.terraform.lock.hcl b/deployments/apps/.terraform.lock.hcl new file mode 100644 index 00000000..8bf3ce37 --- /dev/null +++ b/deployments/apps/.terraform.lock.hcl @@ -0,0 +1,26 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/digitalocean/digitalocean" { + version = "2.34.1" + constraints = ">= 2.0.0" + hashes = [ + "h1:iRyhFUfKnDRWx75+alSOEtdS0BtNUkrvLusC15s34eo=", + "zh:022d4c97af3d022d4e3735a81c6a7297aa43c3b28a8cecaa0ff58273a5677e2e", + "zh:1922f86d5710707eb497fbebcb1a1c5584c843a7e95c3900d750d81bd2785204", + "zh:1b7ab7c67a26c399eb5aa8a7a695cb59279c6a1a562ead3064e4a6b17cdacabe", + "zh:1dc666faa2ec0efc32329b4c8ff79813b54741ef1741bc42d90513e5ba904048", + "zh:220dec61ffd9448a91cca92f2bc6642df10db57b25d3d27036c3a370e9870cb7", + "zh:262301545057e654bd6193dc04b01666531fccfcf722f730827695098d93afa7", + "zh:63677684a14e6b7790833982d203fb2f84b105ad6b9b490b3a4ecc7043cdba81", + "zh:67a2932227623073aa9431a12916b52ce1ccddb96f9a2d6cdae2aaf7558ccbf8", + "zh:70dfc6ac33ee140dcb29a971df7eeb15117741b5a75b9f8486c5468c9dd28f24", + "zh:7e3b3b62754e86442048b4b1284e10807e3e58f417e1d59a4575dd29ac6ba518", + "zh:7e6fe662b1e283ad498eb2549d0c2260b908ab5b848e05f84fa4acdca5b4d5ca", + "zh:9c554170f20e659222896533a3a91954fb1d210eea60de05aea803b36d5ccd5d", + "zh:ad2f64d758bd718eb39171f1c31219900fd2bfb552a14f6a90b18cfd178a74b4", + "zh:cfce070000e95dfe56a901340ac256f9d2f84a73bf62391cba8a8e9bf1f857e0", + "zh:d5ae30eccd53ca7314157e62d8ec53151697ed124e43b24b2d16c565054730c6", + "zh:fbe5edf5337adb7360f9ffef57d02b397555b6a89bba68d1b60edfec6e23f02c", + ] +} diff --git a/deployments/apps/main.tf b/deployments/apps/main.tf new file mode 100644 index 00000000..c00280bd --- /dev/null +++ b/deployments/apps/main.tf @@ -0,0 +1,83 @@ +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 = "blr" + + 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 + } + run_command = "npm run start:docker" + 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 +} \ No newline at end of file From 1ca4a29cdd6dca9ecc24aebc877426efea996e06 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:26:29 +0530 Subject: [PATCH 07/11] chore: remove droplets folder --- deployments/apps/main.tf | 3 +-- deployments/droplets/.gitignore | 3 --- deployments/droplets/.terraform.lock.hcl | 26 ---------------------- deployments/droplets/main.tf | 20 ----------------- deployments/droplets/output.tf | 4 ---- deployments/droplets/server-api.yaml | 28 ------------------------ 6 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 deployments/droplets/.gitignore delete mode 100644 deployments/droplets/.terraform.lock.hcl delete mode 100644 deployments/droplets/main.tf delete mode 100644 deployments/droplets/output.tf delete mode 100644 deployments/droplets/server-api.yaml diff --git a/deployments/apps/main.tf b/deployments/apps/main.tf index c00280bd..fefe332b 100644 --- a/deployments/apps/main.tf +++ b/deployments/apps/main.tf @@ -45,10 +45,9 @@ resource "digitalocean_app" "server-api" { name = "asyncapi-server-api" http_port = 80 health_check { - http_path = "/v1/help/validate" + http_path = "/" port = 80 } - run_command = "npm run start:docker" env { key = "PORT" value = "80" diff --git a/deployments/droplets/.gitignore b/deployments/droplets/.gitignore deleted file mode 100644 index 4c305a08..00000000 --- a/deployments/droplets/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.terraform -terraform.tfstate -terraform.tfstate.backup diff --git a/deployments/droplets/.terraform.lock.hcl b/deployments/droplets/.terraform.lock.hcl deleted file mode 100644 index 8bf3ce37..00000000 --- a/deployments/droplets/.terraform.lock.hcl +++ /dev/null @@ -1,26 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/digitalocean/digitalocean" { - version = "2.34.1" - constraints = ">= 2.0.0" - hashes = [ - "h1:iRyhFUfKnDRWx75+alSOEtdS0BtNUkrvLusC15s34eo=", - "zh:022d4c97af3d022d4e3735a81c6a7297aa43c3b28a8cecaa0ff58273a5677e2e", - "zh:1922f86d5710707eb497fbebcb1a1c5584c843a7e95c3900d750d81bd2785204", - "zh:1b7ab7c67a26c399eb5aa8a7a695cb59279c6a1a562ead3064e4a6b17cdacabe", - "zh:1dc666faa2ec0efc32329b4c8ff79813b54741ef1741bc42d90513e5ba904048", - "zh:220dec61ffd9448a91cca92f2bc6642df10db57b25d3d27036c3a370e9870cb7", - "zh:262301545057e654bd6193dc04b01666531fccfcf722f730827695098d93afa7", - "zh:63677684a14e6b7790833982d203fb2f84b105ad6b9b490b3a4ecc7043cdba81", - "zh:67a2932227623073aa9431a12916b52ce1ccddb96f9a2d6cdae2aaf7558ccbf8", - "zh:70dfc6ac33ee140dcb29a971df7eeb15117741b5a75b9f8486c5468c9dd28f24", - "zh:7e3b3b62754e86442048b4b1284e10807e3e58f417e1d59a4575dd29ac6ba518", - "zh:7e6fe662b1e283ad498eb2549d0c2260b908ab5b848e05f84fa4acdca5b4d5ca", - "zh:9c554170f20e659222896533a3a91954fb1d210eea60de05aea803b36d5ccd5d", - "zh:ad2f64d758bd718eb39171f1c31219900fd2bfb552a14f6a90b18cfd178a74b4", - "zh:cfce070000e95dfe56a901340ac256f9d2f84a73bf62391cba8a8e9bf1f857e0", - "zh:d5ae30eccd53ca7314157e62d8ec53151697ed124e43b24b2d16c565054730c6", - "zh:fbe5edf5337adb7360f9ffef57d02b397555b6a89bba68d1b60edfec6e23f02c", - ] -} diff --git a/deployments/droplets/main.tf b/deployments/droplets/main.tf deleted file mode 100644 index 73005d82..00000000 --- a/deployments/droplets/main.tf +++ /dev/null @@ -1,20 +0,0 @@ -terraform { - required_version = ">= 1.0.0" - - required_providers { - digitalocean = { - source = "digitalocean/digitalocean" - version = ">= 2.0.0" - } - } -} - -provider "digitalocean" {} - -resource "digitalocean_droplet" "server-api" { - image = "ubuntu-23-10-x64" - name = "server-api" - region = "BLR1" - size = "s-1vcpu-1gb" - user_data = file("server-api.yaml") -} \ No newline at end of file diff --git a/deployments/droplets/output.tf b/deployments/droplets/output.tf deleted file mode 100644 index d46eaedd..00000000 --- a/deployments/droplets/output.tf +++ /dev/null @@ -1,4 +0,0 @@ -output "ip_address" { - value = digitalocean_droplet.server-api.ipv4_address - description = "The public IP address of your Droplet application." -} \ No newline at end of file diff --git a/deployments/droplets/server-api.yaml b/deployments/droplets/server-api.yaml deleted file mode 100644 index fd2fb2a8..00000000 --- a/deployments/droplets/server-api.yaml +++ /dev/null @@ -1,28 +0,0 @@ -#cloud-config -groups: - - ubuntu: [root,sys] - -users: - - default - - name: asyncapi - gecos: AsyncAPI - primary-group: ubuntu - groups: users, admin - shell: /bin/bash - sudo: ALL=(ALL) NOPASSWD:ALL - ssh-authorized-keys: - - # Add your public key here - -runcmd: - - sudo apt-get update -y - - sudo apt install apt-transport-https ca-certificates curl software-properties-common - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" - - sudo apt-get update -y - - sudo apt install docker-ce -y - - sudo systemctl status docker - # Add your user to the docker group to avoid using sudo when running docker - # NOTE: You need to logout and login again for this to take effect - - sudo systemctl enable docker - - sudo systemctl start docker - - sudo usermod -aG docker asyncapi From 28f8912e6d4a9de32fa77ab5a91c82cd407ae389 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:07:07 +0530 Subject: [PATCH 08/11] chore: rollback healthcheck path --- deployments/apps/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/apps/main.tf b/deployments/apps/main.tf index fefe332b..bcfd9361 100644 --- a/deployments/apps/main.tf +++ b/deployments/apps/main.tf @@ -45,7 +45,7 @@ resource "digitalocean_app" "server-api" { name = "asyncapi-server-api" http_port = 80 health_check { - http_path = "/" + http_path = "/v1/help/validate" port = 80 } env { From 6bc73ef0c5fdc3873864fcd72e99811d857b9e7f Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:38:35 +0530 Subject: [PATCH 09/11] chore: update region --- deployments/apps/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployments/apps/main.tf b/deployments/apps/main.tf index bcfd9361..64dd9351 100644 --- a/deployments/apps/main.tf +++ b/deployments/apps/main.tf @@ -14,7 +14,7 @@ provider "digitalocean" {} resource "digitalocean_app" "server-api" { spec { name = "server-api" - region = "blr" + region = "sfo3" domain { name = "api.asyncapi.com" @@ -79,4 +79,4 @@ resource "digitalocean_app" "server-api" { output "live_url" { value = digitalocean_app.server-api.default_ingress -} \ No newline at end of file +} From fd0f969c10ac3f55d08f270cad4ec006703603e1 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:41:13 +0530 Subject: [PATCH 10/11] chore: update README.md (add deployment instructions) --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index b4b13209..d9e7cea3 100644 --- a/README.md +++ b/README.md @@ -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 for 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) +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. From e132e0a860296a2f6728b67dd848dbb7b4ddf471 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Mon, 29 Jan 2024 23:47:35 +0530 Subject: [PATCH 11/11] chore: make required changes to README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d9e7cea3..c7775a5a 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ server is ready to use on [http://localhost:80](http://localhost:80). 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 for 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) +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]