Skip to content

Commit 23bd272

Browse files
authored
Merge pull request #310 from DefangLabs/linda-nextjs-claude
Next.js and Claude (Anthropic AI) Sample
2 parents 3662b09 + 5142669 commit 23bd272

21 files changed

+8131
-0
lines changed

.github/workflows/deploy-changed-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
if: env.should_continue == 'true'
6666
env:
6767
FIXED_VERIFIER_PK: ${{ secrets.FIXED_VERIFIER_PK }}
68+
TEST_ANTHROPIC_API_KEY: ${{ secrets.TEST_ANTHROPIC_API_KEY }}
6869
TEST_AWS_ACCESS_KEY: ${{ secrets.TEST_AWS_ACCESS_KEY }}
6970
TEST_AWS_SECRET_KEY: ${{ secrets.TEST_AWS_SECRET_KEY }}
7071
TEST_BOARD_PASSWORD: ${{ secrets.TEST_BOARD_PASSWORD }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]
22+
with:
23+
config-env-vars: ANTHROPIC_API_KEY
24+
env:
25+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

samples/nextjs-claude/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Next.js & Claude
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-nextjs-claude-template%26template_owner%3DDefangSamples)
4+
5+
This sample shows a Next.js and Claude application deployed using Defang. It uses Anthropic API for its chatbot functionality.
6+
7+
## Prerequisites
8+
9+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
10+
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
11+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
12+
13+
## Development
14+
15+
To run the application locally, you can use the following command:
16+
17+
```bash
18+
docker compose -f compose.dev.yaml up --build
19+
```
20+
21+
## Configuration
22+
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):
23+
24+
> Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you.
25+
26+
### `ANTHROPIC_API_KEY`
27+
An API key for Anthropic AI.
28+
```bash
29+
defang config set ANTHROPIC_API_KEY
30+
```
31+
32+
## Deployment
33+
34+
> [!NOTE]
35+
> Download [Defang CLI](https://github.com/DefangLabs/defang)
36+
37+
### Defang Playground
38+
39+
Deploy your application to the Defang Playground by opening up your terminal and typing:
40+
```bash
41+
defang compose up
42+
```
43+
44+
### BYOC
45+
46+
If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud).
47+
48+
---
49+
50+
Title: Next.js & Claude
51+
52+
Short Description: A fun chatbot created with Next.js and Claude.
53+
54+
Tags: Next.js, TypeScript, React, JavaScript, Chatbot, Claude, AI, Anthropic
55+
56+
Languages: TypeScript
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
nextjs-claude:
3+
extends:
4+
file: compose.yaml
5+
service: nextjs-claude
6+
volumes:
7+
- type: bind
8+
source: ./ui
9+
target: /app
10+
command: ["npm", "run", "dev"]

samples/nextjs-claude/compose.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
nextjs-claude:
3+
# uncomment to add your own domain
4+
# domainname: example.com
5+
build:
6+
context: ./ui
7+
dockerfile: Dockerfile
8+
ports:
9+
- target: 3000
10+
published: 3000
11+
mode: ingress
12+
deploy:
13+
resources:
14+
reservations:
15+
memory: 256M
16+
environment:
17+
- ANTHROPIC_API_KEY
18+
healthcheck:
19+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.next
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

0 commit comments

Comments
 (0)