Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support reverse proxy deploy #515

Merged
merged 8 commits into from
Feb 19, 2025
Merged
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: 0 additions & 1 deletion .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,4 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: |
reflyai/refly-${{ matrix.app }}:latest
reflyai/refly-${{ matrix.app }}:${{ github.sha }}
70 changes: 70 additions & 0 deletions .github/workflows/release-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Release Docker Images

on:
workflow_dispatch:
push:
tags:
- 'v*'

jobs:
release-image:
name: Release Docker Images
runs-on: ubuntu-latest
if: github.repository == 'refly-ai/refly'
strategy:
matrix:
app: ['api', 'web']
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- uses: pnpm/action-setup@v4
if: matrix.app == 'web'
with:
run_install: false

- name: Use Node.js
uses: actions/setup-node@v4
if: matrix.app == 'web'
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
if: matrix.app == 'web'
run: pnpm install

- name: Build
run: pnpm build:web
if: matrix.app == 'web'
env:
NODE_OPTIONS: '--max_old_space_size=8192'
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: reflyai
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./apps/${{ matrix.app }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
reflyai/refly-${{ matrix.app }}:latest
reflyai/refly-${{ matrix.app }}:${{ steps.get_version.outputs.VERSION }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ To start deployment:

```bash
cd deploy/docker
cp .env.example .env # make sure all required envs are properly set
cp ../../apps/api/.env.example .env # copy the example api env file
docker compose up -d
```

Visit [http://localhost:5700](http://localhost:5700/) to start using ReflyAI.
For the following steps, you can visit [Self-deploy Guide](https://docs.refly.ai/guide/self-deploy) for more details.

### Local Development

Expand Down
8 changes: 6 additions & 2 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ JINA_API_KEY=
# Fireworks API key, used for embeddings
FIREWORKS_API_KEY=

# Serper API key, used for web search
# Serper API key (https://serper.dev/), used for web search
SERPER_API_KEY=

# Marker API key (https://www.datalab.to/), used for PDF parsing
MARKER_API_KEY=

# ----------------------------------------------
# Optional Environment Variables for API service
# (will have reasonable default values)
Expand Down Expand Up @@ -73,6 +76,8 @@ MINIO_EXTERNAL_BUCKET=
# Authentication Configuration
AUTH_SKIP_VERIFICATION=true
REFLY_COOKIE_DOMAIN=
REFLY_COOKIE_SECURE=
REFLY_COOKIE_SAME_SITE=
LOGIN_REDIRECT_URL=
JWT_SECRET=
JWT_EXPIRATION_TIME=
Expand Down Expand Up @@ -111,7 +116,6 @@ RERANKER_MODEL=jina-reranker-v2-base-multilingual
RERANKER_RELEVANCE_THRESHOLD=0.5

# Skill Configuration
REFLY_DEFAULT_MODEL=openai/gpt-4o-mini
SKILL_IDLE_TIMEOUT=10000
SKILL_EXECUTION_TIMEOUT=180000

Expand Down
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "UNLICENSED",
"scripts": {
"copy-env": "ncp .env.example .env",
"build": "prisma generate && tsc --build --verbose && ncp prisma dist",
"build": "prisma generate && tsc --build --verbose && ncp prisma/ dist/prisma/",
"prisma:generate": "prisma format && prisma generate",
"sync-db-schema": "prisma format && prisma generate && node -r ts-node/register --env-file=.env src/scripts/sync-db-schema.ts",
"dev": "nodemon",
Expand Down
44 changes: 23 additions & 21 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ model Account {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@unique([provider, providerAccountId])
@@map("accounts")
Expand Down Expand Up @@ -92,7 +92,7 @@ model User {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@map("users")
}
Expand Down Expand Up @@ -137,7 +137,7 @@ model ActionResult {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@unique([resultId, version])
@@index([targetType, targetId])
Expand Down Expand Up @@ -170,7 +170,7 @@ model ActionStep {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -205,7 +205,7 @@ model TokenUsage {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@index([uid, createdAt])
@@map("token_usages")
Expand Down Expand Up @@ -235,7 +235,7 @@ model StaticFile {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -264,7 +264,7 @@ model Canvas {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -324,7 +324,7 @@ model Resource {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -360,7 +360,7 @@ model Document {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand All @@ -387,7 +387,7 @@ model Reference {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Soft delete timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -424,7 +424,7 @@ model SkillInstance {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -462,7 +462,7 @@ model SkillTrigger {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand All @@ -488,7 +488,7 @@ model LabelClass {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()
/// Related labels
Expand Down Expand Up @@ -519,7 +519,7 @@ model LabelInstance {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -553,7 +553,7 @@ model SubscriptionPlan {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@unique([planType, interval])
@@map("subscription_plans")
Expand Down Expand Up @@ -581,7 +581,7 @@ model Subscription {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@index([uid])
@@index([status, cancelAt])
Expand Down Expand Up @@ -620,7 +620,7 @@ model TokenUsageMeter {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand Down Expand Up @@ -660,7 +660,7 @@ model StorageUsageMeter {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()
/// Deletion timestamp
deletedAt DateTime? @map("deleted_at") @db.Timestamptz()

Expand All @@ -687,10 +687,12 @@ model ModelInfo {
tier String @map("tier")
/// Whether this model is enabled
enabled Boolean @default(true) @map("enabled")
/// Whether this model is the default model
isDefault Boolean @default(false) @map("is_default")
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@map("model_infos")
}
Expand All @@ -715,7 +717,7 @@ model CheckoutSession {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@index([sessionId])
@@map("checkout_sessions")
Expand Down Expand Up @@ -743,7 +745,7 @@ model RefreshToken {
/// Create timestamp
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
/// Update timestamp
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz()
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz()

@@index([uid])
@@map("refresh_tokens")
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ export class AuthService {

cookieOptions(key: string): CookieOptions {
const baseOptions: CookieOptions = {
domain: this.configService.get('auth.cookieDomain') ?? '',
secure: true,
sameSite: 'strict',
domain: this.configService.get('auth.cookie.domain'),
secure: Boolean(this.configService.get('auth.cookie.secure')),
sameSite: this.configService.get('auth.cookie.sameSite'),
path: '/',
};

Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/canvas/canvas.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { CollabModule } from '@/collab/collab.module';
import { QUEUE_DELETE_KNOWLEDGE_ENTITY } from '@/utils/const';
import { CommonModule } from '@/common/common.module';
import { MiscModule } from '@/misc/misc.module';
import { SubscriptionModule } from '@/subscription/subscription.module';

@Module({
imports: [
CommonModule,
CollabModule,
MiscModule,
SubscriptionModule,
BullModule.registerQueue({
name: QUEUE_DELETE_KNOWLEDGE_ENTITY,
}),
Expand Down
9 changes: 6 additions & 3 deletions apps/api/src/canvas/canvas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import {
import { genCanvasID } from '@refly-packages/utils';
import { DeleteKnowledgeEntityJobData } from '@/knowledge/knowledge.dto';
import { QUEUE_DELETE_KNOWLEDGE_ENTITY } from '@/utils/const';
import { ConfigService } from '@nestjs/config';
import { ChatOpenAI } from '@langchain/openai';
import { HumanMessage } from '@langchain/core/messages';
import { SystemMessage } from '@langchain/core/messages';
import { AutoNameCanvasJobData } from './canvas.dto';
import { SubscriptionService } from '@/subscription/subscription.service';

@Injectable()
export class CanvasService {
Expand All @@ -37,7 +37,7 @@ export class CanvasService {
private elasticsearch: ElasticsearchService,
private collabService: CollabService,
private miscService: MiscService,
private configService: ConfigService,
private subscriptionService: SubscriptionService,
@Inject(MINIO_INTERNAL) private minio: MinioService,
@InjectQueue(QUEUE_DELETE_KNOWLEDGE_ENTITY)
private deleteKnowledgeQueue: Queue<DeleteKnowledgeEntityJobData>,
Expand Down Expand Up @@ -385,8 +385,11 @@ export class CanvasService {
return { title: '' };
}

const defaultModel = await this.subscriptionService.getDefaultModel();
this.logger.log(`Using default model for auto naming: ${defaultModel?.name}`);

const model = new ChatOpenAI({
model: this.configService.get('skill.defaultModel'),
model: defaultModel?.name,
apiKey: process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY,
configuration: {
baseURL: process.env.OPENROUTER_API_KEY && 'https://openrouter.ai/api/v1',
Expand Down
Loading