Skip to content

Commit

Permalink
Initial commit on the dockerization
Browse files Browse the repository at this point in the history
  • Loading branch information
santthosh committed May 27, 2024
1 parent 11a6e1e commit 193317f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
.dockerignore
.git
53 changes: 53 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# NextAuth.js Parameters
NEXTAUTH_URL=http://localhost:3000/
NEXTAUTH_SECRET=c60f1bcb46db934646424129387359d5
# Linux: `openssl rand -hex 32` or go to https://generate-secret.vercel.app/32

# Providers
ENABLE_CREDENTIALS_PROVIDER=true
ENABLE_EMAIL_PROVIDER=false
ENABLE_GITHUB_PROVIDER=false
ENABLE_GOOGLE_PROVIDER=false

# Credentials Provider Parameters
CREDENTIALS_APPROVED_USERNAME=jsmith
CREDENTIALS_APPROVED_PASSWORD=localhost@

# Email Server Parameters
EMAIL_SERVER_USER=resend
EMAIL_SERVER_PASSWORD=
EMAIL_SERVER_HOST=smtp.resend.com
EMAIL_SERVER_PORT=465
EMAIL_FROM=no-reply@assistantshub.ai

# GitHub OAuth Parameters
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Google OAuth Parameters
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# AWS Parameters
AWS_S3_BUCKET=
AWS_REGION=us-west-2
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# OpenAI API Key for Assistants Hub
OPENAI_API_KEY=
# Google AI Studio API Key for Assistants Hub
GOOGLE_AI_STUDIO_API_KEY=
# Groq Cloud API Key for Assistants Hub
GROQ_CLOUD_API_KEY=
# Anthropic API Key for Assistants Hub
ANTHROPIC_API_KEY=


# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
POSTGRES_PRISMA_URL="postgresql://.."
BLOB_READ_WRITE_TOKEN="vercel_blob_rw_..."
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM node:latest as base

# 1. Install dependencies only when needed
FROM base AS deps

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apt-get update
RUN apt-get install build-essential
RUN apt-get install openssl

WORKDIR /app

# 2. Rebuild the source code only when needed
FROM deps AS builder

WORKDIR /app

COPY public ./public
COPY src ./src
COPY package.json ./package.json
COPY .prettierrc.json ./.prettierrc.json
COPY next.config.js ./next.config.js
COPY tsconfig.json ./tsconfig.json
COPY tailwind.config.ts ./tailwind.config.ts

COPY prisma ./prisma

RUN corepack enable pnpm && pnpm install

# This will do the trick, use the corresponding env file for each environment.
COPY .env.template .env
RUN npm run build

# 3. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup --gid 1001 nodejs && adduser -uid 1001 --gid 1001 nextjs

COPY --from=builder /app/public ./public
COPY --from=builder /app/.env ./.env

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/server ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000
ENV PORT 3000

CMD HOSTNAME=localhost node server.js
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.8'
services:
nextjs:
platform:
linux/arm64
build:
context: .
dockerfile: Dockerfile
image: assistantshub
ports:
- "3000:3000"
volumes:
- .:/app
environment:
- POSTGRES_PRISMA_URL=postgresql://postgres:password@db:5432/assistantshub?schema=public
env_file:
- .env.docker
depends_on:
db:
condition: service_healthy
command: >
sh -c "
npm run generate &&
npm run migrate &&
npm run seed &&
npm run start
"
db:
image: timescale/timescaledb:latest-pg16
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: assistantshub
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 8s
retries: 5
start_period: 10s

volumes:
pgdata:
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"scripts": {
"dev": "next dev -p 3001",
"build:local": "prisma generate && prisma migrate dev && next build",
"build": "prisma generate && prisma migrate deploy && next build && prisma db seed",
"build": "next build",
"generate": "prisma generate",
"migrate": "prisma migrate deploy",
"seed": "prisma db seed",
"start": "next start",
"lint": "next lint",
"format": "prettier --check --ignore-path .gitignore .",
Expand Down
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
binaryTargets = ["native", "linux-arm64-openssl-3.0.x"]
}

datasource db {
Expand Down
3 changes: 3 additions & 0 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (process.env.ENABLE_EMAIL_PROVIDER === 'true') {
const emailProvider = EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
// @ts-ignore
port: process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
Expand Down Expand Up @@ -76,6 +77,8 @@ if (process.env.ENABLE_GOOGLE_PROVIDER === 'true') {
providers.push(googleProvider);
}



export const authOptions = {
adapter: PrismaAdapter(prisma),
providers: providers,
Expand Down
1 change: 1 addition & 0 deletions src/app/assistants/[id]/chat/useChatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const useChatContext = () => {
useEffect(() => {
getFingerprint()
.then((fingerprint) => {
// @ts-ignore
setFingerprint(fingerprint);
})
.catch((error) => {
Expand Down

0 comments on commit 193317f

Please sign in to comment.