Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/nextjs-openai/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
11 changes: 11 additions & 0 deletions samples/nextjs-openai/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/aws-cli:1": {}
}
}
25 changes: 25 additions & 0 deletions samples/nextjs-openai/.github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
environment: playground
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Deploy
uses: DefangLabs/[email protected]
with:
config-env-vars: OPENAI_API_KEY
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
56 changes: 56 additions & 0 deletions samples/nextjs-openai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Next.js & OpenAI

[![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-openai-template%26template_owner%3DDefangSamples)

This sample shows a Next.js and OpenAI application deployed using Defang. It uses the OpenAI API for its chatbot functionality.

## Prerequisites

1. Download [Defang CLI](https://github.com/DefangLabs/defang)
2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)

## Development

To run the application locally, you can use the following command:

```bash
docker compose -f compose.dev.yaml up --build
```

## Configuration
For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration):

> 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.

### `OPENAI_API_KEY`
An API key for Open AI.
```bash
defang config set OPENAI_API_KEY
```

## Deployment

> [!NOTE]
> Download [Defang CLI](https://github.com/DefangLabs/defang)

### Defang Playground

Deploy your application to the Defang Playground by opening up your terminal and typing:
```bash
defang compose up
```

### BYOC

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).

---

Title: Next.js & OpenAI

Short Description: A fun chatbot created with Next.js and OpenAI.

Tags: Next.js, TypeScript, React, JavaScript, Chatbot, OpenAI, AI

Languages: TypeScript
10 changes: 10 additions & 0 deletions samples/nextjs-openai/compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
ui:
extends:
file: compose.yaml
service: nextjs-openai
volumes:
- type: bind
source: ./ui
target: /app
command: ["npm", "run", "dev"]
19 changes: 19 additions & 0 deletions samples/nextjs-openai/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
ui:
# uncomment to add your own domain
# domainname: example.com
build:
context: ./ui
dockerfile: Dockerfile
ports:
- target: 3000
published: 3000
mode: ingress
deploy:
resources:
reservations:
memory: 256M
environment:
- OPENAI_API_KEY
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
6 changes: 6 additions & 0 deletions samples/nextjs-openai/run/package-lock.json

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

2 changes: 2 additions & 0 deletions samples/nextjs-openai/ui/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.next
3 changes: 3 additions & 0 deletions samples/nextjs-openai/ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions samples/nextjs-openai/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
17 changes: 17 additions & 0 deletions samples/nextjs-openai/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:bookworm-slim

RUN apt-get update && apt-get install -y curl && apt-get clean

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm run build

EXPOSE 3000

CMD [ "npm", "run", "start" ]
4 changes: 4 additions & 0 deletions samples/nextjs-openai/ui/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading
Loading