Skip to content

Commit 817836d

Browse files
committed
defang playground
1 parent 68c8b16 commit 817836d

File tree

8 files changed

+220
-26
lines changed

8 files changed

+220
-26
lines changed

samples/mastra/.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Default .dockerignore file for Defang
2+
**/__pycache__
3+
**/.direnv
4+
**/.DS_Store
5+
**/.envrc
6+
**/.git
7+
**/.github
8+
**/.idea
9+
**/.next
10+
**/.vscode
11+
**/compose.*.yaml
12+
**/compose.*.yml
13+
**/compose.yaml
14+
**/compose.yml
15+
**/docker-compose.*.yaml
16+
**/docker-compose.*.yml
17+
**/docker-compose.yaml
18+
**/docker-compose.yml
19+
**/node_modules
20+
**/Thumbs.db
21+
Dockerfile
22+
*.Dockerfile
23+
# Ignore our own binary, but only in the root to avoid ignoring subfolders
24+
defang
25+
defang.exe
26+
# Ignore our project-level state
27+
.defang*

samples/mastra/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:22-alpine
2+
3+
WORKDIR /app
4+
COPY package*.json ./
5+
RUN npm ci
6+
COPY src ./src
7+
RUN npx mastra build
8+
RUN apk add --no-cache gcompat
9+
10+
RUN addgroup -g 1001 -S nodejs && \
11+
adduser -S mastra -u 1001 && \
12+
chown -R mastra:nodejs /app
13+
14+
USER mastra
15+
16+
ENV PORT=8080
17+
ENV NODE_ENV=production
18+
ENV READINESS_CHECK_PATH="/api"
19+
20+
EXPOSE 8080
21+
22+
CMD ["node", "--import=./.mastra/output/instrumentation.mjs", ".mastra/output/index.mjs"]

samples/mastra/Dockerfile.local

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM node:22
2+
3+
WORKDIR /app
4+
COPY package*.json ./
5+
# Use npm install instead of npm ci for better optional dependency handling
6+
RUN npm install
7+
COPY src ./src
8+
9+
RUN groupadd -g 1001 nodejs && \
10+
useradd -r -u 1001 -g nodejs mastra -m && \
11+
chown -R mastra:nodejs /app && \
12+
mkdir -p /home/mastra/.config && \
13+
chown -R mastra:nodejs /home/mastra
14+
15+
USER mastra
16+
17+
ENV PORT=8080
18+
# ENV NODE_ENV=development
19+
# ENV READINESS_CHECK_PATH="/api"
20+
21+
EXPOSE 8080
22+
23+
CMD ["npm", "run", "dev"]

samples/mastra/compose.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
db:
3+
image: postgres:15
4+
restart: unless-stopped
5+
environment:
6+
- POSTGRES_USER=postgres
7+
- POSTGRES_PASSWORD
8+
- POSTGRES_DB=postgres
9+
ports:
10+
- mode: host
11+
target: 5432
12+
13+
mastra:
14+
# uncomment to add your own domain
15+
# domainname: example.com
16+
restart: unless-stopped
17+
build:
18+
context: .
19+
dockerfile: Dockerfile
20+
ports:
21+
- mode: ingress
22+
target: 8080
23+
published: 8080
24+
environment:
25+
- GOOGLE_GENERATIVE_AI_API_KEY
26+
- DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres
27+
healthcheck:
28+
test: ["CMD", "curl", "-f", "http://localhost:8080"]
29+
depends_on:
30+
- db

samples/mastra/package-lock.json

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/mastra/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@mastra/libsql": "^0.16.1",
2323
"@mastra/loggers": "^0.10.18",
2424
"@mastra/memory": "^0.15.10",
25+
"@mastra/pg": "^0.17.7",
2526
"zod": "^4.1.12"
2627
},
2728
"devDependencies": {
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Agent } from '@mastra/core/agent';
2-
import { Memory } from '@mastra/memory';
3-
import { LibSQLStore } from '@mastra/libsql';
4-
import { weatherTool } from '../tools/weather-tool';
5-
import { scorers } from '../scorers/weather-scorer';
1+
import { Agent } from "@mastra/core/agent";
2+
import { Memory } from "@mastra/memory";
3+
import { PostgresStore } from "@mastra/pg";
4+
import { weatherTool } from "../tools/weather-tool";
5+
import { scorers } from "../scorers/weather-scorer";
66

