Skip to content

Commit bbc9451

Browse files
Shurtu-galasyncapi-bot
andauthored
fix: server-api deploy (#1857)
Co-authored-by: Shurtu-gal <ashishpadhy1729@gmail.com> Co-authored-by: asyncapi-bot <info@asyncapi.io>
1 parent 310cc9d commit bbc9451

File tree

13 files changed

+336
-11
lines changed

13 files changed

+336
-11
lines changed

.changeset/1857.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@asyncapi/cli': patch
3+
---
4+
5+
fix: server-api deploy
6+
7+
- 837be8a: fix: server-api release and deployment
8+
9+
Signed-off-by: Shurtu-gal <ashishpadhy1729@gmail.com>
10+
- 09af23e: chore: add app platform spec
11+
12+
Signed-off-by: Shurtu-gal <ashishpadhy1729@gmail.com>
13+
- a5eef9f: chore: install generator templates globally
14+
15+
Signed-off-by: Shurtu-gal <ashishpadhy1729@gmail.com>
16+
17+

.github/workflows/release-server-api.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ on:
33
release:
44
types:
55
- published
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to release'
10+
required: true
611
jobs:
712

813
publish-docker:
@@ -15,24 +20,25 @@ jobs:
1520
- name: Get version without v character
1621
id: version
1722
run: |
18-
VERSION=${{github.event.release.tag_name}}
23+
VERSION=${{github.event.release.tag_name || github.event.inputs.version}}
1924
VERSION_WITHOUT_V=${VERSION:1}
2025
echo "value=${VERSION_WITHOUT_V}" >> $GITHUB_OUTPUT
2126
2227
- name: Set Up QEMU
23-
uses: docker/setup-qemu-action@v2
28+
uses: docker/setup-qemu-action@v3
2429

2530
- name: Set Up Docker Buildx
26-
uses: docker/setup-buildx-action@v2
31+
uses: docker/setup-buildx-action@v3
2732

2833
- name: Login to Docker Hub
29-
uses: docker/login-action@v2
34+
uses: docker/login-action@v3
3035
with:
3136
username: ${{ secrets.DOCKER_USERNAME }}
3237
password: ${{ secrets.DOCKER_PASSWORD }}
3338

3439
- name: Build and Push Docker Image
35-
uses: docker/build-push-action@v4
40+
uses: docker/build-push-action@v6
41+
id: push
3642
with:
3743
context: .
3844
file: ./src/apps/api/Dockerfile
@@ -41,8 +47,14 @@ jobs:
4147
asyncapi/server-api:${{ steps.version.outputs.value }}
4248
asyncapi/server-api:latest
4349
platforms: linux/amd64,linux/arm64
44-
cache-from: type=gha
45-
cache-to: type=gha
50+
cache-from: |
51+
type=gha,scope=server-api
52+
type=registry,ref=asyncapi/server-api:cache
53+
cache-to: |
54+
type=gha,mode=max,scope=server-api
55+
type=registry,ref=asyncapi/server-api:cache,mode=max
56+
build-args: |
57+
BUILDKIT_INLINE_CACHE=1
4658
4759
- uses: meeDamian/sync-readme@82715041300710d9be7c726c9d6c683b70451087 #version 1.0.6 https://github.com/meeDamian/sync-readme/releases/tag/v1.0.6
4860
with:
@@ -52,14 +64,19 @@ jobs:
5264
readme: ./src/apps/api/README.md
5365
description: Server API providing official AsyncAPI tools
5466

67+
outputs:
68+
digest: ${{ steps.push.outputs.digest }}
69+
5570
deploy-app:
5671
name: Deploy to DigitalOcean App
5772
needs: publish-docker
5873
runs-on: ubuntu-latest
5974
steps:
6075
- name: Deploy to DigitalOcean App
61-
uses: digitalocean/app_action@e583e1b463e8ac378854c0a01af1de8a5afd836b
76+
uses: digitalocean/app_action@190f99be3ce4cbbe5d1ca0a63a8ac9d0add205d0
77+
env:
78+
DOCKER_DIGEST: ${{ needs.publish-docker.outputs.digest }}
6279
with:
63-
app_name: "server-api"
6480
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
65-
images: '[{"name":"asyncapi-server-api","image":{"registry_type":"DOCKER_HUB","registry":"asyncapi","repository":"server-api","tag":"latest"}}]'
81+
app_spec_location: ./src/apps/api/.do/app.yaml
82+
print_deploy_logs: true

openapi.yaml

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
openapi: 3.1.0
22
info:
3-
version: 0.1.0
3+
version: 0.2.0
44
title: AsyncAPI Server API
55
description: Server API providing official AsyncAPI tools
66
contact:
@@ -15,6 +15,31 @@ servers:
1515
- url: https://api.asyncapi.com/v1
1616

1717
paths:
18+
/version:
19+
get:
20+
summary: Get the current version of the AsyncAPI CLI.
21+
operationId: getVersion
22+
tags:
23+
- version
24+
responses:
25+
"200":
26+
description: Successfully retrieved the version.
27+
content:
28+
application/json:
29+
schema:
30+
ref: "#/components/schemas/VersionResponse"
31+
"500":
32+
description: Internal server error.
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/Problem"
37+
default:
38+
description: Unexpected problem.
39+
content:
40+
application/json:
41+
schema:
42+
$ref: "#/components/schemas/Problem"
1843
/validate:
1944
post:
2045
summary: Validate the given AsyncAPI document.
@@ -581,3 +606,108 @@ components:
581606
- title
582607
- status
583608
additionalProperties: true
609+
VersionResponse:
610+
type: object
611+
description: Version information for the AsyncAPI CLI API
612+
properties:
613+
version:
614+
type: string
615+
description: The current version of the AsyncAPI CLI
616+
example: "3.5.1"
617+
name:
618+
type: string
619+
description: The name of the application
620+
example: "@asyncapi/cli"
621+
description:
622+
type: string
623+
description: Description of the application
624+
example: "All in one CLI for all AsyncAPI tools"
625+
runtime:
626+
type: object
627+
description: Runtime information
628+
properties:
629+
node:
630+
type: string
631+
description: Node.js version
632+
example: "v24.7.0"
633+
environment:
634+
type: string
635+
description: Build environment
636+
example: "development"
637+
enum: ["development", "staging", "production"]
638+
platform:
639+
type: string
640+
description: Operating system platform
641+
example: "darwin"
642+
arch:
643+
type: string
644+
description: System architecture
645+
example: "arm64"
646+
uptime:
647+
type: string
648+
description: Application uptime
649+
example: "12 seconds"
650+
startTime:
651+
type: string
652+
format: date-time
653+
description: Application start time
654+
example: "2025-09-12T05:08:25.171Z"
655+
required:
656+
- node
657+
- environment
658+
- platform
659+
- arch
660+
- uptime
661+
- startTime
662+
repository:
663+
type: object
664+
description: Repository information
665+
properties:
666+
url:
667+
type: string
668+
format: uri
669+
description: Repository URL
670+
example: "https://github.com/asyncapi/cli"
671+
bugs:
672+
type: string
673+
format: uri
674+
description: Bug tracker URL
675+
example: "https://github.com/asyncapi/cli/issues"
676+
license:
677+
type: string
678+
description: License type
679+
example: "Apache-2.0"
680+
required:
681+
- url
682+
- bugs
683+
- license
684+
api:
685+
type: object
686+
description: API metadata
687+
properties:
688+
basePath:
689+
type: string
690+
description: API base path
691+
example: "/version"
692+
timestamp:
693+
type: string
694+
format: date-time
695+
description: Current timestamp
696+
example: "2025-09-12T05:08:37.979Z"
697+
health:
698+
type: string
699+
description: API health status
700+
example: "ok"
701+
enum: ["ok", "degraded", "error"]
702+
required:
703+
- basePath
704+
- timestamp
705+
- health
706+
required:
707+
- version
708+
- name
709+
- description
710+
- build
711+
- runtime
712+
- repository
713+
- api

src/apps/api/.do/app.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: server-api
2+
region: sfo3
3+
4+
domain:
5+
name: api.asyncapi.com
6+
type: PRIMARY
7+
8+
ingress:
9+
rules:
10+
- component: asyncapi-server-api
11+
match:
12+
path:
13+
prefix: /
14+
cors:
15+
allow_origins:
16+
- exact: "*"
17+
allow_methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
18+
allow_headers: ["*"]
19+
20+
services:
21+
- name: asyncapi-server-api
22+
image:
23+
registry_type: DOCKER_HUB
24+
registry: asyncapi
25+
repository: server-api
26+
digest: ${DOCKER_DIGEST}
27+
http_port: 80
28+
health_check:
29+
http_path: /v1/help
30+
port: 80
31+
envs:
32+
- key: PORT
33+
value: "80"
34+
instance_count: 1
35+
instance_size_slug: basic-xs
36+
alerts:
37+
- rule: CPU_UTILIZATION
38+
operator: GREATER_THAN
39+
value: 80
40+
window: TEN_MINUTES
41+
42+
alerts:
43+
- rule: DEPLOYMENT_FAILED

src/apps/api/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ COPY *.json ./
2626
# 4. Build TypeScript or production-ready JS
2727
RUN npm run api:build
2828

29+
# ---- Templates stage ----
30+
FROM base AS templates
31+
32+
# Copy templates list
33+
COPY ./src/apps/api/templates.json /tmp/templates.json
34+
35+
# Install generator templates globally using the templates.json array
36+
# This layer will be cached unless template versions change
37+
RUN TEMPLATES=$(node -e "console.log(JSON.parse(require('fs').readFileSync('/tmp/templates.json', 'utf8')).join(' '))") && \
38+
npm install -g $TEMPLATES
39+
2940
# ---- Release stage ----
3041
FROM base AS release
3142

@@ -47,12 +58,19 @@ RUN npm ci --omit=dev --ignore-scripts \
4758
&& npm cache clean --force \
4859
&& npm prune --production
4960

61+
# Copy globally installed templates from templates stage
62+
COPY --from=templates /usr/local/lib/node_modules /usr/local/lib/node_modules
63+
COPY --from=templates /usr/local/bin /usr/local/bin
64+
5065
# Copy OpenAPI document
5166
COPY openapi.yaml ./
5267

5368
# Change ownership of the app directory to the non-root user
5469
RUN chown -R asyncapi:nodejs /app
5570

71+
# Change ownership of node_modules to the non-root user
72+
RUN chown -R asyncapi:nodejs /usr/local/lib/node_modules
73+
5674
# Switch to non-root user
5775
USER asyncapi
5876

src/apps/api/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Controller } from '@/interfaces';
1212
import { logger } from '../../utils/logger';
1313
import { API_VERSION } from './constants';
1414
import { problemMiddleware } from './middlewares/problem.middleware';
15+
import { loggerMiddleware } from './middlewares/logger.middleware';
1516

1617
export class App {
1718
private app: express.Application;
@@ -89,6 +90,7 @@ export class App {
8990
crossOriginEmbedderPolicy: false,
9091
}),
9192
);
93+
this.app.use(loggerMiddleware);
9294
}
9395

9496
private async initializeControllers() {

0 commit comments

Comments
 (0)