77
export const weatherAgent = new Agent({
8-
name: 'Weather Agent',
8+
name: "Weather Agent",
99
instructions: `
1010
You are a helpful weather assistant that provides accurate weather information and can help planning activities based on the weather.
1111
@@ -20,34 +20,34 @@ export const weatherAgent = new Agent({
2020
2121
Use the weatherTool to fetch current weather data.
2222
`,
23-
model: 'google/gemini-2.5-pro',
23+
model: "google/gemini-2.5-pro",
2424
tools: { weatherTool },
2525
scorers: {
2626
toolCallAppropriateness: {
2727
scorer: scorers.toolCallAppropriatenessScorer,
2828
sampling: {
29-
type: 'ratio',
29+
type: "ratio",
3030
rate: 1,
3131
},
3232
},
3333
completeness: {
3434
scorer: scorers.completenessScorer,
3535
sampling: {
36-
type: 'ratio',
36+
type: "ratio",
3737
rate: 1,
3838
},
3939
},
4040
translation: {
4141
scorer: scorers.translationScorer,
4242
sampling: {
43-
type: 'ratio',
43+
type: "ratio",
4444
rate: 1,
4545
},
4646
},
4747
},
4848
memory: new Memory({
49-
storage: new LibSQLStore({
50-
url: 'file:../mastra.db', // path is relative to the .mastra/output directory
49+
storage: new PostgresStore({
50+
connectionString: process.env.DATABASE_URL!,
5151
}),
5252
}),
5353
});

samples/mastra/src/mastra/index.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
2-
import { Mastra } from '@mastra/core/mastra';
3-
import { PinoLogger } from '@mastra/loggers';
4-
import { LibSQLStore } from '@mastra/libsql';
5-
import { weatherWorkflow } from './workflows/weather-workflow';
6-
import { weatherAgent } from './agents/weather-agent';
7-
import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';
1+
import { Mastra } from "@mastra/core/mastra";
2+
import { PinoLogger } from "@mastra/loggers";
3+
import { PostgresStore } from "@mastra/pg";
4+
import { weatherWorkflow } from "./workflows/weather-workflow";
5+
import { weatherAgent } from "./agents/weather-agent";
6+
import {
7+
toolCallAppropriatenessScorer,
8+
completenessScorer,
9+
translationScorer,
10+
} from "./scorers/weather-scorer";
811

912
export const mastra = new Mastra({
1013
workflows: { weatherWorkflow },
1114
agents: { weatherAgent },
12-
scorers: { toolCallAppropriatenessScorer, completenessScorer, translationScorer },
13-
storage: new LibSQLStore({
15+
scorers: {
16+
toolCallAppropriatenessScorer,
17+
completenessScorer,
18+
translationScorer,
19+
},
20+
storage: new PostgresStore({
1421
// stores observability, scores, ... into memory storage, if it needs to persist, change to file:../mastra.db
15-
url: ":memory:",
22+
connectionString: process.env.DATABASE_URL!,
1623
}),
1724
logger: new PinoLogger({
18-
name: 'Mastra',
19-
level: 'info',
25+
name: "Mastra",
26+
level: "info",
2027
}),
2128
telemetry: {
2229
// Telemetry is deprecated and will be removed in the Nov 4th release
23-
enabled: false,
30+
enabled: false,
2431
},
2532
observability: {
2633
// Enables DefaultExporter and CloudExporter for AI tracing
27-
default: { enabled: true },
34+
default: { enabled: true },
2835
},
2936
});

0 commit comments

Comments
 (0)